generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(usage): make context map to usage
- Loading branch information
Showing
4 changed files
with
58 additions
and
29 deletions.
There are no files selected for viewing
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
68 changes: 47 additions & 21 deletions
68
src/main/kotlin/com/feakin/intellij/resolve/ref/impl/FkContextDeclReferenceImpl.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,52 @@ | ||
package com.feakin.intellij.resolve.ref.impl | ||
|
||
import com.feakin.intellij.psi.FkContextDeclaration | ||
import com.feakin.intellij.psi.FkContextName | ||
import com.feakin.intellij.psi.FkElement | ||
import com.feakin.intellij.resolve.indexes.FkNamedElementIndex | ||
import com.feakin.intellij.FkFile | ||
import com.feakin.intellij.FkFileType | ||
import com.feakin.intellij.psi.* | ||
import com.feakin.intellij.resolve.ref.FkReferenceBase | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiManager | ||
import com.intellij.psi.search.FileTypeIndex | ||
import com.intellij.psi.search.GlobalSearchScope | ||
import com.intellij.psi.util.PsiTreeUtil | ||
|
||
// todo: change to contextNameRef | ||
//class FkContextDeclReferenceImpl( | ||
// element: FkContextDeclaration | ||
//) : FkReferenceBase<FkContextDeclaration>(element) { | ||
// override fun multiResolve(): List<FkElement> { | ||
// val collection = | ||
// FkNamedElementIndex.findElementsByName(element.identifier.text, element.project, element.resolveScope) | ||
// .filter { it is FkContextName } | ||
// .toCollection(mutableListOf()) | ||
// | ||
// return collection | ||
// } | ||
// | ||
// override fun isReferenceTo(element: PsiElement): Boolean { | ||
// return element is FkContextDeclaration && super.isReferenceTo(element) | ||
// } | ||
//} | ||
class FkContextDeclReferenceImpl( | ||
element: FkContextDeclaration | ||
) : FkReferenceBase<FkContextDeclaration>(element) { | ||
override fun multiResolve(): List<FkElement> { | ||
val project = element.project | ||
val scope = GlobalSearchScope.allScope(project) | ||
val collection = mutableListOf<FkElement>() | ||
|
||
val virtualFiles: Collection<VirtualFile> = FileTypeIndex.getFiles(FkFileType, scope) | ||
virtualFiles.forEach { virtualFile -> | ||
val fkFile = PsiManager.getInstance(project).findFile(virtualFile) as FkFile | ||
val fkDeclarations = PsiTreeUtil.getChildrenOfType(fkFile, FkDeclaration::class.java) | ||
|
||
val contextMaps: Array<out FkContextMapDeclaration>? = fkDeclarations?.mapNotNull { | ||
PsiTreeUtil.getChildrenOfType(it, FkContextMapDeclaration::class.java)?.toList() | ||
}?.flatten()?.toTypedArray() | ||
|
||
val mapBodys: Array<out FkContextMapBody>? = contextMaps?.mapNotNull { | ||
PsiTreeUtil.getChildrenOfType(it, FkContextMapBody::class.java)?.toList() | ||
}?.flatten()?.toTypedArray() | ||
|
||
mapBodys?.forEach { contextMapDeclaration -> | ||
PsiTreeUtil.getChildrenOfType(contextMapDeclaration, FkContextName::class.java) | ||
?.forEach { contextName -> | ||
if (contextName.text == element.name) { | ||
collection.add(contextName) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return collection | ||
} | ||
|
||
override fun isReferenceTo(element: PsiElement): Boolean { | ||
return element is FkContextDeclaration && super.isReferenceTo(element) | ||
} | ||
} | ||
|
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
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