Created
February 12, 2018 15:31
-
-
Save suhininalex/f5f4ab004e3841f8fb09bbcbd3b78a3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class KotlinScope: LanguageScope { | |
override fun createTokenId(element: PsiElement): Short = when { | |
isKotlinMethodName(element) -> nonAnonimizedIndex(element) | |
else -> anonimizedIndex(element) | |
} | |
override fun isIndexedFile(fileType: FileType): Boolean { | |
return fileType.name == "Kotlin" | |
} | |
override fun findIndexableScope(file: PsiFile): List<PsiElement> { | |
return file.findChildren(::isScopeElement).map { it.lastChild } | |
} | |
override fun isIndexedElement(element: PsiElement): Boolean { | |
return !isCommonNoise(element) | |
} | |
private fun isScopeElement(psiElement: PsiElement): Boolean { | |
val typeString = psiElement.node.elementType.toString() | |
return typeString == "FUN" || typeString == "PROPERTY_ACCESSOR" | |
} | |
private fun isKotlinMethodName(element: PsiElement): Boolean { | |
return element.type == "IDENTIFIER" && | |
element.parent?.type == "REFERENCE_EXPRESSION" && | |
element.grandparent?.type == "CALL_EXPRESSION" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment