diff --git a/README.md b/README.md index ee524bc..14d4e1b 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,10 @@ weak warnings as missing macro evaluation will not resolve symbols defined via ` Provides the assigned value of a `=`, `set` or `equ` symbol definition when hovering over a symbol. +#### M68kMacroDefinition + +When used over a macro invocation, shows the expanded macro contents. + #### M68kLabel Shows the comments above the label (local or global) and an end-of-line comment, if available. If the first statement after the label is a directive @@ -160,6 +164,7 @@ are appreciated. It really is keeping me motivated to continue development. - Enhancement: Label documentation now also works for local labels and includes end-of-line comment for label, too. - Enhancement: Symbol definition documentation now also includes comments in the same way as the label documentation does. +- New: Macro definition / invocation documentation provider that even tries to expand macros. ### V0.7 (26-Sep-21) diff --git a/build.gradle b/build.gradle index 41a97ac..2f8f26b 100644 --- a/build.gradle +++ b/build.gradle @@ -62,6 +62,7 @@ patchPluginXml {
Full changelog available at Github project site.
""") diff --git a/src/main/java/de/platon42/intellij/plugins/m68k/documentation/AbstractM68kDocumentationProvider.kt b/src/main/java/de/platon42/intellij/plugins/m68k/documentation/AbstractM68kDocumentationProvider.kt index 032cf3f..da64798 100644 --- a/src/main/java/de/platon42/intellij/plugins/m68k/documentation/AbstractM68kDocumentationProvider.kt +++ b/src/main/java/de/platon42/intellij/plugins/m68k/documentation/AbstractM68kDocumentationProvider.kt @@ -6,7 +6,7 @@ import com.intellij.openapi.util.text.HtmlBuilder import com.intellij.openapi.util.text.HtmlChunk import com.intellij.psi.PsiElement import de.platon42.intellij.plugins.m68k.psi.M68kNamedElement -import de.platon42.intellij.plugins.m68k.psi.M68kPsiWalkUtil +import de.platon42.intellij.plugins.m68k.psi.utils.M68kPsiWalkUtil abstract class AbstractM68kDocumentationProvider : AbstractDocumentationProvider() { @@ -27,6 +27,9 @@ abstract class AbstractM68kDocumentationProvider : AbstractDocumentationProvider fun getContent(element: PsiElement) = HtmlBuilder().append(HtmlChunk.text(element.text).code()).wrapWith(DocumentationMarkup.CONTENT_ELEMENT) + fun getContent(chunk: HtmlChunk) = + HtmlBuilder().append(chunk).wrapWith(DocumentationMarkup.CONTENT_ELEMENT) + fun getContent(value: String) = HtmlBuilder().append(value).wrapWith(DocumentationMarkup.CONTENT_ELEMENT) } \ No newline at end of file diff --git a/src/main/java/de/platon42/intellij/plugins/m68k/documentation/M68kMacroDefinitionDocumentationProvider.kt b/src/main/java/de/platon42/intellij/plugins/m68k/documentation/M68kMacroDefinitionDocumentationProvider.kt new file mode 100644 index 0000000..7fe0a93 --- /dev/null +++ b/src/main/java/de/platon42/intellij/plugins/m68k/documentation/M68kMacroDefinitionDocumentationProvider.kt @@ -0,0 +1,42 @@ +package de.platon42.intellij.plugins.m68k.documentation + +import com.intellij.openapi.util.text.HtmlBuilder +import com.intellij.openapi.util.text.HtmlChunk +import com.intellij.psi.PsiElement +import com.intellij.psi.util.PsiTreeUtil +import de.platon42.intellij.plugins.m68k.psi.M68kMacroCall +import de.platon42.intellij.plugins.m68k.psi.M68kMacroDefinition +import de.platon42.intellij.plugins.m68k.psi.utils.M68kMacroExpansionUtil + +class M68kMacroDefinitionDocumentationProvider : AbstractM68kDocumentationProvider() { + + override fun getQuickNavigateInfo(element: PsiElement, originalElement: PsiElement?): String? { + return generateDoc(element, originalElement) + } + + override fun generateDoc(element: PsiElement, originalElement: PsiElement?): String? { + return if (element is M68kMacroDefinition) createDoc(element, originalElement, 100) else null // TODO make this configurable + } + + override fun generateHoverDoc(element: PsiElement, originalElement: PsiElement?): String? { + return if (element is M68kMacroDefinition) createDoc(element, originalElement, 4) else null // TODO make this configurable + } + + private fun createDoc(macrodef: M68kMacroDefinition, originalElement: PsiElement?, linesLimit: Int): String { + val macroCall = PsiTreeUtil.getParentOfType(originalElement, M68kMacroCall::class.java) + val expandedMacro = M68kMacroExpansionUtil.expandMacro(macrodef, macroCall) + val builder = HtmlBuilder() + return builder + .append(getComments(macrodef)) + .append(getDefinition(HtmlChunk.text(macrodef.name!!).code())) + .append( + getContent( + HtmlBuilder().appendWithSeparators( + HtmlChunk.br(), + expandedMacro.take(linesLimit).map { HtmlChunk.text(it).code() }.toList() + ).toFragment() + ) + ) + .toString() + } +} \ No newline at end of file diff --git a/src/main/java/de/platon42/intellij/plugins/m68k/psi/M68kLookupUtil.kt b/src/main/java/de/platon42/intellij/plugins/m68k/psi/utils/M68kLookupUtil.kt similarity index 98% rename from src/main/java/de/platon42/intellij/plugins/m68k/psi/M68kLookupUtil.kt rename to src/main/java/de/platon42/intellij/plugins/m68k/psi/utils/M68kLookupUtil.kt index 74c01f3..bee4b48 100644 --- a/src/main/java/de/platon42/intellij/plugins/m68k/psi/M68kLookupUtil.kt +++ b/src/main/java/de/platon42/intellij/plugins/m68k/psi/utils/M68kLookupUtil.kt @@ -1,9 +1,10 @@ -package de.platon42.intellij.plugins.m68k.psi +package de.platon42.intellij.plugins.m68k.psi.utils import com.intellij.openapi.project.Project import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.stubs.StubIndex import com.intellij.psi.util.PsiTreeUtil +import de.platon42.intellij.plugins.m68k.psi.* import de.platon42.intellij.plugins.m68k.stubs.M68kGlobalLabelStubIndex import de.platon42.intellij.plugins.m68k.stubs.M68kMacroDefinitionStubIndex import de.platon42.intellij.plugins.m68k.stubs.M68kSymbolDefinitionStubIndex diff --git a/src/main/java/de/platon42/intellij/plugins/m68k/psi/utils/M68kMacroExpansionUtil.kt b/src/main/java/de/platon42/intellij/plugins/m68k/psi/utils/M68kMacroExpansionUtil.kt new file mode 100644 index 0000000..165c907 --- /dev/null +++ b/src/main/java/de/platon42/intellij/plugins/m68k/psi/utils/M68kMacroExpansionUtil.kt @@ -0,0 +1,25 @@ +package de.platon42.intellij.plugins.m68k.psi.utils + +import de.platon42.intellij.plugins.m68k.psi.M68kMacroCall +import de.platon42.intellij.plugins.m68k.psi.M68kMacroDefinition + +object M68kMacroExpansionUtil { + + fun expandMacro(macroDefinition: M68kMacroDefinition, macroCall: M68kMacroCall?): ListMOLVANIA
move.l \\1,d0
mulu d0,d0
MOLVANIA
move.l d1,d0
mulu d0,d0
DTW
dc.b ((15)<<4)|(14),((14)<<4)|(10),((1)<<4)|(2),((3)<<4)|(4),((10)<<4)|(11),((10)<<4)|(12),((5)<<4)|(3),((9)<<4)|(10)