Skip to content

Commit 388d484

Browse files
committed
fix(devins-lang): restrict agent_id to non-whitespace characters #101
The regex pattern for agent_id in DevInLexer.flex has been updated to only allow non-whitespace characters, ensuring that agent IDs are syntactically valid and do not include spaces or tabs. This change aligns with the language specification and improves the parsing and validation of agent IDs in the DevInLang grammar. Additionally, the DevInsDocumentationProvider class has been refactored to extend AbstractDocumentationProvider instead of DocumentationProvider directly, and it now handles documentation lookup for AGENT_ID and COMMAND_ID elements. The class now imports the necessary packages for interacting with agent configurations and built-in commands, and it provides a more detailed documentation string for each element type. This refactoring enhances the documentation capabilities of the language plugin and improves the developer experience.
1 parent 4c8a49b commit 388d484

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

exts/devins-lang/src/grammar/DevInLexer.flex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import com.intellij.psi.TokenType;
3737
IDENTIFIER=[a-zA-Z0-9][_\-a-zA-Z0-9]*
3838

3939
VARIABLE_ID=[a-zA-Z0-9][_\-a-zA-Z0-9]*
40-
AGENT_ID=[a-zA-Z0-9][_\-a-zA-Z0-9\s]*
40+
AGENT_ID=[a-zA-Z0-9][_\-a-zA-Z0-9]*
4141
COMMAND_ID=[a-zA-Z0-9][_\-a-zA-Z0-9]*
4242
LANGUAGE_ID=[a-zA-Z][_\-a-zA-Z0-9 .]*
4343
SYSTEM_ID=[a-zA-Z][_\-a-zA-Z0-9]*
Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
11
package cc.unitmesh.devti.language.documentation
22

3-
import com.intellij.lang.documentation.DocumentationProvider
3+
import cc.unitmesh.devti.agent.configurable.loadAgentConfigs
4+
import cc.unitmesh.devti.language.completion.BuiltinCommand
5+
import cc.unitmesh.devti.language.psi.DevInTypes
6+
import com.intellij.lang.documentation.AbstractDocumentationProvider
7+
import com.intellij.openapi.editor.Editor
48
import com.intellij.psi.PsiElement
9+
import com.intellij.psi.PsiFile
10+
import com.intellij.psi.util.elementType
511

6-
class DevInsDocumentationProvider : DocumentationProvider {
7-
override fun getQuickNavigateInfo(element: PsiElement?, originalElement: PsiElement?): String? {
8-
return super.getQuickNavigateInfo(element, originalElement)
12+
class DevInsDocumentationProvider : AbstractDocumentationProvider() {
13+
override fun generateDoc(element: PsiElement?, originalElement: PsiElement?): String? {
14+
val project = element?.project ?: return null
15+
return when (element.elementType) {
16+
DevInTypes.AGENT_ID -> {
17+
val agentConfigs = loadAgentConfigs(project).filter {
18+
it.name == element.text
19+
}
20+
21+
if (agentConfigs.isEmpty()) return null
22+
agentConfigs.joinToString("\n") { it.description }
23+
}
24+
25+
DevInTypes.COMMAND_ID -> {
26+
BuiltinCommand.all().find { it.commandName == element.text }?.description
27+
}
28+
29+
else -> {
30+
element.text
31+
}
32+
}
33+
}
34+
35+
override fun getCustomDocumentationElement(
36+
editor: Editor,
37+
file: PsiFile,
38+
contextElement: PsiElement?,
39+
targetOffset: Int
40+
): PsiElement? {
41+
return contextElement ?: file.findElementAt(targetOffset)
942
}
1043
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<lang.documentationProvider language="DevIn"
4141
id="devinsDocumentationProvider"
4242
implementationClass="cc.unitmesh.devti.language.documentation.DevInsDocumentationProvider"/>
43+
<documentationProvider implementation="cc.unitmesh.devti.language.documentation.DevInsDocumentationProvider"/>
4344
</extensions>
4445

4546
<actions>

0 commit comments

Comments
 (0)