Skip to content

Commit

Permalink
feat: try to add navigator
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Sep 27, 2022
1 parent 6edfaa6 commit 5969ed3
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.feakin.intellij.ide.navigate

import com.feakin.intellij.FeakinLanguage
import com.feakin.intellij.psi.stubs.FkContextIndex
import com.intellij.lang.Language
import com.intellij.navigation.ChooseByNameContributorEx
import com.intellij.navigation.GotoClassContributor
import com.intellij.navigation.NavigationItem
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.stubs.StubIndex
import com.intellij.util.Processor
import com.intellij.util.indexing.FindSymbolParameters
import com.intellij.util.indexing.IdFilter

class FkDomainObjectNavigationContributor : GotoClassContributor, ChooseByNameContributorEx {
override fun processNames(processor: Processor<in String?>, scope: GlobalSearchScope, filter: IdFilter?) {
if (!StubIndex.getInstance()
.processAllKeys(FkContextIndex.KEY, processor, scope, filter)
) {
return
}
}

override fun processElementsWithName(
name: String,
processor: Processor<in NavigationItem>,
parameters: FindSymbolParameters
) {
}

override fun getQualifiedName(item: NavigationItem): String? {
return null
}

override fun getQualifiedNameSeparator(): String? {
return null
}

override fun getElementLanguage(): Language {
return FeakinLanguage
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import com.intellij.psi.stubs.StringStubIndexExtension
import com.intellij.psi.stubs.StubIndex
import com.intellij.psi.stubs.StubIndexKey

class FeakinContextDeclarationNameIndex : StringStubIndexExtension<FeakinContextDeclaration>() {
// todo: change to generic
class FkContextIndex : StringStubIndexExtension<FeakinContextDeclaration>() {
override fun getKey(): StubIndexKey<String, FeakinContextDeclaration> {
return KEY
}

companion object {
val KEY = StubIndexKey.createIndexKey<String, FeakinContextDeclaration>("feakin.declaration.shortName")
fun allKeys(project: Project?): Collection<String> {
Expand Down
34 changes: 34 additions & 0 deletions src/main/kotlin/com/feakin/intellij/psi/stubs/FkNamedElement.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.feakin.intellij.psi.stubs

import com.feakin.intellij.psi.FeakinNamedElement
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.stubs.StringStubIndexExtension
import com.intellij.psi.stubs.StubIndex
import com.intellij.psi.stubs.StubIndexKey

class FkNamedElementIndex : StringStubIndexExtension<FeakinNamedElement>() {
override fun getKey(): StubIndexKey<String, FeakinNamedElement> = KEY

companion object {
val KEY: StubIndexKey<String, FeakinNamedElement> =
StubIndexKey.createIndexKey("com.feakin.intellij.psi.stubs.index.FkNamedElementIndex")

fun findElementsByName(
project: Project,
target: String,
scope: GlobalSearchScope = GlobalSearchScope.allScope(project)
): Collection<FeakinNamedElement> {
return getElements(KEY, target, project, scope)
}
}
}

inline fun <Key, reified Psi : PsiElement> getElements(
indexKey: StubIndexKey<Key, Psi>,
key: Key, project: Project,
scope: GlobalSearchScope?
): Collection<Psi> =
StubIndex.getElements(indexKey, key, project, scope, Psi::class.java)

7 changes: 5 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
<depends>com.intellij.modules.platform</depends>

<extensions defaultExtensionNs="com.intellij">
<stubIndex implementation="com.feakin.intellij.psi.stubs.FeakinContextDeclarationNameIndex"/>

<!-- File-type Factory -->
<fileType name="Feakin File"
language="Feakin"
Expand All @@ -34,6 +32,11 @@
<lang.commenter language="Feakin" implementationClass="com.feakin.intellij.completion.FeakinCommenter"/>
<lang.braceMatcher language="Feakin" implementationClass="com.feakin.intellij.ide.FeakinBraceMatcher"/>

<!-- Editor -->
<extendWordSelectionHandler implementation="com.feakin.intellij.ide.editor.FeakinBlockSelectionHandler"/>
<!-- Navigate between useDomainObject and DomainObjectDecl -->
<stubIndex implementation="com.feakin.intellij.psi.stubs.FkNamedElementIndex"/>
<stubIndex implementation="com.feakin.intellij.psi.stubs.FkContextIndex"/>
<gotoClassContributor implementation="com.feakin.intellij.ide.navigate.FkDomainObjectNavigationContributor"/>
</extensions>
</idea-plugin>

0 comments on commit 5969ed3

Please sign in to comment.