Skip to content

Commit 4c8a49b

Browse files
committed
feat(devins-lang): add documentation provider and refactor custom agent completion
#101 The commit adds a new documentation provider for the DevIn language, which improves the user experience by providing quick navigation information for PsiElements. Additionally, the commit refactors the CustomAgentCompletion class to use the new documentation provider and fixes an issue with the import statements. The changes also include modifications to the plugin.xml file to register the documentation provider and a refactoring of the loadAgentConfigs function to use the new documentation provider.
1 parent 8e46a8a commit 4c8a49b

File tree

6 files changed

+31
-17
lines changed

6 files changed

+31
-17
lines changed

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/utils/ProjectFileUtil.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,5 @@ import com.intellij.openapi.vfs.VirtualFileManager
88
fun Project.lookupFile(path: String): VirtualFile? {
99
val projectPath = this.guessProjectDir()?.toNioPath()
1010
val realpath = projectPath?.resolve(path)
11-
12-
val virtualFile =
13-
VirtualFileManager.getInstance().findFileByUrl("file://${realpath?.toAbsolutePath()}")
14-
return virtualFile
11+
return VirtualFileManager.getInstance().findFileByUrl("file://${realpath?.toAbsolutePath()}")
1512
}

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/CustomAgentCompletion.kt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
11
package cc.unitmesh.devti.language.completion
22

3-
import cc.unitmesh.devti.agent.configurable.customAgentSetting
3+
import cc.unitmesh.devti.agent.configurable.loadAgentConfigs
44
import cc.unitmesh.devti.agent.model.CustomAgentConfig
55
import com.intellij.codeInsight.completion.CompletionParameters
66
import com.intellij.codeInsight.completion.CompletionProvider
77
import com.intellij.codeInsight.completion.CompletionResultSet
88
import com.intellij.codeInsight.lookup.LookupElementBuilder
99
import com.intellij.util.ProcessingContext
10-
import kotlinx.serialization.json.Json
11-
// DON'T CHANGE THIS IMPORT
12-
import kotlinx.serialization.decodeFromString
1310

1411
class CustomAgentCompletion : CompletionProvider<CompletionParameters>() {
1512
override fun addCompletions(
1613
parameters: CompletionParameters,
1714
context: ProcessingContext,
1815
result: CompletionResultSet,
1916
) {
20-
val project = parameters.originalFile.project
21-
val configs: List<CustomAgentConfig> = try {
22-
val ragsJsonConfig = project.customAgentSetting.ragsJsonConfig
23-
Json.decodeFromString(ragsJsonConfig)
24-
} catch (e: Exception) {
25-
emptyList()
26-
}
17+
val configs: List<CustomAgentConfig> = loadAgentConfigs(parameters.originalFile.project)
2718

2819
configs.forEach {
2920
result.addElement(

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/FileReferenceLanguageProvider.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ class FileReferenceLanguageProvider : CompletionProvider<CompletionParameters>()
5656

5757
fun canBeAdded(file: VirtualFile): Boolean {
5858
if (!file.isValid || file.isDirectory) return false
59-
6059
if (file.fileType.isBinary || FileUtilRt.isTooLarge(file.length)) return false
6160

6261
return true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package cc.unitmesh.devti.language.documentation
2+
3+
import com.intellij.lang.documentation.DocumentationProvider
4+
import com.intellij.psi.PsiElement
5+
6+
class DevInsDocumentationProvider : DocumentationProvider {
7+
override fun getQuickNavigateInfo(element: PsiElement?, originalElement: PsiElement?): String? {
8+
return super.getQuickNavigateInfo(element, originalElement)
9+
}
10+
}

exts/devins-lang/src/main/resources/cc.unitmesh.devti.language.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
<runLineMarkerContributor language="DevIn"
3838
implementationClass="cc.unitmesh.devti.language.run.DevInsRunLineMarkersProvider"/>
3939

40+
<lang.documentationProvider language="DevIn"
41+
id="devinsDocumentationProvider"
42+
implementationClass="cc.unitmesh.devti.language.documentation.DevInsDocumentationProvider"/>
4043
</extensions>
4144

4245
<actions>
@@ -46,6 +49,6 @@
4649
</actions>
4750

4851
<extensions defaultExtensionNs="cc.unitmesh">
49-
<customAgentResponse implementation="cc.unitmesh.devti.language.provider.DevInsCustomAgentResponse" />
52+
<customAgentResponse implementation="cc.unitmesh.devti.language.provider.DevInsCustomAgentResponse"/>
5053
</extensions>
5154
</idea-plugin>

src/main/kotlin/cc/unitmesh/devti/agent/configurable/CoUnitSettingService.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
package cc.unitmesh.devti.agent.configurable
22

3+
import cc.unitmesh.devti.agent.model.CustomAgentConfig
34
import com.intellij.openapi.components.*
45
import com.intellij.openapi.project.Project
6+
import kotlinx.serialization.json.Json
7+
// DON'T CHANGE THIS IMPORT
8+
import kotlinx.serialization.decodeFromString
59

610
val Project.customAgentSetting: CoUnitProjectSettingsService
711
get() = service<CoUnitProjectSettingsService>()
812

13+
fun loadAgentConfigs(project: Project): List<CustomAgentConfig> {
14+
val configs: List<CustomAgentConfig> = try {
15+
val ragsJsonConfig = project.customAgentSetting.ragsJsonConfig
16+
Json.decodeFromString(ragsJsonConfig)
17+
} catch (e: Exception) {
18+
emptyList()
19+
}
20+
return configs
21+
}
22+
923
@Service(Service.Level.PROJECT)
1024
@State(name = "CoUnitProjectSettings", storages = [Storage(StoragePathMacros.WORKSPACE_FILE)])
1125
class CoUnitProjectSettingsService(

0 commit comments

Comments
 (0)