Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit90f978f

Browse files
committed
fix(completion): handle null paths in file completion
- Safely handle null paths in FileCompletionProvider by checking buildElement result- Make relativePath() more robust by catching exceptions and handling invalid files- Remove unused VirtualFilePresentation import
1 parentdac43aa commit90f978f

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

‎core/src/main/kotlin/cc/unitmesh/devti/util/ProjectFileUtil.kt‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,14 @@ fun VirtualFile.canBeAdded(project: Project): Boolean {
5252
}
5353

5454
fun VirtualFile.relativePath(project:Project):String {
55+
if (!this.isValid)returnthis.path
5556
val projectDir= project.guessProjectDir()!!.toNioPath().toFile()
56-
val relativePath=FileUtil.getRelativePath(projectDir,this.toNioPath().toFile())
57+
val relativePath=try {
58+
FileUtil.getRelativePath(projectDir,this.toNioPath().toFile())
59+
}catch (e:Exception) {
60+
null
61+
}
62+
5763
return relativePath?:this.path
5864
}
5965

‎exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/provider/FileCompletionProvider.kt‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import com.intellij.codeInsight.lookup.LookupElement
1010
importcom.intellij.codeInsight.lookup.LookupElementBuilder
1111
importcom.intellij.codeInsight.lookup.LookupElementPresentation
1212
importcom.intellij.codeInsight.lookup.LookupElementRenderer
13-
importcom.intellij.ide.presentation.VirtualFilePresentation
1413
importcom.intellij.openapi.fileEditor.impl.EditorHistoryManager
1514
importcom.intellij.openapi.project.Project
1615
importcom.intellij.openapi.roots.ProjectFileIndex
@@ -29,7 +28,8 @@ class FileCompletionProvider : CompletionProvider<CompletionParameters>() {
2928
var recentlyFiles:MutableList<VirtualFile>=mutableListOf()
3029
EditorHistoryManager.getInstance(project).fileList.forEach {
3130
if (!it.canBeAdded())return@forEach
32-
result.addElement(buildElement(it, project,99.0))
31+
val element= buildElement(it, project,99.0)?:return@forEach
32+
result.addElement(element)
3333
recentlyFiles.add(it)
3434
}
3535

@@ -38,14 +38,14 @@ class FileCompletionProvider : CompletionProvider<CompletionParameters>() {
3838
if (recentlyFiles.contains(it))return@iterateContenttrue
3939
if (!ProjectFileIndex.getInstance(project).isInContent(it))return@iterateContenttrue
4040
if (ProjectFileIndex.getInstance(project).isUnderIgnored(it))return@iterateContenttrue
41-
result.addElement(buildElement(it, project,1.0))
41+
val element= buildElement(it, project,1.0)?:return@iterateContenttrue
42+
result.addElement(element)
4243
true
4344
}
4445
}
4546

46-
privatefunbuildElement(virtualFile:VirtualFile,project:Project,priority:Double):LookupElement {
47-
val filepath= virtualFile.relativePath(project)
48-
47+
privatefunbuildElement(virtualFile:VirtualFile,project:Project,priority:Double):LookupElement? {
48+
val filepath= virtualFile.relativePath(project)?:returnnull
4949
val elementBuilder=LookupElementBuilder.create(filepath)
5050
.withCaseSensitivity(false)
5151
.withRenderer(object:LookupElementRenderer<LookupElement>() {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp