Added Mnemonics auto-completion.

This commit is contained in:
Chris Hodges 2021-07-16 15:23:30 +02:00
parent d53a1fbac8
commit 9ebc93fd15
4 changed files with 59 additions and 1 deletions

View File

@ -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<CompletionParameters>() {
override fun addCompletions(parameters: CompletionParameters, context: ProcessingContext, resultSet: CompletionResultSet) {
resultSet.addAllElements(M68kIsa.mnemonics.map(LookupElementBuilder::create))
}
})
}
}

View File

@ -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)

View File

@ -21,6 +21,7 @@
<lang.syntaxHighlighterFactory language="M68k"
implementationClass="de.platon42.intellij.plugins.m68k.syntax.M68kSyntaxHighlighterFactory"/>
<colorSettingsPage implementation="de.platon42.intellij.plugins.m68k.syntax.M68kColorSettingsPage"/>
<completion.contributor language="M68k" implementationClass="de.platon42.intellij.plugins.m68k.asm.M68kMnemonicCompletionContributor"/>
</extensions>
<actions>

View File

@ -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<caret>
""")
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: <caret>
""")
myFixture.completeBasic()
assertThat(myFixture.lookupElementStrings).hasSameElementsAs(M68kIsa.mnemonics)
}
@Test
internal fun completion_shows_all_mnemonics_after_space(@MyFixture myFixture: CodeInsightTestFixture) {
myFixture.configureByText("completeme.asm", """
<caret>
""")
myFixture.completeBasic()
assertThat(myFixture.lookupElementStrings).hasSameElementsAs(M68kIsa.mnemonics)
}
}