修改bnf
This commit is contained in:
@@ -3,10 +3,7 @@ package me.zhouxi.slint.completion
|
||||
import com.intellij.codeInsight.completion.CompletionContributor
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import com.intellij.patterns.PlatformPatterns
|
||||
import me.zhouxi.slint.completion.provider.BasicTypeProvider
|
||||
import me.zhouxi.slint.completion.provider.ComponentProvider
|
||||
import me.zhouxi.slint.completion.provider.ElementKeywordProvider
|
||||
import me.zhouxi.slint.completion.provider.TopKeywordProvider
|
||||
import me.zhouxi.slint.completion.provider.*
|
||||
import me.zhouxi.slint.lang.psi.SlintTypes
|
||||
import me.zhouxi.slint.lang.psi.stubs.types.SlintFileElementType
|
||||
|
||||
@@ -38,6 +35,12 @@ class SlintCompletionContributor : CompletionContributor() {
|
||||
PlatformPatterns.psiElement().withAncestor(2, PlatformPatterns.psiElement(SlintTypes.ComponentBody)),
|
||||
ComponentProvider
|
||||
)
|
||||
//propertyBinding
|
||||
extend(
|
||||
CompletionType.BASIC,
|
||||
PlatformPatterns.psiElement().withAncestor(2, PlatformPatterns.psiElement(SlintTypes.ComponentBody)),
|
||||
PropertyBindingProvider
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package me.zhouxi.slint.completion.provider
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionParameters
|
||||
import com.intellij.codeInsight.completion.CompletionProvider
|
||||
import com.intellij.codeInsight.completion.CompletionResultSet
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder
|
||||
import com.intellij.icons.AllIcons
|
||||
import com.intellij.psi.util.parentOfType
|
||||
import com.intellij.util.ProcessingContext
|
||||
import me.zhouxi.slint.lang.psi.SlintComponent
|
||||
import me.zhouxi.slint.lang.psi.SlintSubComponent
|
||||
import me.zhouxi.slint.lang.psi.extension.inheritsProperties
|
||||
|
||||
object PropertyBindingProvider : CompletionProvider<CompletionParameters>() {
|
||||
override fun addCompletions(
|
||||
parameters: CompletionParameters,
|
||||
context: ProcessingContext,
|
||||
result: CompletionResultSet
|
||||
) {
|
||||
val element = parameters.position
|
||||
val subComponent = element.parentOfType<SlintSubComponent>()
|
||||
if (subComponent != null) {
|
||||
val component = subComponent.referenceIdentifier.reference?.resolve() as SlintComponent? ?: return
|
||||
val builders = component.inheritsProperties()
|
||||
.map { LookupElementBuilder.create(it).withTypeText(component.name).withIcon(AllIcons.Nodes.Property) }
|
||||
result.addAllElements(builders)
|
||||
} else {
|
||||
val component = element.parentOfType<SlintComponent>() ?: return
|
||||
val builders = component.inheritsProperties()
|
||||
.map { LookupElementBuilder.create(it).withTypeText(component.name).withIcon(AllIcons.Nodes.Property) }
|
||||
result.addAllElements(builders)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package me.zhouxi.slint.lang.psi.extension
|
||||
|
||||
import me.zhouxi.slint.lang.psi.SlintComponent
|
||||
import me.zhouxi.slint.lang.psi.SlintProperty
|
||||
|
||||
|
||||
fun SlintComponent.inheritsProperties(): List<SlintProperty> {
|
||||
val properties = this.componentBody?.propertyList ?: emptyList()
|
||||
val inherit =
|
||||
this.inheritDeclaration?.referenceIdentifier?.reference?.resolve() as SlintComponent? ?: return properties
|
||||
return properties + inherit.inheritsProperties()
|
||||
}
|
||||
@@ -41,7 +41,7 @@ class SlintReferenceContributor : PsiReferenceContributor() {
|
||||
psiElement(ComponentBody)
|
||||
)
|
||||
),
|
||||
PropertyReferenceProvider()
|
||||
PropertyReferenceProvider
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,18 +10,23 @@ import com.intellij.util.ProcessingContext
|
||||
import me.zhouxi.slint.lang.psi.SlintComponent
|
||||
import me.zhouxi.slint.lang.psi.SlintPropertyBinding
|
||||
import me.zhouxi.slint.lang.psi.SlintSubComponent
|
||||
import me.zhouxi.slint.lang.psi.extension.inheritsProperties
|
||||
import me.zhouxi.slint.lang.psi.utils.searchProperty
|
||||
|
||||
class PropertyReferenceProvider : PsiReferenceProvider() {
|
||||
object PropertyReferenceProvider : PsiReferenceProvider() {
|
||||
override fun getReferencesByElement(element: PsiElement, context: ProcessingContext): Array<PsiReference> {
|
||||
return arrayOf(PropertyReference(element))
|
||||
}
|
||||
|
||||
class PropertyReference(element: PsiElement) : PsiReferenceBase<PsiElement?>(element) {
|
||||
override fun resolve(): PsiElement? {
|
||||
val binding = element.parentOfType<SlintPropertyBinding>() ?: return null
|
||||
val parent = binding.parentOfTypes(SlintSubComponent::class, SlintComponent::class) ?: return null
|
||||
return searchProperty(parent) { it.propertyName?.textMatches(element) == true }
|
||||
val subComponent = element.parentOfType<SlintSubComponent>()
|
||||
if (subComponent != null) {
|
||||
val component = subComponent.referenceIdentifier.reference?.resolve() as SlintComponent? ?: return null
|
||||
return component.inheritsProperties().find { it.propertyName?.textMatches(element) == true }
|
||||
}
|
||||
val component = element.parentOfType<SlintComponent>() ?: return null
|
||||
return component.inheritsProperties().find { it.propertyName?.textMatches(element) == true }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user