Skip to content

Commit 9f6db3e

Browse files
committed
fix(gui): handle LightVirtualFile in relativePath calculation
Add special handling for LightVirtualFile to return an empty string and wrap the path calculation in a try-catch block to prevent exceptions. This ensures more robust handling of virtual files in the AutoDevInput UI.
1 parent 8ab56f1 commit 9f6db3e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

core/src/main/kotlin/cc/unitmesh/devti/gui/chat/ui/AutoDevInput.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,12 @@ fun insertStringAndSaveChange(
189189
}
190190

191191
fun VirtualFile.relativePath(project: Project): String {
192-
val projectDir = project.guessProjectDir()!!.toNioPath().toFile()
193-
val relativePath = FileUtil.getRelativePath(projectDir, this.toNioPath().toFile())
194-
return relativePath ?: this.path
192+
if (this is LightVirtualFile) return ""
193+
try {
194+
val projectDir = project.guessProjectDir()!!.toNioPath().toFile()
195+
val relativePath = FileUtil.getRelativePath(projectDir, this.toNioPath().toFile())
196+
return relativePath ?: this.path
197+
} catch (e: Exception) {
198+
return this.path
199+
}
195200
}

0 commit comments

Comments
 (0)