Added assembler directives to code completion.

This commit is contained in:
Chris Hodges 2022-10-29 13:10:55 +02:00
parent cd0bcd22ff
commit def6fe306f
7 changed files with 97 additions and 4 deletions

View File

@ -67,6 +67,8 @@ patchPluginXml {
<li>Bugfix: addq/subq for address register stated it would affect the condition codes, which it in fact doesn't.
<li>New: Added simple custom navigation bar.
<li>New: Added folding support for functions and macro definitions.
<li>New: Added assembler directives to code completion (only lower-case except for other directives like IF
and MACRO, which are only suggested for upper-case).
</ul>
<p>Full changelog available at <a href="https://github.com/chrisly42/mc68000-asm-plugin#changelog">Github project site</a>.</p>
""")

View File

@ -0,0 +1,27 @@
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.M68kIcons
import de.platon42.intellij.plugins.m68k.psi.M68kTypes
class M68kDirectiveCompletionContributor : CompletionContributor() {
companion object {
val DIRECTIVES =
listOf(AssemblerDirectives.dataDirectives, AssemblerDirectives.plainDirectives, AssemblerDirectives.otherDirectives.map(String::uppercase))
.flatten()
.toSortedSet()
.map { PrioritizedLookupElement.withPriority(LookupElementBuilder.create(it).withIcon(M68kIcons.MNEMONIC), 1.5) }
}
init {
extend(CompletionType.BASIC, PlatformPatterns.psiElement(M68kTypes.MACRO_INVOCATION), object : CompletionProvider<CompletionParameters>() {
override fun addCompletions(parameters: CompletionParameters, context: ProcessingContext, resultSet: CompletionResultSet) {
resultSet.addAllElements(DIRECTIVES)
}
})
}
}

View File

@ -32,7 +32,7 @@ class M68kLocalLabelDefCompletionContributor : CompletionContributor() {
}
referencedLocalLabels.removeAll(definedLocalLabels)
resultSet.addAllElements(
if (parameters.originalPosition?.text == ".") {
if (parameters.originalPosition?.text?.startsWith(".") == true) {
referencedLocalLabels.map { LookupElementBuilder.create(it.removePrefix(".")) }
} else {
referencedLocalLabels.map(LookupElementBuilder::create)

View File

@ -28,6 +28,7 @@
<highlightVisitor implementation="de.platon42.intellij.plugins.m68k.syntax.M68kRainbowVisitor"/>
<colorSettingsPage implementation="de.platon42.intellij.plugins.m68k.syntax.M68kColorSettingsPage"/>
<completion.contributor language="MC68000" implementationClass="de.platon42.intellij.plugins.m68k.asm.M68kMnemonicCompletionContributor"/>
<completion.contributor language="MC68000" implementationClass="de.platon42.intellij.plugins.m68k.asm.M68kDirectiveCompletionContributor"/>
<completion.contributor language="MC68000" implementationClass="de.platon42.intellij.plugins.m68k.refs.M68kGlobalLabelSymbolCompletionContributor"/>
<completion.contributor language="MC68000" implementationClass="de.platon42.intellij.plugins.m68k.refs.M68kLocalLabelDefCompletionContributor"/>
<completion.contributor language="MC68000" implementationClass="de.platon42.intellij.plugins.m68k.refs.M68kMacroCallCompletionContributor"/>

View File

@ -0,0 +1,63 @@
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 M68kDirectiveCompletionContributorTest : AbstractM68kTest() {
@Test
internal fun completion_shows_plain_directive(@MyFixture myFixture: CodeInsightTestFixture) {
myFixture.configureByText(
"completeme.asm", """
inc<caret>
"""
)
myFixture.completeBasic()
assertThat(myFixture.lookupElementStrings).containsExactlyInAnyOrder("include", "incbin", "incdir")
}
@Test
internal fun completion_shows_other_directive(@MyFixture myFixture: CodeInsightTestFixture) {
myFixture.configureByText(
"completeme.asm", """
IF<caret>
"""
)
myFixture.completeBasic()
assertThat(myFixture.lookupElementStrings).containsExactlyInAnyOrder(
"IF",
"IFB",
"IFC",
"IFD",
"IFEQ",
"IFGE",
"IFGT",
"IFLE",
"IFLT",
"IFMACROD",
"IFMACROND",
"IFNB",
"IFNC",
"IFND",
"IFNE",
"ENDIF"
)
}
@Test
internal fun completion_shows_data_directives(@MyFixture myFixture: CodeInsightTestFixture) {
myFixture.configureByText(
"completeme.asm", """
dc<caret>
"""
)
myFixture.completeBasic()
assertThat(myFixture.lookupElementStrings).containsExactlyInAnyOrder("dc", "dc.b", "dc.w", "dc.l", "dcb", "dcb.b", "dcb.w", "dcb.l", "data_c")
}
}

View File

@ -30,7 +30,7 @@ label: <caret>
"""
)
myFixture.completeBasic()
assertThat(myFixture.lookupElementStrings).hasSameElementsAs(M68kIsa.mnemonics)
assertThat(myFixture.lookupElementStrings).containsAnyElementsOf(M68kIsa.mnemonics)
}
@Test
@ -41,6 +41,6 @@ label: <caret>
"""
)
myFixture.completeBasic()
assertThat(myFixture.lookupElementStrings).hasSameElementsAs(M68kIsa.mnemonics)
assertThat(myFixture.lookupElementStrings).containsAnyElementsOf(M68kIsa.mnemonics)
}
}

View File

@ -27,6 +27,6 @@ noppy MACRO
"""
)
myFixture.completeBasic()
assertThat(myFixture.lookupElementStrings).containsExactlyInAnyOrder("nop", "not", "noppy")
assertThat(myFixture.lookupElementStrings).containsExactlyInAnyOrder("nop", "not", "noppy", "cnop")
}
}