Added documentation provider info for global labels. Shows directives and comments above.
Fixed BNF for labels with preprocessor statements. Bumped versions.
This commit is contained in:
+47
@@ -0,0 +1,47 @@
|
||||
package de.platon42.intellij.plugins.m68k.documentation
|
||||
|
||||
import com.intellij.lang.documentation.AbstractDocumentationProvider
|
||||
import com.intellij.lang.documentation.DocumentationMarkup
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.psi.PsiComment
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.util.SmartList
|
||||
import de.platon42.intellij.plugins.m68k.psi.M68kGlobalLabel
|
||||
import de.platon42.intellij.plugins.m68k.psi.M68kStatement
|
||||
|
||||
class M68kGlobalLabelDocumentationProvider : AbstractDocumentationProvider() {
|
||||
|
||||
override fun getQuickNavigateInfo(element: PsiElement, originalElement: PsiElement?): String? {
|
||||
return generateDoc(element, originalElement)
|
||||
}
|
||||
|
||||
override fun generateDoc(element: PsiElement, originalElement: PsiElement?): String? {
|
||||
return if (element is M68kGlobalLabel) {
|
||||
// TODO find out how we can generate inner links for more symbol references inside the expression (DocumentationManagerUtil)
|
||||
val statement = element.parent as M68kStatement
|
||||
var preprocessorDirective = statement.preprocessorDirective
|
||||
if ((preprocessorDirective == null) && (statement.asmInstruction == null) && (statement.macroCall == null)) {
|
||||
val nextLineStatement = PsiTreeUtil.skipWhitespacesAndCommentsForward(PsiTreeUtil.skipWhitespacesAndCommentsForward(statement))
|
||||
as? M68kStatement
|
||||
preprocessorDirective = nextLineStatement?.preprocessorDirective
|
||||
}
|
||||
val content = if (preprocessorDirective != null)
|
||||
DocumentationMarkup.CONTENT_START + StringUtil.escapeXmlEntities(preprocessorDirective.text) + DocumentationMarkup.CONTENT_END
|
||||
else ""
|
||||
val comments = SmartList<String>()
|
||||
var prevToken: PsiElement? = statement
|
||||
do {
|
||||
prevToken = PsiTreeUtil.skipWhitespacesBackward(prevToken)
|
||||
if (prevToken !is PsiComment) break
|
||||
comments.add(prevToken.text)
|
||||
} while (true)
|
||||
val commentpart =
|
||||
if (comments.isNotEmpty()) comments.asReversed().joinToString("<br>", DocumentationMarkup.GRAYED_START, DocumentationMarkup.GRAYED_END) else ""
|
||||
|
||||
commentpart +
|
||||
DocumentationMarkup.DEFINITION_START + StringUtil.escapeXmlEntities(element.name!!) + DocumentationMarkup.DEFINITION_END +
|
||||
content
|
||||
} else null
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -16,7 +16,7 @@ class M68kSymbolDefinitionDocumentationProvider : AbstractDocumentationProvider(
|
||||
override fun generateDoc(element: PsiElement, originalElement: PsiElement?): String? {
|
||||
return if (element is M68kSymbolDefinition) {
|
||||
// TODO find out how we can generate inner links for more symbol references inside the expression (DocumentationManagerUtil)
|
||||
val value = (element.getParent() as M68kAssignment).expr.text
|
||||
val value = (element.parent as M68kAssignment).expr.text
|
||||
DocumentationMarkup.DEFINITION_START + StringUtil.escapeXmlEntities(element.name!!) + DocumentationMarkup.DEFINITION_END +
|
||||
DocumentationMarkup.CONTENT_START + StringUtil.escapeXmlEntities(value) + DocumentationMarkup.CONTENT_END
|
||||
} else null
|
||||
|
||||
@@ -121,7 +121,6 @@ M68kFile ::= line*
|
||||
private line ::= !<<eof>> (MacroDefinition | statement) (<<eof>>|EOL)
|
||||
|
||||
statement ::= (Assignment
|
||||
| PreprocessorDirective
|
||||
| LabelInsts)
|
||||
{pin = 1 recoverWhile = statement_recover}
|
||||
|
||||
@@ -140,8 +139,8 @@ Assignment ::= SymbolDefinition COLON? (OP_ASSIGN|EQU) expr
|
||||
private LabelInsts ::= LabelWithInstruction | LabelOnly | InstructionOnly
|
||||
|
||||
private LabelOnly ::= Label
|
||||
private LabelWithInstruction ::= Label Instruction
|
||||
private InstructionOnly ::= Instruction
|
||||
private LabelWithInstruction ::= Label (Instruction|PreprocessorDirective)
|
||||
private InstructionOnly ::= (Instruction|PreprocessorDirective)
|
||||
|
||||
LocalLabel ::= LOCAL_LABEL_DEF COLON? {
|
||||
name = "local label"
|
||||
@@ -175,7 +174,7 @@ AsmOp ::= MNEMONIC OperandSize? {
|
||||
|
||||
PreprocessorKeyword ::= (DATA_DIRECTIVE | OTHER_DIRECTIVE)
|
||||
|
||||
PreprocessorDirective ::= Label? PreprocessorKeyword PreprocessorOperands? {
|
||||
PreprocessorDirective ::= PreprocessorKeyword PreprocessorOperands? {
|
||||
mixin = "de.platon42.intellij.plugins.m68k.psi.M68kPreprocessorDirectiveMixin"
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ object M68kPsiImplUtil {
|
||||
|
||||
// Local Label
|
||||
@JvmStatic
|
||||
fun getName(element: M68kLocalLabel): String = element.firstChild?.text ?: ""
|
||||
fun getName(element: M68kLocalLabel): String? = element.firstChild?.text
|
||||
|
||||
@JvmStatic
|
||||
fun setName(element: M68kLocalLabel, name: String): PsiElement {
|
||||
|
||||
Reference in New Issue
Block a user