fix: 语法问题
This commit is contained in:
@@ -4,7 +4,7 @@ import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class SlintElementType extends IElementType {
|
||||
public class SlintElementType extends IElementType {
|
||||
|
||||
|
||||
public SlintElementType(@NonNls @NotNull String rawKind) {
|
||||
|
||||
12
src/main/java/me/zhouxi/slint/lang/psi/SlintParserUtil.java
Normal file
12
src/main/java/me/zhouxi/slint/lang/psi/SlintParserUtil.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package me.zhouxi.slint.lang.psi;
|
||||
|
||||
import com.intellij.lang.PsiBuilder;
|
||||
import com.intellij.lang.parser.GeneratedParserUtilBase;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
|
||||
/**
|
||||
* @author zhouxi 2024/5/30
|
||||
*/
|
||||
public class SlintParserUtil extends GeneratedParserUtilBase {
|
||||
|
||||
}
|
||||
37
src/main/java/me/zhouxi/slint/lang/psi/SlintPsiKeyword.java
Normal file
37
src/main/java/me/zhouxi/slint/lang/psi/SlintPsiKeyword.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package me.zhouxi.slint.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import me.zhouxi.slint.lang.SlintElementType;
|
||||
import me.zhouxi.slint.lang.psi.impl.SlintPsiElementImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface SlintPsiKeyword extends SlintPsiElement {
|
||||
|
||||
|
||||
abstract class Impl extends SlintPsiElementImpl implements SlintPsiKeyword {
|
||||
|
||||
public Impl(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SlintKeyword:" + getText();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static ElementType type(String debugName) {
|
||||
return ElementType.TYPE;
|
||||
}
|
||||
|
||||
|
||||
class ElementType extends SlintElementType {
|
||||
|
||||
public static final ElementType TYPE = new ElementType("SlintKeyword");
|
||||
|
||||
private ElementType(@NotNull String debugName) {
|
||||
super(debugName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package me.zhouxi.slint.lang.psi.keyword;
|
||||
|
||||
import me.zhouxi.slint.lang.psi.SlintPsiElement;
|
||||
|
||||
public interface SlintPsiKeywordIdentifier extends SlintPsiElement {
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package me.zhouxi.slint.lang.psi.keyword;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import me.zhouxi.slint.lang.psi.impl.SlintPsiElementImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class SlintPsiKeywordIdentifierImpl extends SlintPsiElementImpl implements SlintPsiKeywordIdentifier {
|
||||
|
||||
public SlintPsiKeywordIdentifierImpl(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SlintKeyword:" + getText();
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.intellij.lang.ASTNode
|
||||
import com.intellij.psi.TokenType
|
||||
import com.intellij.psi.formatter.common.AbstractBlock
|
||||
import com.intellij.psi.tree.TokenSet
|
||||
import me.zhouxi.slint.lang.psi.SlintPsiKeyword
|
||||
import me.zhouxi.slint.lang.psi.SlintTypes
|
||||
import me.zhouxi.slint.lang.psi.SlintTypes.*
|
||||
import me.zhouxi.slint.lang.psi.utils.braces
|
||||
@@ -27,7 +28,7 @@ class FormattingBlock(
|
||||
var current = childBlocks
|
||||
var myIndent: Indent? = indent
|
||||
for (child in node.getChildren(null)) {
|
||||
if (braces.contains(child.elementType) && (node.elementType == SubComponent || node.elementType == Component)) {
|
||||
if (braces.contains(child.elementType) && syntheticParentTokens.contains(node.elementType)) {
|
||||
current = syntheticBlocks
|
||||
myIndent = Indent.getNormalIndent()
|
||||
}
|
||||
@@ -65,15 +66,20 @@ class FormattingBlock(
|
||||
|
||||
companion object {
|
||||
val leafTokens =
|
||||
TokenSet.orSet(
|
||||
TokenSet.create(
|
||||
ReferenceIdentifier,
|
||||
ComponentName,
|
||||
InternalName,
|
||||
LocalVariable,
|
||||
PropertyName
|
||||
),
|
||||
keywords
|
||||
PropertyName,
|
||||
PropertyModifier,
|
||||
SlintPsiKeyword.ElementType.TYPE
|
||||
)
|
||||
}
|
||||
|
||||
private val syntheticParentTokens = TokenSet.create(
|
||||
SubComponent,
|
||||
Component,
|
||||
GlobalSingleton
|
||||
)
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ class SlintFormatterModelBuilder : FormattingModelBuilder {
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private fun createSpaceBuilder(settings: CodeStyleSettings): SpacingBuilder {
|
||||
return SpacingBuilder(settings, SlintLanguage.INSTANCE)
|
||||
.after(Comma)
|
||||
@@ -56,6 +55,8 @@ class SlintFormatterModelBuilder : FormattingModelBuilder {
|
||||
.spacing(1, 1, 0, true, 2)
|
||||
.around(keywords)
|
||||
.spaces(1)
|
||||
.after(RAngle)
|
||||
.spaces(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,7 @@ class SyntheticBlock(
|
||||
override fun getAlignment() = alignment
|
||||
|
||||
override fun getSpacing(child1: Block?, child2: Block): Spacing? {
|
||||
if (child2 is ASTBlock && child2.node!!.elementType == SlintTypes.Semicolon) {
|
||||
return Spacing.createSpacing(1, 1, 0, true, 2)
|
||||
}
|
||||
//如果是连续的{}
|
||||
if (child1 is ASTBlock && child2 is ASTBlock
|
||||
&& child1.node!!.elementType == LBrace && child2.node!!.elementType == RBrace
|
||||
) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.intellij.lang.annotation.HighlightSeverity
|
||||
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors
|
||||
import com.intellij.psi.PsiElement
|
||||
import me.zhouxi.slint.lang.psi.*
|
||||
import me.zhouxi.slint.lang.psi.keyword.SlintPsiKeywordIdentifier
|
||||
import me.zhouxi.slint.lang.psi.SlintPsiKeyword
|
||||
|
||||
class KeywordHighlightAnnotator : Annotator {
|
||||
override fun annotate(element: PsiElement, holder: AnnotationHolder) {
|
||||
@@ -17,7 +17,7 @@ class KeywordHighlightAnnotator : Annotator {
|
||||
.create()
|
||||
return
|
||||
}
|
||||
if (element is SlintPsiKeywordIdentifier) {
|
||||
if (element is SlintPsiKeyword) {
|
||||
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
|
||||
.range(element)
|
||||
.textAttributes(Definitions._KeyWord)
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
<depends>com.intellij.modules.platform</depends>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<typedHandler implementation="me.zhouxi.slint.completion.SlintCompletionAutoPopupHandler" id="completionAutoPopup"
|
||||
<typedHandler implementation="me.zhouxi.slint.completion.SlintCompletionAutoPopupHandler"
|
||||
id="completionAutoPopup"
|
||||
order="first"/>
|
||||
<fileType name="Slint File"
|
||||
implementationClass="me.zhouxi.slint.lang.psi.SlintFileType"
|
||||
|
||||
Reference in New Issue
Block a user