|
1 | 1 | package cc.unitmesh.devti.language.documentation
|
2 | 2 |
|
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 |
4 | 8 | import com.intellij.psi.PsiElement
|
| 9 | +import com.intellij.psi.PsiFile |
| 10 | +import com.intellij.psi.util.elementType |
5 | 11 |
|
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) |
9 | 42 | }
|
10 | 43 | }
|
0 commit comments