修改bnf
This commit is contained in:
@@ -4,6 +4,9 @@ import com.intellij.codeInsight.completion.*
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder
|
||||
import com.intellij.icons.AllIcons
|
||||
import com.intellij.patterns.PlatformPatterns
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.stubs.StubIndex
|
||||
import com.intellij.psi.util.childrenOfType
|
||||
import com.intellij.psi.util.parentOfType
|
||||
import com.intellij.util.ProcessingContext
|
||||
@@ -15,6 +18,7 @@ import me.zhouxi.slint.lang.psi.SlintPsiUtils.InternalTypes
|
||||
import me.zhouxi.slint.lang.psi.SlintTypes
|
||||
import me.zhouxi.slint.lang.psi.utils.exportedElements
|
||||
import me.zhouxi.slint.lang.psi.utils.inheritDeclaredElements
|
||||
import me.zhouxi.slint.stubs.StubKeys
|
||||
import me.zhouxi.slint.stubs.types.SlintFileElementType
|
||||
|
||||
class SlintCompletionContributor : CompletionContributor() {
|
||||
@@ -57,19 +61,17 @@ class SlintCompletionContributor : CompletionContributor() {
|
||||
context: ProcessingContext,
|
||||
result: CompletionResultSet
|
||||
) {
|
||||
val project = parameters.position.project
|
||||
val components = StubIndex.getInstance().getAllKeys(StubKeys.Component, project).map {
|
||||
LookupElementBuilder.create(it).withIcon(AllIcons.Nodes.Class)
|
||||
}
|
||||
result.addAllElements(components)
|
||||
result.addAllElements(ElementKeywords)
|
||||
val component = parameters.position.parentOfType<SlintComponent>() ?: return
|
||||
val elements = component.inheritDeclaredElements()
|
||||
for (element in elements) {
|
||||
result.addElement(LookupElementBuilder.create(element).withIcon(AllIcons.Nodes.Property))
|
||||
}
|
||||
val file = component.containingFile as SlintFile
|
||||
val array = file.childrenOfType<SlintImport>()
|
||||
.mapNotNull { it.moduleLocation?.reference?.resolve() as SlintFile? }
|
||||
.flatMap { it.exportedElements() }
|
||||
for (element in array) {
|
||||
result.addElement(LookupElementBuilder.create(element).withIcon(AllIcons.Nodes.Class))
|
||||
val currentComponent = parameters.position.parentOfType<SlintComponent>() ?: return
|
||||
val elements = currentComponent.inheritDeclaredElements().map {
|
||||
LookupElementBuilder.create(it).withIcon(AllIcons.Nodes.Property)
|
||||
}
|
||||
result.addAllElements(elements)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import me.zhouxi.slint.lang.psi.SlintPsiNamedElement
|
||||
abstract class SlintPsiNamedElementMixinImpl(node: ASTNode) : SlintPsiElementImpl(node),
|
||||
SlintPsiNamedElement {
|
||||
override fun getNameIdentifier(): PsiElement? {
|
||||
return findChildByClass(SlintNamed::class.java)
|
||||
return findChildByClass(SlintNamed::class.java) ?: this
|
||||
}
|
||||
|
||||
override fun getName(): String? {
|
||||
@@ -26,7 +26,12 @@ abstract class SlintPsiNamedElementMixinImpl(node: ASTNode) : SlintPsiElementImp
|
||||
}
|
||||
|
||||
override fun getTextOffset(): Int {
|
||||
return nameIdentifier?.textOffset ?: super.getTextOffset()
|
||||
val identifier = nameIdentifier
|
||||
return if (identifier == this) {
|
||||
return super.getTextOffset()
|
||||
} else {
|
||||
identifier!!.textOffset
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(IncorrectOperationException::class)
|
||||
|
||||
@@ -7,29 +7,29 @@ import me.zhouxi.slint.lang.psi.*
|
||||
|
||||
fun SlintExport.exportedElements(): List<SlintPsiNamedElement> {
|
||||
val list = mutableListOf<SlintPsiNamedElement>()
|
||||
this.exportType?.exportIdentifierList?.forEach {
|
||||
if (it.externalName == null) {
|
||||
val component = it.referenceIdentifier.reference?.resolve() as SlintComponent?
|
||||
component?.let { list.add(component) }
|
||||
} else {
|
||||
list.add(it.externalName!!)
|
||||
}
|
||||
}
|
||||
this.component?.let { list.add(it) }
|
||||
this.globalSingleton?.let { list.add(it) }
|
||||
val file = this.exportModule?.moduleLocation?.reference?.resolve() as SlintFile? ?: return list
|
||||
val exports = file.childrenOfType<SlintExport>()
|
||||
//TODO recursion error
|
||||
exports.forEach { list.addAll(it.exportedElements()) }
|
||||
// this.exportType?.exportIdentifierList?.forEach {
|
||||
// if (it.externalName == null) {
|
||||
// val component = it.referenceIdentifier.reference?.resolve() as SlintComponent?
|
||||
// component?.let { list.add(component) }
|
||||
// } else {
|
||||
// list.add(it.externalName!!)
|
||||
// }
|
||||
// }
|
||||
// this.component?.let { list.add(it) }
|
||||
// this.globalSingleton?.let { list.add(it) }
|
||||
// val file = this.exportModule?.moduleLocation?.reference?.resolve() as SlintFile? ?: return list
|
||||
// val exports = file.childrenOfType<SlintExport>()
|
||||
// //TODO recursion error
|
||||
// exports.forEach { list.addAll(it.exportedElements()) }
|
||||
return list
|
||||
}
|
||||
|
||||
fun SlintImport.importedElements(): List<PsiElement> {
|
||||
val list = mutableListOf<PsiElement>()
|
||||
this.importedIdentifierList.forEach { identifier ->
|
||||
list.add(identifier.referenceIdentifier)
|
||||
identifier.internalName?.let { list.add(it) }
|
||||
}
|
||||
// this.importedIdentifierList.forEach { identifier ->
|
||||
// list.add(identifier.referenceIdentifier)
|
||||
// identifier.internalName?.let { list.add(it) }
|
||||
// }
|
||||
return list
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ class SlintReferenceContributor : PsiReferenceContributor() {
|
||||
psiElement(SubComponent),
|
||||
psiElement(Component),
|
||||
psiElement(InheritDeclaration),
|
||||
psiElement(ImportedIdentifier),
|
||||
psiElement(ExportIdentifier)
|
||||
// psiElement(ImportedIdentifier),
|
||||
// psiElement(ExportIdentifier)
|
||||
)
|
||||
),
|
||||
ComponentReferenceProvider()
|
||||
|
||||
@@ -28,12 +28,6 @@ class ComponentReferenceProvider : PsiReferenceProvider() {
|
||||
if (component != null) {
|
||||
return component
|
||||
}
|
||||
// TODO psiTreeUtils
|
||||
//然后是导出的组件 maybe component or externalName
|
||||
val externalElement = file.exportedElements().firstOrNull { it.textMatches(element) }
|
||||
if (externalElement != null) {
|
||||
return externalElement
|
||||
}
|
||||
//maybe internalName or referencedIdentifier;
|
||||
val element = file.importedElements().firstOrNull { it.textMatches(element) } ?: return null
|
||||
if (element is SlintPsiReferencedIdentifier) {
|
||||
@@ -44,13 +38,5 @@ class ComponentReferenceProvider : PsiReferenceProvider() {
|
||||
}
|
||||
return element
|
||||
}
|
||||
|
||||
override fun getVariants(): Array<Any> {
|
||||
val file = element.containingFile as SlintFile
|
||||
val array: Array<Any> = file.childrenOfType<SlintImport>()
|
||||
.mapNotNull { it.moduleLocation?.reference?.resolve() as SlintFile? }
|
||||
.flatMap { it.exportedElements() }.toTypedArray()
|
||||
return array
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package me.zhouxi.slint.reference.provider
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiReference
|
||||
import com.intellij.psi.PsiReferenceBase
|
||||
import com.intellij.psi.PsiReferenceProvider
|
||||
import com.intellij.psi.util.parentOfType
|
||||
import com.intellij.util.ProcessingContext
|
||||
import me.zhouxi.slint.lang.psi.SlintFile
|
||||
import me.zhouxi.slint.lang.psi.SlintImport
|
||||
import me.zhouxi.slint.lang.psi.SlintInternalName
|
||||
import me.zhouxi.slint.lang.psi.utils.exportedElements
|
||||
|
||||
/**
|
||||
* @author zhouxi 2024/5/17
|
||||
*/
|
||||
class InternalNameReferenceProvider : PsiReferenceProvider() {
|
||||
override fun getReferencesByElement(element: PsiElement, context: ProcessingContext): Array<PsiReference> {
|
||||
return arrayOf(InternalNameReference(element as SlintInternalName))
|
||||
}
|
||||
|
||||
class InternalNameReference(element: SlintInternalName) : PsiReferenceBase<SlintInternalName?>(element) {
|
||||
override fun resolve(): PsiElement? {
|
||||
val slintImport = element.parentOfType<SlintImport>() ?: return null
|
||||
val slintFile = slintImport.moduleLocation?.reference?.resolve() as? SlintFile ?: return null
|
||||
return slintFile.exportedElements().firstOrNull { it.textMatches(element) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,18 @@ package me.zhouxi.slint.stubs.impl
|
||||
|
||||
import com.intellij.psi.stubs.PsiFileStubImpl
|
||||
import com.intellij.psi.tree.IStubFileElementType
|
||||
import me.zhouxi.slint.lang.psi.SlintComponent
|
||||
import me.zhouxi.slint.lang.psi.SlintFile
|
||||
import me.zhouxi.slint.lang.psi.SlintTypes
|
||||
import me.zhouxi.slint.stubs.stub.SlintFileStub
|
||||
import me.zhouxi.slint.stubs.types.SlintComponentStubType
|
||||
import me.zhouxi.slint.stubs.types.SlintFileElementType
|
||||
|
||||
/**
|
||||
* @author zhouxi 2024/5/23
|
||||
*/
|
||||
class SlintFileStubImpl(file: SlintFile) : PsiFileStubImpl<SlintFile>(file), SlintFileStub {
|
||||
class SlintFileStubImpl(file: SlintFile?) : PsiFileStubImpl<SlintFile>(file), SlintFileStub {
|
||||
|
||||
override fun getType() = SlintFileElementType
|
||||
|
||||
override fun getType(): IStubFileElementType<*> {
|
||||
return SlintFileElementType
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,5 @@ import me.zhouxi.slint.lang.psi.SlintComponent
|
||||
import me.zhouxi.slint.stubs.StubKeys
|
||||
|
||||
class ComponentNameIndex : StringStubIndexExtension<SlintComponent>() {
|
||||
override fun getKey(): StubIndexKey<String, SlintComponent> {
|
||||
return StubKeys.Component
|
||||
}
|
||||
override fun getKey() = StubKeys.Component
|
||||
}
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
package me.zhouxi.slint.stubs.stub;
|
||||
package me.zhouxi.slint.stubs.stub
|
||||
|
||||
import com.intellij.psi.stubs.PsiFileStub;
|
||||
import me.zhouxi.slint.lang.psi.SlintFile;
|
||||
import com.intellij.psi.stubs.PsiFileStub
|
||||
import me.zhouxi.slint.lang.psi.SlintComponent
|
||||
import me.zhouxi.slint.lang.psi.SlintFile
|
||||
import me.zhouxi.slint.lang.psi.SlintTypes
|
||||
import me.zhouxi.slint.stubs.types.SlintFileElementType
|
||||
|
||||
public interface SlintFileStub extends PsiFileStub<SlintFile> {
|
||||
interface SlintFileStub : PsiFileStub<SlintFile> {
|
||||
|
||||
val components: Array<SlintComponent>
|
||||
get() = getChildrenByType(SlintTypes.Component) {
|
||||
arrayOfNulls<SlintComponent>(it)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,20 +4,20 @@ import com.intellij.lang.ASTNode
|
||||
import com.intellij.lang.LighterAST
|
||||
import com.intellij.lang.LighterASTNode
|
||||
import com.intellij.lang.LighterASTTokenNode
|
||||
import com.intellij.lang.TreeBackedLighterAST
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.impl.search.JavaSourceFilterScope
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.stubs.*
|
||||
import com.intellij.psi.util.parentOfType
|
||||
import me.zhouxi.slint.lang.SlintLanguage
|
||||
import me.zhouxi.slint.lang.psi.SlintComponent
|
||||
import me.zhouxi.slint.lang.psi.SlintExport
|
||||
import me.zhouxi.slint.lang.psi.SlintTypes.ComponentName
|
||||
import me.zhouxi.slint.lang.psi.SlintTypes.Export
|
||||
import me.zhouxi.slint.lang.psi.SlintTypes.*
|
||||
import me.zhouxi.slint.lang.psi.impl.SlintComponentImpl
|
||||
import me.zhouxi.slint.stubs.StubKeys
|
||||
import me.zhouxi.slint.stubs.impl.SlintComponentStubImpl
|
||||
import me.zhouxi.slint.stubs.stub.SlintComponentStub
|
||||
import org.mozilla.javascript.ast.AstNode
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
@@ -37,7 +37,7 @@ class SlintComponentStubType(debugName: String) :
|
||||
return SlintComponentStubImpl(
|
||||
parentStub,
|
||||
this,
|
||||
psi.parentOfType<SlintExport>() != null,
|
||||
psi.exportKeyword != null,
|
||||
psi.componentName!!.text
|
||||
)
|
||||
}
|
||||
@@ -60,15 +60,7 @@ class SlintComponentStubType(debugName: String) :
|
||||
}
|
||||
|
||||
override fun createStub(tree: LighterAST, node: LighterASTNode, parentStub: StubElement<*>): SlintComponentStub {
|
||||
var exported = false
|
||||
var parent = tree.getParent(node)
|
||||
while (parent != null) {
|
||||
if (parent.tokenType == Export) {
|
||||
exported = true
|
||||
break
|
||||
}
|
||||
parent = tree.getParent(parent)
|
||||
}
|
||||
val exported = tree.getChildren(node).any { it.tokenType == ExportKeyword }
|
||||
val identifier = tree.getChildren(node).first { it.tokenType == ComponentName }
|
||||
val token = tree.getChildren(identifier)[0] as LighterASTTokenNode
|
||||
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
package me.zhouxi.slint.stubs.types
|
||||
|
||||
import com.intellij.psi.stubs.StubElement
|
||||
import com.intellij.psi.stubs.StubInputStream
|
||||
import com.intellij.psi.tree.ILightStubFileElementType
|
||||
import me.zhouxi.slint.lang.SlintLanguage
|
||||
import me.zhouxi.slint.stubs.impl.SlintFileStubImpl
|
||||
import me.zhouxi.slint.stubs.stub.SlintFileStub
|
||||
|
||||
object SlintFileElementType : ILightStubFileElementType<SlintFileStubImpl?>("SlintFile", SlintLanguage.INSTANCE) {
|
||||
object SlintFileElementType : ILightStubFileElementType<SlintFileStub>("SlintFile", SlintLanguage.INSTANCE) {
|
||||
|
||||
override fun getStubVersion(): Int {
|
||||
return 1
|
||||
}
|
||||
|
||||
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>?): SlintFileStub {
|
||||
return SlintFileStubImpl(null)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user