Skip to content

Commit 0979670

Browse files
committed
fix(knowledge): wrap file path access in runReadAction
Ensure thread-safe access to `containingFile.virtualFile.path` by wrapping it in `runReadAction`. This prevents potential threading issues when accessing file paths in the knowledge provider.
1 parent 4f3ab88 commit 0979670

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

core/src/main/kotlin/cc/unitmesh/devti/bridge/knowledge/KnowledgeFunctionProvider.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,14 @@ class KnowledgeFunctionProvider : ToolchainFunctionProvider {
6565
val elementText = KnowledgeWebApiProvider.available(project).map {
6666
it.lookupApiCallTree(project, method, path)
6767
}.flatten().joinToString("\n") {
68-
"## " + it.containingFile.virtualFile.path + "\n" + it.text
68+
runReadAction {
69+
val path = it.containingFile.virtualFile?.path
70+
if (path != null) {
71+
"## " + path + "\n" + it.text
72+
} else {
73+
it.text
74+
}
75+
}
6976
}
7077

7178
return elementText

0 commit comments

Comments
 (0)