generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
3 changed files
with
39 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 37 additions & 4 deletions
41
...g/src/main/kotlin/cc/unitmesh/devti/language/documentation/DevInsDocumentationProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,43 @@ | ||
package cc.unitmesh.devti.language.documentation | ||
|
||
import com.intellij.lang.documentation.DocumentationProvider | ||
import cc.unitmesh.devti.agent.configurable.loadAgentConfigs | ||
import cc.unitmesh.devti.language.completion.BuiltinCommand | ||
import cc.unitmesh.devti.language.psi.DevInTypes | ||
import com.intellij.lang.documentation.AbstractDocumentationProvider | ||
import com.intellij.openapi.editor.Editor | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiFile | ||
import com.intellij.psi.util.elementType | ||
|
||
class DevInsDocumentationProvider : DocumentationProvider { | ||
override fun getQuickNavigateInfo(element: PsiElement?, originalElement: PsiElement?): String? { | ||
return super.getQuickNavigateInfo(element, originalElement) | ||
class DevInsDocumentationProvider : AbstractDocumentationProvider() { | ||
override fun generateDoc(element: PsiElement?, originalElement: PsiElement?): String? { | ||
val project = element?.project ?: return null | ||
return when (element.elementType) { | ||
DevInTypes.AGENT_ID -> { | ||
val agentConfigs = loadAgentConfigs(project).filter { | ||
it.name == element.text | ||
} | ||
|
||
if (agentConfigs.isEmpty()) return null | ||
agentConfigs.joinToString("\n") { it.description } | ||
} | ||
|
||
DevInTypes.COMMAND_ID -> { | ||
BuiltinCommand.all().find { it.commandName == element.text }?.description | ||
} | ||
|
||
else -> { | ||
element.text | ||
} | ||
} | ||
} | ||
|
||
override fun getCustomDocumentationElement( | ||
editor: Editor, | ||
file: PsiFile, | ||
contextElement: PsiElement?, | ||
targetOffset: Int | ||
): PsiElement? { | ||
return contextElement ?: file.findElementAt(targetOffset) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters