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