diff --git a/src/main/java/de/platon42/intellij/plugins/m68k/refs/M68kLocalLabelReference.kt b/src/main/java/de/platon42/intellij/plugins/m68k/refs/M68kLocalLabelReference.kt index e7a492e..5e8b965 100644 --- a/src/main/java/de/platon42/intellij/plugins/m68k/refs/M68kLocalLabelReference.kt +++ b/src/main/java/de/platon42/intellij/plugins/m68k/refs/M68kLocalLabelReference.kt @@ -63,10 +63,8 @@ class M68kLocalLabelReference(element: M68kSymbolReference) : PsiPolyVariantRefe } override fun getVariants(): Array { - return findLocalLabels(element) { true }.asSequence() - .distinct() + return findLocalLabels(element) { true } .map { LookupElementBuilder.createWithIcon(it) } - .toList() .toTypedArray() } } \ No newline at end of file diff --git a/src/test/java/de/platon42/intellij/plugins/m68k/refs/M68kReferenceContributorTest.kt b/src/test/java/de/platon42/intellij/plugins/m68k/refs/M68kReferenceContributorTest.kt index 959c11a..7b5cac7 100644 --- a/src/test/java/de/platon42/intellij/plugins/m68k/refs/M68kReferenceContributorTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/m68k/refs/M68kReferenceContributorTest.kt @@ -1,5 +1,6 @@ package de.platon42.intellij.plugins.m68k.refs +import com.intellij.codeInsight.lookup.LookupElementBuilder import com.intellij.psi.PsiElement import com.intellij.testFramework.fixtures.CodeInsightTestFixture import de.platon42.intellij.jupiter.LightCodeInsightExtension @@ -8,6 +9,7 @@ import de.platon42.intellij.jupiter.TestDataPath import de.platon42.intellij.jupiter.TestDataSubPath import de.platon42.intellij.plugins.m68k.AbstractM68kTest import de.platon42.intellij.plugins.m68k.psi.M68kLocalLabel +import de.platon42.intellij.plugins.m68k.psi.M68kSymbolReference import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -18,20 +20,20 @@ import org.junit.jupiter.api.extension.ExtendWith internal class M68kReferenceContributorTest : AbstractM68kTest() { @Test - internal fun reference_to_dot_local_label(@MyFixture myFixture: CodeInsightTestFixture) { -// val reference = myFixture.getReferenceAtCaretPositionWithAssertion("dot_local_label.asm") -// assertThat(reference.element).isInstanceOf(M68kSym) + internal fun reference_to_dot_local_label_can_be_renamed(@MyFixture myFixture: CodeInsightTestFixture) { myFixture.configureByFile("dot_local_label.asm") assertThat(myFixture.elementAtCaret).isInstanceOf(M68kLocalLabel::class.java) .extracting(PsiElement::getText).isEqualTo(".loop") + myFixture.renameElementAtCaret(".narf") + myFixture.checkResultByFile("dot_local_label_after_rename.asm") } @Test - internal fun reference_to_multiple_conditional_local_label_dollar(@MyFixture myFixture: CodeInsightTestFixture) { + internal fun reference_to_multiple_conditional_local_label_dollar_and_variants(@MyFixture myFixture: CodeInsightTestFixture) { val reference = myFixture.getReferenceAtCaretPositionWithAssertion("multiple_conditional_local_label_dollar.asm") - assertThat(reference.element).isInstanceOf(M68kLocalLabel::class.java) - myFixture.configureByFile("multiple_conditional_local_label_dollar.asm") - assertThat(myFixture.elementAtCaret).isInstanceOf(M68kLocalLabel::class.java) - .extracting(PsiElement::getText).isEqualTo("loop$") + assertThat(reference.element).isInstanceOf(M68kSymbolReference::class.java) + assertThat(reference.variants).hasOnlyElementsOfType(LookupElementBuilder::class.java) + .extracting { (it as LookupElementBuilder).lookupString } + .containsExactlyInAnyOrderElementsOf(listOf("loop$", "loop$", ".skip")) } } \ No newline at end of file diff --git a/src/test/resources/references/labels/dot_local_label_after_rename.asm b/src/test/resources/references/labels/dot_local_label_after_rename.asm new file mode 100644 index 0000000..a615587 --- /dev/null +++ b/src/test/resources/references/labels/dot_local_label_after_rename.asm @@ -0,0 +1,10 @@ + +main + tst.w d1 + beq.s .skip + moveq.l #42,d0 +.narf move.l d0,(a0)+ + dbra d0,.narf +.skip subq.w #1,d1 + beq.s .narf + rts