Skip to content

Commit 8c8ade1

Browse files
committed
fix(knowledge): handle invalid API format with file lookup #308
Add logic to handle invalid API format by attempting to lookup the file and find related classes using `RelatedClassesProvider`. This improves error handling and provides more context when the API format is invalid.
1 parent d9999ca commit 8c8ade1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package cc.unitmesh.devti.bridge.knowledge
22

33
import cc.unitmesh.devti.bridge.KnowledgeTransfer
44
import cc.unitmesh.devti.bridge.provider.KnowledgeWebApiProvider
5+
import cc.unitmesh.devti.provider.RelatedClassesProvider
56
import cc.unitmesh.devti.provider.toolchain.ToolchainFunctionProvider
7+
import com.intellij.openapi.application.runReadAction
68
import com.intellij.openapi.project.Project
9+
import com.intellij.psi.PsiManager
710

811
val API_METHODS: List<String> = listOf("GET", "POST", "PUT", "DELETE", "PATCH")
912

@@ -37,6 +40,15 @@ class KnowledgeFunctionProvider : ToolchainFunctionProvider {
3740
// split prop to method and path
3841
val split = prop.split("#")
3942
if (split.size != 2) {
43+
val lookupFile = project.lookupFile(prop) ?: return "Invalid API format or File not found"
44+
if (lookupFile.isValid) {
45+
/// since VueFile can only find by File Usage
46+
val psiFile = runReadAction { PsiManager.getInstance(project).findFile(lookupFile) }
47+
?: return "Invalid API format or File not found or PsiFile not found"
48+
return RelatedClassesProvider.provide(psiFile.language)?.lookupIO(psiFile)
49+
?: "No related classes found"
50+
}
51+
4052
return "Invalid API format"
4153
}
4254

0 commit comments

Comments
 (0)