diff --git a/src/main/grammar/main.bnf b/src/main/grammar/main.bnf index f9d58ed..ad3b0b8 100644 --- a/src/main/grammar/main.bnf +++ b/src/main/grammar/main.bnf @@ -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,15 +149,11 @@ 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 | PropertyChanged - | States | TwoWayBinding | PropertyBinding | ConditionalElement + | States | TwoWayBinding|PropertyBinding | ConditionalElement | RepetitionElement | SubComponent { recoverWhile(".*")=recoverWhileForComponentBody } @@ -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 } //----------- diff --git a/src/main/kotlin/me/zhouxi/slint/completion/SlintCompletionContributor.kt b/src/main/kotlin/me/zhouxi/slint/completion/SlintCompletionContributor.kt index 9be6699..4b982cb 100644 --- a/src/main/kotlin/me/zhouxi/slint/completion/SlintCompletionContributor.kt +++ b/src/main/kotlin/me/zhouxi/slint/completion/SlintCompletionContributor.kt @@ -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 ) } diff --git a/src/main/kotlin/me/zhouxi/slint/lang/psi/extension/SlintComponentEx.kt b/src/main/kotlin/me/zhouxi/slint/lang/psi/extension/SlintComponentEx.kt index d5d938f..d7fc712 100644 --- a/src/main/kotlin/me/zhouxi/slint/lang/psi/extension/SlintComponentEx.kt +++ b/src/main/kotlin/me/zhouxi/slint/lang/psi/extension/SlintComponentEx.kt @@ -5,7 +5,7 @@ import me.zhouxi.slint.lang.psi.SlintProperty fun SlintComponent.inheritsProperties(): List { - 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() diff --git a/src/main/kotlin/me/zhouxi/slint/lang/psi/utils/SlintPsiTreeUtils.kt b/src/main/kotlin/me/zhouxi/slint/lang/psi/utils/SlintPsiTreeUtils.kt index 910723e..6854ea5 100644 --- a/src/main/kotlin/me/zhouxi/slint/lang/psi/utils/SlintPsiTreeUtils.kt +++ b/src/main/kotlin/me/zhouxi/slint/lang/psi/utils/SlintPsiTreeUtils.kt @@ -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? { 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 searchElementInParents( @@ -115,18 +115,4 @@ fun searchElementInParents( } val inheritComponent = resolveReferencedComponent(component.inheritDeclaration?.referenceIdentifier) return searchElementInParents(inheritComponent, predicate, function) -} - -fun SlintComponent.currentDeclaredElements(): List { - val properties = this.componentBody?.propertyList ?: emptyList() - val callbacks = this.componentBody?.callbackList ?: emptyList() - return properties + callbacks -} - -fun SlintComponent.inheritDeclaredElements(): List { - 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() } \ No newline at end of file diff --git a/src/main/kotlin/me/zhouxi/slint/reference/SlintReferenceContributor.kt b/src/main/kotlin/me/zhouxi/slint/reference/SlintReferenceContributor.kt index ef304ba..37a6f2f 100644 --- a/src/main/kotlin/me/zhouxi/slint/reference/SlintReferenceContributor.kt +++ b/src/main/kotlin/me/zhouxi/slint/reference/SlintReferenceContributor.kt @@ -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