diff --git a/src/main/java/de/platon42/intellij/plugins/m68k/refs/M68kGlobalLabelSymbolReference.kt b/src/main/java/de/platon42/intellij/plugins/m68k/refs/M68kGlobalLabelSymbolReference.kt index 1307289..d576e89 100644 --- a/src/main/java/de/platon42/intellij/plugins/m68k/refs/M68kGlobalLabelSymbolReference.kt +++ b/src/main/java/de/platon42/intellij/plugins/m68k/refs/M68kGlobalLabelSymbolReference.kt @@ -8,6 +8,9 @@ import com.intellij.psi.PsiPolyVariantReferenceBase import com.intellij.psi.ResolveResult import com.intellij.psi.impl.source.resolve.ResolveCache import com.intellij.psi.search.GlobalSearchScope +import com.intellij.psi.search.PsiSearchHelper +import com.intellij.psi.search.UsageSearchContext +import com.intellij.util.SmartList import de.platon42.intellij.plugins.m68k.psi.M68kGlobalLabel import de.platon42.intellij.plugins.m68k.psi.M68kLookupUtil import de.platon42.intellij.plugins.m68k.psi.M68kSymbolDefinition @@ -19,28 +22,34 @@ class M68kGlobalLabelSymbolReference(element: M68kSymbolReference) : companion object { val INSTANCE = Resolver() - fun findGlobalLabels(element: M68kSymbolReference, predicate: (M68kGlobalLabel) -> Boolean): List { - return M68kLookupUtil.findAllGlobalLabels(element.project).filter(predicate) - } + fun findGlobalLabels(element: M68kSymbolReference, predicate: (M68kGlobalLabel) -> Boolean): List = + M68kLookupUtil.findAllGlobalLabels(element.project).filter(predicate) - fun findSymbolDefinitions(element: M68kSymbolReference, predicate: (M68kSymbolDefinition) -> Boolean): List { - return M68kLookupUtil.findAllSymbolDefinitions(element.project).filter(predicate) - } - - private fun getCurrentFileSearchScope(element: PsiElement): GlobalSearchScope { - return GlobalSearchScope.fileScope(element.containingFile.originalFile) - } + fun findSymbolDefinitions(element: M68kSymbolReference, predicate: (M68kSymbolDefinition) -> Boolean): List = + M68kLookupUtil.findAllSymbolDefinitions(element.project).filter(predicate) } class Resolver : ResolveCache.PolyVariantResolver { override fun resolve(ref: M68kGlobalLabelSymbolReference, incompleteCode: Boolean): Array { val refName = ref.element.symbolName + val project = ref.element.project + val targets: MutableList = SmartList() + PsiSearchHelper.getInstance(project).processElementsWithWord( + { elem, offset -> + when (elem) { + is M68kGlobalLabel, is M68kSymbolDefinition -> targets.add(elem) + } + true + }, GlobalSearchScope.allScope(project), + refName, UsageSearchContext.IN_CODE, true + ) + val globalLabelMatches: Array = findGlobalLabels(ref.myElement) { it.name == refName } .map { PsiElementResolveResult(it) } .toTypedArray() if (globalLabelMatches.isNotEmpty()) return globalLabelMatches - return findSymbolDefinitions(ref.myElement) { it.name == refName } + return targets .map { PsiElementResolveResult(it) } .toTypedArray() } diff --git a/src/main/java/de/platon42/intellij/plugins/m68k/refs/M68kSymbolDefinitionReference.kt b/src/main/java/de/platon42/intellij/plugins/m68k/refs/M68kSymbolDefinitionReference.kt deleted file mode 100644 index 3398602..0000000 --- a/src/main/java/de/platon42/intellij/plugins/m68k/refs/M68kSymbolDefinitionReference.kt +++ /dev/null @@ -1,55 +0,0 @@ -package de.platon42.intellij.plugins.m68k.refs - -import com.intellij.codeInsight.lookup.LookupElementBuilder -import com.intellij.openapi.util.TextRange -import com.intellij.psi.PsiElement -import com.intellij.psi.PsiElementResolveResult -import com.intellij.psi.PsiPolyVariantReferenceBase -import com.intellij.psi.ResolveResult -import com.intellij.psi.impl.source.resolve.ResolveCache -import com.intellij.psi.search.GlobalSearchScope -import de.platon42.intellij.plugins.m68k.psi.M68kLookupUtil -import de.platon42.intellij.plugins.m68k.psi.M68kSymbolDefinition -import de.platon42.intellij.plugins.m68k.psi.M68kSymbolReference - -class M68kSymbolDefinitionReference(element: M68kSymbolReference) : - PsiPolyVariantReferenceBase(element, TextRange(0, element.textLength)) { - - companion object { - val INSTANCE = Resolver() - - fun findSymbolDefinitions(element: M68kSymbolReference, predicate: (M68kSymbolDefinition) -> Boolean): List { - return M68kLookupUtil.findAllSymbolDefinitions(element.project).filter(predicate) - } - - private fun getCurrentFileSearchScope(element: PsiElement): GlobalSearchScope { - return GlobalSearchScope.fileScope(element.containingFile.originalFile) - } - } - - class Resolver : ResolveCache.PolyVariantResolver { - override fun resolve(ref: M68kSymbolDefinitionReference, incompleteCode: Boolean): Array { - val refName = ref.element.symbolName - - return findSymbolDefinitions(ref.myElement) { it.name == refName } - .map { PsiElementResolveResult(it) } - .toTypedArray() - } - } - - override fun multiResolve(incompleteCode: Boolean): Array { - return ResolveCache.getInstance(element.project) - .resolveWithCaching(this, INSTANCE, false, incompleteCode) - } - - override fun resolve(): PsiElement? { - val resolveResults = multiResolve(false) - return resolveResults.singleOrNull()?.element - } - - override fun getVariants(): Array { - return findSymbolDefinitions(element) { true } - .map { LookupElementBuilder.createWithIcon(it) } - .toTypedArray() - } -} \ No newline at end of file diff --git a/src/main/java/de/platon42/intellij/plugins/m68k/scanner/M68kFindUsagesProvider.kt b/src/main/java/de/platon42/intellij/plugins/m68k/scanner/M68kFindUsagesProvider.kt index 542d178..2ec6dd1 100644 --- a/src/main/java/de/platon42/intellij/plugins/m68k/scanner/M68kFindUsagesProvider.kt +++ b/src/main/java/de/platon42/intellij/plugins/m68k/scanner/M68kFindUsagesProvider.kt @@ -19,7 +19,7 @@ class M68kFindUsagesProvider : FindUsagesProvider { M68kLexer(M68kLexerPrefs()), // FIXME Oh no! More Prefs! TokenSet.create(M68kTypes.SYMBOLDEF, M68kTypes.GLOBAL_LABEL_DEF, M68kTypes.LOCAL_LABEL_DEF, M68kTypes.SYMBOL), TokenSet.create(M68kTypes.COMMENT), - TokenSet.create(M68kTypes.STRINGLIT), + TokenSet.create(M68kTypes.STRINGLIT, M68kTypes.DECIMAL, M68kTypes.HEXADECIMAL, M68kTypes.OCTAL, M68kTypes.BINARY), TokenSet.EMPTY ) }