From 9ebc93fd15fa31596cd716a38294cd8b4cba0f39 Mon Sep 17 00:00:00 2001 From: chrisly42 Date: Fri, 16 Jul 2021 15:23:30 +0200 Subject: [PATCH] Added Mnemonics auto-completion. --- .../asm/M68kMnemonicCompletionContributor.kt | 17 ++++++++ .../m68k/syntax/M68kSyntaxHighlighter.kt | 2 +- src/main/resources/META-INF/plugin.xml | 1 + .../M68kMnemonicCompletionContributorTest.kt | 40 +++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/platon42/intellij/plugins/m68k/asm/M68kMnemonicCompletionContributor.kt create mode 100644 src/test/java/de/platon42/intellij/plugins/m68k/asm/M68kMnemonicCompletionContributorTest.kt diff --git a/src/main/java/de/platon42/intellij/plugins/m68k/asm/M68kMnemonicCompletionContributor.kt b/src/main/java/de/platon42/intellij/plugins/m68k/asm/M68kMnemonicCompletionContributor.kt new file mode 100644 index 0000000..27f7493 --- /dev/null +++ b/src/main/java/de/platon42/intellij/plugins/m68k/asm/M68kMnemonicCompletionContributor.kt @@ -0,0 +1,17 @@ +package de.platon42.intellij.plugins.m68k.asm + +import com.intellij.codeInsight.completion.* +import com.intellij.codeInsight.lookup.LookupElementBuilder +import com.intellij.patterns.PlatformPatterns +import com.intellij.util.ProcessingContext +import de.platon42.intellij.plugins.m68k.psi.M68kTypes + +class M68kMnemonicCompletionContributor : CompletionContributor() { + init { + extend(CompletionType.BASIC, PlatformPatterns.psiElement(M68kTypes.MACRO_INVOKATION), object : CompletionProvider() { + override fun addCompletions(parameters: CompletionParameters, context: ProcessingContext, resultSet: CompletionResultSet) { + resultSet.addAllElements(M68kIsa.mnemonics.map(LookupElementBuilder::create)) + } + }) + } +} \ No newline at end of file diff --git a/src/main/java/de/platon42/intellij/plugins/m68k/syntax/M68kSyntaxHighlighter.kt b/src/main/java/de/platon42/intellij/plugins/m68k/syntax/M68kSyntaxHighlighter.kt index 4613c8c..2f70bf5 100644 --- a/src/main/java/de/platon42/intellij/plugins/m68k/syntax/M68kSyntaxHighlighter.kt +++ b/src/main/java/de/platon42/intellij/plugins/m68k/syntax/M68kSyntaxHighlighter.kt @@ -25,7 +25,7 @@ class M68kSyntaxHighlighter : SyntaxHighlighterBase() { M68kTypes.MNEMONIC -> arrayOf(MNEMONIC) M68kTypes.MACRO_INVOKATION -> arrayOf(MACRO_CALL) M68kTypes.DATA_DIRECTIVE -> arrayOf(DATA_PREPROCESSOR) - M68kTypes.OTHER_DIRECTIVE -> arrayOf(OTHER_PREPROCESSOR) + M68kTypes.OTHER_DIRECTIVE, M68kTypes.EQU -> arrayOf(OTHER_PREPROCESSOR) M68kTypes.OPSIZE_BS -> arrayOf(DATA_WIDTH_BS) M68kTypes.OPSIZE_W -> arrayOf(DATA_WIDTH_W) M68kTypes.OPSIZE_L -> arrayOf(DATA_WIDTH_L) diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 31b6e24..e5ae8b1 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -21,6 +21,7 @@ + diff --git a/src/test/java/de/platon42/intellij/plugins/m68k/asm/M68kMnemonicCompletionContributorTest.kt b/src/test/java/de/platon42/intellij/plugins/m68k/asm/M68kMnemonicCompletionContributorTest.kt new file mode 100644 index 0000000..b0a86a8 --- /dev/null +++ b/src/test/java/de/platon42/intellij/plugins/m68k/asm/M68kMnemonicCompletionContributorTest.kt @@ -0,0 +1,40 @@ +package de.platon42.intellij.plugins.m68k.asm + +import com.intellij.testFramework.fixtures.CodeInsightTestFixture +import de.platon42.intellij.jupiter.LightCodeInsightExtension +import de.platon42.intellij.jupiter.MyFixture +import de.platon42.intellij.plugins.m68k.AbstractM68kTest +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(LightCodeInsightExtension::class) +internal class M68kMnemonicCompletionContributorTest : AbstractM68kTest() { + + @Test + internal fun completion_shows_all_move_mnemonics_after_first_letters(@MyFixture myFixture: CodeInsightTestFixture) { + myFixture.configureByText("completeme.asm", """ + mo + """) + myFixture.completeBasic() + assertThat(myFixture.lookupElementStrings).containsExactlyInAnyOrder("move", "moveq", "movea", "movem", "movep") + } + + @Test + internal fun completion_shows_all_mnemonics_after_label(@MyFixture myFixture: CodeInsightTestFixture) { + myFixture.configureByText("completeme.asm", """ +label: + """) + myFixture.completeBasic() + assertThat(myFixture.lookupElementStrings).hasSameElementsAs(M68kIsa.mnemonics) + } + + @Test + internal fun completion_shows_all_mnemonics_after_space(@MyFixture myFixture: CodeInsightTestFixture) { + myFixture.configureByText("completeme.asm", """ + + """) + myFixture.completeBasic() + assertThat(myFixture.lookupElementStrings).hasSameElementsAs(M68kIsa.mnemonics) + } +} \ No newline at end of file