删除componentBody
This commit is contained in:
@@ -68,7 +68,7 @@ private recoverTopElement ::= !('component' | 'struct' | 'enum' | 'global'| 'exp
|
||||
private DocumentElement ::= Import | Struct | Enum | GlobalSingleton | Component | Export {
|
||||
recoverWhile=recoverTopElement
|
||||
}
|
||||
GlobalSingleton ::= ExportKeyword? GlobalKeyword ComponentName ComponentBody {
|
||||
GlobalSingleton ::= ExportKeyword? GlobalKeyword ComponentName '{' ComponentElement* '}' {
|
||||
pin=2
|
||||
implements=["me.zhouxi.slint.lang.psi.SlintPsiNamedElement"]
|
||||
mixin="me.zhouxi.slint.lang.psi.impl.SlintPsiNamedElementImpl"
|
||||
@@ -135,7 +135,7 @@ ExportModule ::= '*' FromKeyword ModuleLocation ';'{
|
||||
pin=1
|
||||
}
|
||||
|
||||
Component ::= ExportKeyword? ComponentKeyword ComponentName InheritDeclaration? ComponentBody {
|
||||
Component ::= ExportKeyword? ComponentKeyword ComponentName InheritDeclaration? '{' ComponentElement* '}' {
|
||||
pin=2
|
||||
implements=[
|
||||
"me.zhouxi.slint.lang.psi.SlintPsiNamedElement"
|
||||
@@ -149,10 +149,6 @@ Component ::= ExportKeyword? ComponentKeyword ComponentName InheritDeclaration?
|
||||
InheritDeclaration ::= InheritsKeyword ReferenceIdentifier {
|
||||
pin=1
|
||||
}
|
||||
ComponentBody ::= '{' ComponentElement* '}'{
|
||||
pin=1
|
||||
recoverWhile=recoverWhileForComponentBody
|
||||
}
|
||||
//组件元素定义
|
||||
private ComponentElement ::=ChildrenPlaceholder| Property | Callback
|
||||
| Function | PropertyAnimation | CallbackConnection | Transitions
|
||||
@@ -245,7 +241,7 @@ RepetitionIndex ::= '[' LocalVariable ']'{
|
||||
}
|
||||
//--------------------------------SubElementDeclaration Start---------------------------------------------------
|
||||
//子组件结构元素定义
|
||||
SubComponent ::= (PropertyName ':=')? ReferenceIdentifier ComponentBody{
|
||||
SubComponent ::= (PropertyName ':=')? ReferenceIdentifier '{' ComponentElement* '}'{
|
||||
pin=3
|
||||
recoverWhile=recoverWhileForComponentBody
|
||||
}
|
||||
@@ -329,7 +325,7 @@ private QualifiedNamePropertyBinding::= QualifiedPropertyNameReference ':' Bindi
|
||||
PropertyBinding ::= ReferenceIdentifier ':' BindingStatement{
|
||||
pin=2
|
||||
}
|
||||
private WhileIdentifier::=!('}'|GenericIdentifier)
|
||||
private WhileIdentifier::=!('}'|';'|GenericIdentifier)
|
||||
//优先尝试表达式解析 {}属于代码块 {name:xx}属于表达式,那么需要预测后面两个token,第二个token不是':'的情况下才是代码块
|
||||
//所以优先判断对象创建判断,然后进行代码块判断,最后进行表达式
|
||||
//代码块分号可选
|
||||
@@ -339,10 +335,10 @@ BindingStatement ::=ObjectCreationExpressionWithSem|(CodeBlock ';'?)| Expression
|
||||
}
|
||||
//用于错误的直观化
|
||||
private ObjectCreationExpressionWithSem::=ObjectCreationExpression';'{
|
||||
pin=1
|
||||
pin=2
|
||||
}
|
||||
private ExpressionWithSem::= Expression ';'{
|
||||
pin=1
|
||||
pin=2
|
||||
}
|
||||
|
||||
//-----------
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.intellij.codeInsight.completion.CompletionType
|
||||
import com.intellij.patterns.PlatformPatterns
|
||||
import me.zhouxi.slint.completion.provider.*
|
||||
import me.zhouxi.slint.lang.psi.SlintTypes
|
||||
import me.zhouxi.slint.lang.psi.SlintTypes.Component
|
||||
import me.zhouxi.slint.lang.psi.stubs.types.SlintFileElementType
|
||||
|
||||
class SlintCompletionContributor : CompletionContributor() {
|
||||
@@ -26,19 +27,19 @@ class SlintCompletionContributor : CompletionContributor() {
|
||||
//componentBody
|
||||
extend(
|
||||
CompletionType.BASIC,
|
||||
PlatformPatterns.psiElement().withAncestor(2, PlatformPatterns.psiElement(SlintTypes.ComponentBody)),
|
||||
PlatformPatterns.psiElement().withAncestor(2, PlatformPatterns.psiElement(Component)),
|
||||
ElementKeywordProvider
|
||||
)
|
||||
//componentBody
|
||||
extend(
|
||||
CompletionType.BASIC,
|
||||
PlatformPatterns.psiElement().withAncestor(2, PlatformPatterns.psiElement(SlintTypes.ComponentBody)),
|
||||
PlatformPatterns.psiElement().withAncestor(2,PlatformPatterns.psiElement(Component)),
|
||||
ComponentProvider
|
||||
)
|
||||
//propertyBinding
|
||||
extend(
|
||||
CompletionType.BASIC,
|
||||
PlatformPatterns.psiElement().withAncestor(2, PlatformPatterns.psiElement(SlintTypes.ComponentBody)),
|
||||
PlatformPatterns.psiElement().withAncestor(2, PlatformPatterns.psiElement(Component)),
|
||||
PropertyBindingProvider
|
||||
)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import me.zhouxi.slint.lang.psi.SlintProperty
|
||||
|
||||
|
||||
fun SlintComponent.inheritsProperties(): List<SlintProperty> {
|
||||
val properties = this.componentBody?.propertyList ?: emptyList()
|
||||
val properties = this.propertyList
|
||||
val inherit =
|
||||
this.inheritDeclaration?.referenceIdentifier?.reference?.resolve() as SlintComponent? ?: return properties
|
||||
return properties + inherit.inheritsProperties()
|
||||
|
||||
@@ -75,7 +75,7 @@ fun searchProperty(
|
||||
return searchProperty(component, predicate)
|
||||
}
|
||||
if (component is SlintComponent) {
|
||||
return searchElementInParents(component, predicate) { it.componentBody?.propertyList }
|
||||
return searchElementInParents(component, predicate) { it.propertyList }
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -85,7 +85,7 @@ fun searchProperty(
|
||||
predicate: Predicate<SlintProperty>
|
||||
): SlintProperty? {
|
||||
val component = resolveComponent(subComponent?.referenceIdentifier) ?: return null
|
||||
return searchElementInParents(component, predicate) { it.componentBody?.propertyList }
|
||||
return searchElementInParents(component, predicate) { it.propertyList }
|
||||
}
|
||||
|
||||
fun searchCallback(
|
||||
@@ -96,7 +96,7 @@ fun searchCallback(
|
||||
return searchElementInParents(
|
||||
component as SlintComponent,
|
||||
predicate
|
||||
) { it.componentBody?.callbackList }
|
||||
) { it.callbackList }
|
||||
}
|
||||
|
||||
fun <T> searchElementInParents(
|
||||
@@ -116,17 +116,3 @@ fun <T> searchElementInParents(
|
||||
val inheritComponent = resolveReferencedComponent(component.inheritDeclaration?.referenceIdentifier)
|
||||
return searchElementInParents(inheritComponent, predicate, function)
|
||||
}
|
||||
|
||||
fun SlintComponent.currentDeclaredElements(): List<SlintPsiNamedElement> {
|
||||
val properties = this.componentBody?.propertyList ?: emptyList()
|
||||
val callbacks = this.componentBody?.callbackList ?: emptyList()
|
||||
return properties + callbacks
|
||||
}
|
||||
|
||||
fun SlintComponent.inheritDeclaredElements(): List<SlintPsiNamedElement> {
|
||||
val properties = this.componentBody?.propertyList ?: emptyList()
|
||||
val callbacks = this.componentBody?.callbackList ?: emptyList()
|
||||
val inheritedComponent = resolveReferencedComponent(this.inheritDeclaration?.referenceIdentifier)
|
||||
?: return properties + callbacks
|
||||
return properties + callbacks + inheritedComponent.inheritDeclaredElements()
|
||||
}
|
||||
@@ -23,7 +23,6 @@ class SlintReferenceContributor : PsiReferenceContributor() {
|
||||
psiElement(Component),
|
||||
psiElement(InheritDeclaration),
|
||||
psiElement(ImportSpecifier)
|
||||
// psiElement(ExportIdentifier)
|
||||
)
|
||||
),
|
||||
ComponentReferenceProvider
|
||||
@@ -38,7 +37,8 @@ class SlintReferenceContributor : PsiReferenceContributor() {
|
||||
psiElement().withParent(
|
||||
or(
|
||||
psiElement(PropertyBinding),
|
||||
psiElement(ComponentBody)
|
||||
psiElement(Component),
|
||||
psiElement(SubComponent)
|
||||
)
|
||||
),
|
||||
PropertyReferenceProvider
|
||||
|
||||
Reference in New Issue
Block a user