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.NonNls;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public final class SlintElementType extends IElementType {
|
public class SlintElementType extends IElementType {
|
||||||
|
|
||||||
|
|
||||||
public SlintElementType(@NonNls @NotNull String rawKind) {
|
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.TokenType
|
||||||
import com.intellij.psi.formatter.common.AbstractBlock
|
import com.intellij.psi.formatter.common.AbstractBlock
|
||||||
import com.intellij.psi.tree.TokenSet
|
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.SlintTypes.*
|
import me.zhouxi.slint.lang.psi.SlintTypes.*
|
||||||
import me.zhouxi.slint.lang.psi.utils.braces
|
import me.zhouxi.slint.lang.psi.utils.braces
|
||||||
@@ -27,7 +28,7 @@ class FormattingBlock(
|
|||||||
var current = childBlocks
|
var current = childBlocks
|
||||||
var myIndent: Indent? = indent
|
var myIndent: Indent? = indent
|
||||||
for (child in node.getChildren(null)) {
|
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
|
current = syntheticBlocks
|
||||||
myIndent = Indent.getNormalIndent()
|
myIndent = Indent.getNormalIndent()
|
||||||
}
|
}
|
||||||
@@ -65,15 +66,20 @@ class FormattingBlock(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val leafTokens =
|
val leafTokens =
|
||||||
TokenSet.orSet(
|
TokenSet.create(
|
||||||
TokenSet.create(
|
ReferenceIdentifier,
|
||||||
ReferenceIdentifier,
|
ComponentName,
|
||||||
ComponentName,
|
InternalName,
|
||||||
InternalName,
|
LocalVariable,
|
||||||
LocalVariable,
|
PropertyName,
|
||||||
PropertyName
|
PropertyModifier,
|
||||||
),
|
SlintPsiKeyword.ElementType.TYPE
|
||||||
keywords
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val syntheticParentTokens = TokenSet.create(
|
||||||
|
SubComponent,
|
||||||
|
Component,
|
||||||
|
GlobalSingleton
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ class SlintFormatterModelBuilder : FormattingModelBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private fun createSpaceBuilder(settings: CodeStyleSettings): SpacingBuilder {
|
private fun createSpaceBuilder(settings: CodeStyleSettings): SpacingBuilder {
|
||||||
return SpacingBuilder(settings, SlintLanguage.INSTANCE)
|
return SpacingBuilder(settings, SlintLanguage.INSTANCE)
|
||||||
.after(Comma)
|
.after(Comma)
|
||||||
@@ -56,6 +55,8 @@ class SlintFormatterModelBuilder : FormattingModelBuilder {
|
|||||||
.spacing(1, 1, 0, true, 2)
|
.spacing(1, 1, 0, true, 2)
|
||||||
.around(keywords)
|
.around(keywords)
|
||||||
.spaces(1)
|
.spaces(1)
|
||||||
|
.after(RAngle)
|
||||||
|
.spaces(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,9 +33,7 @@ class SyntheticBlock(
|
|||||||
override fun getAlignment() = alignment
|
override fun getAlignment() = alignment
|
||||||
|
|
||||||
override fun getSpacing(child1: Block?, child2: Block): Spacing? {
|
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
|
if (child1 is ASTBlock && child2 is ASTBlock
|
||||||
&& child1.node!!.elementType == LBrace && child2.node!!.elementType == RBrace
|
&& 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.openapi.editor.DefaultLanguageHighlighterColors
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import me.zhouxi.slint.lang.psi.*
|
import me.zhouxi.slint.lang.psi.*
|
||||||
import me.zhouxi.slint.lang.psi.keyword.SlintPsiKeywordIdentifier
|
import me.zhouxi.slint.lang.psi.SlintPsiKeyword
|
||||||
|
|
||||||
class KeywordHighlightAnnotator : Annotator {
|
class KeywordHighlightAnnotator : Annotator {
|
||||||
override fun annotate(element: PsiElement, holder: AnnotationHolder) {
|
override fun annotate(element: PsiElement, holder: AnnotationHolder) {
|
||||||
@@ -17,7 +17,7 @@ class KeywordHighlightAnnotator : Annotator {
|
|||||||
.create()
|
.create()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (element is SlintPsiKeywordIdentifier) {
|
if (element is SlintPsiKeyword) {
|
||||||
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
|
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
|
||||||
.range(element)
|
.range(element)
|
||||||
.textAttributes(Definitions._KeyWord)
|
.textAttributes(Definitions._KeyWord)
|
||||||
|
|||||||
@@ -11,7 +11,8 @@
|
|||||||
<depends>com.intellij.modules.platform</depends>
|
<depends>com.intellij.modules.platform</depends>
|
||||||
|
|
||||||
<extensions defaultExtensionNs="com.intellij">
|
<extensions defaultExtensionNs="com.intellij">
|
||||||
<typedHandler implementation="me.zhouxi.slint.completion.SlintCompletionAutoPopupHandler" id="completionAutoPopup"
|
<typedHandler implementation="me.zhouxi.slint.completion.SlintCompletionAutoPopupHandler"
|
||||||
|
id="completionAutoPopup"
|
||||||
order="first"/>
|
order="first"/>
|
||||||
<fileType name="Slint File"
|
<fileType name="Slint File"
|
||||||
implementationClass="me.zhouxi.slint.lang.psi.SlintFileType"
|
implementationClass="me.zhouxi.slint.lang.psi.SlintFileType"
|
||||||
|
|||||||
Reference in New Issue
Block a user