Skip to content

Commit

Permalink
feat(usage): enable to search for usage
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Oct 5, 2022
1 parent e9a1fe0 commit 0941be5
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.feakin.intellij.highlight

import com.feakin.intellij.lexer.FeakinLexerAdapter
import com.feakin.intellij.lexer.FkLexer
import com.feakin.intellij.lexer.FeakinElementTypes
import com.intellij.lexer.Lexer
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors
Expand All @@ -10,7 +10,7 @@ import com.intellij.psi.tree.IElementType

class FeakinSyntaxHighlighter : SyntaxHighlighterBase() {
override fun getHighlightingLexer(): Lexer {
return FeakinLexerAdapter()
return FkLexer()
}

override fun getTokenHighlights(tokenType: IElementType): Array<TextAttributesKey> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class FeakinBraceMatcher implements PairedBraceMatcher {
public class FkBraceMatcher implements PairedBraceMatcher {
private static final BracePair[] BRACE_PAIRS = {
new BracePair(FeakinElementTypes.LBRACE, FeakinElementTypes.RBRACE, true),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.feakin.intellij.ide.search

import com.intellij.find.findUsages.FindUsagesHandler
import com.intellij.psi.PsiElement

class FkFindUsagesHandler(psiElement: PsiElement, private val secondaryElements: Array<PsiElement>) : FindUsagesHandler(psiElement) {
override fun getSecondaryElements(): Array<PsiElement> = secondaryElements
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.feakin.intellij.ide.search

import com.feakin.intellij.psi.FeakinNamedElement
import com.intellij.find.findUsages.FindUsagesHandler
import com.intellij.find.findUsages.FindUsagesHandlerFactory
import com.intellij.psi.PsiElement

class FkFindUsagesHandlerFactory : FindUsagesHandlerFactory() {
override fun canFindUsages(element: PsiElement): Boolean = element is FeakinNamedElement

override fun createFindUsagesHandler(element: PsiElement, forHighlightUsages: Boolean): FindUsagesHandler {
val secondaryElements = if (!forHighlightUsages) findSecondaryElements(element) else emptyList()
return FkFindUsagesHandler(element, secondaryElements.toTypedArray())
}

private fun findSecondaryElements(element: PsiElement): List<PsiElement> {
return emptyList()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.feakin.intellij.ide.search

import com.feakin.intellij.psi.FeakinNamedElement
import com.intellij.lang.HelpID
import com.intellij.lang.findUsages.FindUsagesProvider
import com.intellij.psi.PsiElement

class FkFindUsagesProvider : FindUsagesProvider {
override fun getWordsScanner() = FkWordScanner()

override fun canFindUsagesFor(psiElement: PsiElement): Boolean = psiElement is FeakinNamedElement

override fun getHelpId(psiElement: PsiElement): String = HelpID.FIND_OTHER_USAGES

override fun getType(element: PsiElement): String = ""

override fun getDescriptiveName(element: PsiElement): String = (element as? FeakinNamedElement)?.name.orEmpty()

override fun getNodeText(element: PsiElement, useFullName: Boolean): String = ""

}
13 changes: 13 additions & 0 deletions src/main/kotlin/com/feakin/intellij/ide/search/FkWordScanner.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.feakin.intellij.ide.search

import com.feakin.intellij.lexer.FeakinElementTypes.*
import com.feakin.intellij.lexer.FkLexer
import com.intellij.lang.cacheBuilder.DefaultWordsScanner
import com.intellij.psi.tree.TokenSet

class FkWordScanner : DefaultWordsScanner(
FkLexer(),
TokenSet.create(IDENTIFIER),
TokenSet.create(BLOCK_COMMENT, COMMENT),
TokenSet.create(STRING_LITERAL)
)

This file was deleted.

5 changes: 5 additions & 0 deletions src/main/kotlin/com/feakin/intellij/lexer/FkLexer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.feakin.intellij.lexer

import com.intellij.lexer.FlexAdapter

class FkLexer : FlexAdapter(com.feakin.intellij.lexer._FeakinLexer(null))
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.feakin.intellij.parser
import com.feakin.intellij.FkFile
import com.feakin.intellij.FkLanguage
import com.feakin.intellij.lexer.FeakinElementTypes
import com.feakin.intellij.lexer.FeakinLexerAdapter
import com.feakin.intellij.lexer.FkLexer
import com.intellij.lang.ASTNode
import com.intellij.lang.ParserDefinition
import com.intellij.lang.PsiParser
Expand All @@ -18,13 +18,12 @@ import com.intellij.psi.tree.TokenSet

class FeakinParserDefinition : ParserDefinition {
companion object {
val WHITE_SPACES = TokenSet.create(TokenType.WHITE_SPACE)
val COMMENTS = TokenSet.create(FeakinElementTypes.COMMENT)
val FILE = IFileElementType(FkLanguage)
}

override fun createLexer(project: Project): Lexer {
return FeakinLexerAdapter()
return FkLexer()
}

override fun createParser(project: Project): PsiParser {
Expand Down
11 changes: 8 additions & 3 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
<lang.psiStructureViewFactory language="Feakin"
implementationClass="com.feakin.intellij.structure.FkStructureViewFactory"/>

<!-- Editor -->
<extendWordSelectionHandler implementation="com.feakin.intellij.ide.editor.FeakinBlockSelectionHandler"/>
<lang.foldingBuilder language="Feakin"
implementationClass="com.feakin.intellij.edit.FeakinFoldingBuilder"/>

<lang.commenter language="Feakin" implementationClass="com.feakin.intellij.completion.FeakinCommenter"/>
<lang.braceMatcher language="Feakin" implementationClass="com.feakin.intellij.ide.FeakinBraceMatcher"/>
<lang.braceMatcher language="Feakin" implementationClass="com.feakin.intellij.ide.FkBraceMatcher"/>


<!-- Editor -->
<extendWordSelectionHandler implementation="com.feakin.intellij.ide.editor.FeakinBlockSelectionHandler"/>
<!-- Navigate between useDomainObject and DomainObjectDecl -->
<stubIndex implementation="com.feakin.intellij.psi.stubs.FkNamedElementIndex"/>
<!-- TODO: add support for goto -->
Expand Down Expand Up @@ -66,6 +67,10 @@

<!-- Formatter -->
<lang.formatter language="Feakin" implementationClass="com.feakin.intellij.formatter.FkFormattingModelBuilder"/>

<!-- Usages Provider -->
<lang.findUsagesProvider language="Feakin" implementationClass="com.feakin.intellij.ide.search.FkFindUsagesProvider"/>
<findUsagesHandlerFactory implementation="com.feakin.intellij.ide.search.FkFindUsagesHandlerFactory"/>
</extensions>

<actions>
Expand Down

0 comments on commit 0941be5

Please sign in to comment.