initial commit
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
generate=[token-case="as-is" element-case="as-is"]
|
||||
parserClass="me.zhouxi.slint.lang.parser.SlintParser"
|
||||
implements="me.zhouxi.slint.lang.psi.SlintPsiElement"
|
||||
extends="me.zhouxi.slint.lang.psi.SlintPsiElementImpl"
|
||||
extends="me.zhouxi.slint.lang.psi.impl.SlintPsiElementImpl"
|
||||
elementTypeHolderClass="me.zhouxi.slint.lang.psi.SlintTypes"
|
||||
elementTypeClass="me.zhouxi.slint.lang.SlintElementType"
|
||||
tokenTypeClass="me.zhouxi.slint.lang.SlintTokenType"
|
||||
@@ -133,8 +133,12 @@ ExportModule ::= '*' FromKeyword ModuleLocation ';'{
|
||||
|
||||
Component ::= ComponentKeyword ComponentName InheritDeclaration? ComponentBody {
|
||||
pin=1
|
||||
implements=["me.zhouxi.slint.lang.psi.SlintPsiNamedElement"]
|
||||
mixin="me.zhouxi.slint.lang.psi.impl.SlintPsiNamedElementMixinImpl"
|
||||
implements=[
|
||||
"me.zhouxi.slint.lang.psi.SlintPsiNamedElement"
|
||||
"com.intellij.psi.StubBasedPsiElement<me.zhouxi.slint.stubs.stub.SlintComponentStub>"
|
||||
]
|
||||
stubClass="me.zhouxi.slint.stubs.stub.SlintComponentStub"
|
||||
mixin="me.zhouxi.slint.lang.psi.impl.SlintStubBasedPsiNamedElementImpl<me.zhouxi.slint.stubs.stub.SlintComponentStub>"
|
||||
}
|
||||
//组件定义
|
||||
//private LegacyComponent ::= (ComponentName|NamedIdentifier ':=' ) ComponentBody
|
||||
@@ -183,7 +187,7 @@ PropertyChanged ::= ChangedKeyword LocalVariable '=>' CodeBlock{
|
||||
// 回调定义 pure callback abc()->int; callback abc; callback(..);callback()->type;
|
||||
CallbackDeclaration ::= PureKeyword? CallbackKeyword FunctionName CallbackBinding? ';'{
|
||||
pin=2
|
||||
implements=["me.zhouxi.slint.lang.psi.SlintPsiNamedElement"]
|
||||
implements=["me.zhouxi.slint.lang.psi.SlintPsiNamedElement""me.zhouxi.slint.stubs.SlintPsiStubElement<>"]
|
||||
mixin="me.zhouxi.slint.lang.psi.impl.SlintPsiNamedElementMixinImpl"
|
||||
}
|
||||
//回调参数定义
|
||||
@@ -502,7 +506,7 @@ Named ::= PropertyName | TypeName |ExternalName | InternalName|ComponentName|Fu
|
||||
pin=1
|
||||
}
|
||||
{
|
||||
extends("PropertyName|TypeName|ComponentName|FunctionName")=Named
|
||||
extends("PropertyName|TypeName|ComponentName|FunctionName|InternalName|ExternalName")=Named
|
||||
}
|
||||
LocalVariable ::= GenericIdentifier{
|
||||
mixin="me.zhouxi.slint.lang.psi.impl.SlintPsiNamedElementMixinImpl"
|
||||
|
||||
@@ -8,7 +8,7 @@ public final class SlintElementType extends IElementType {
|
||||
|
||||
|
||||
public SlintElementType(@NonNls @NotNull String rawKind) {
|
||||
super(rawKind, Slint.INSTANCE);
|
||||
super(rawKind, SlintLanguage.INSTANCE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@ import static com.intellij.openapi.util.IconLoader.getIcon;
|
||||
/**
|
||||
* @author zhouxi 2024/4/30
|
||||
*/
|
||||
public class Slint extends Language {
|
||||
public class SlintLanguage extends Language {
|
||||
|
||||
public static final Slint INSTANCE = new Slint();
|
||||
public static final SlintLanguage INSTANCE = new SlintLanguage();
|
||||
|
||||
protected Slint() {
|
||||
protected SlintLanguage() {
|
||||
super("Slint");
|
||||
}
|
||||
|
||||
public static final Icon ICON = getIcon("META-INF/pluginIcon.svg", Slint.class);
|
||||
public static final Icon ICON = getIcon("META-INF/pluginIcon.svg", SlintLanguage.class);
|
||||
}
|
||||
@@ -10,11 +10,14 @@ import com.intellij.psi.FileViewProvider;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.tree.IFileElementType;
|
||||
import com.intellij.psi.tree.ILightStubFileElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import me.zhouxi.slint.lang.lexer.SlintLexer;
|
||||
import me.zhouxi.slint.lang.parser.SlintParser;
|
||||
import me.zhouxi.slint.lang.psi.SlintFile;
|
||||
import me.zhouxi.slint.lang.psi.SlintTypes;
|
||||
import me.zhouxi.slint.stubs.impl.SlintFileStub;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static me.zhouxi.slint.lang.psi.SlintTypes.*;
|
||||
@@ -38,7 +41,12 @@ public class SlintParserDefinition implements ParserDefinition {
|
||||
return FileType;
|
||||
}
|
||||
|
||||
public static final IFileElementType FileType = new IFileElementType("SlintFile",Slint.INSTANCE);
|
||||
public static final ILightStubFileElementType<SlintFileStub> FileType = new ILightStubFileElementType<>("SlintFile", SlintLanguage.INSTANCE) {
|
||||
@Override
|
||||
public @NonNls @NotNull String getExternalId() {
|
||||
return "slint.FILE";
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public @NotNull TokenSet getCommentTokens() {
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class SlintTokenType extends IElementType {
|
||||
|
||||
public SlintTokenType(@NonNls @NotNull String kind) {
|
||||
super(kind, Slint.INSTANCE);
|
||||
super(kind, SlintLanguage.INSTANCE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.intellij.extapi.psi.PsiFileBase;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.psi.FileViewProvider;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import me.zhouxi.slint.lang.Slint;
|
||||
import me.zhouxi.slint.lang.SlintLanguage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -13,7 +13,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class SlintFile extends PsiFileBase implements PsiFile {
|
||||
|
||||
public SlintFile(@NotNull FileViewProvider viewProvider) {
|
||||
super(viewProvider, Slint.INSTANCE);
|
||||
super(viewProvider, SlintLanguage.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,7 +3,7 @@ package me.zhouxi.slint.lang.psi;
|
||||
import com.intellij.openapi.fileTypes.LanguageFileType;
|
||||
import com.intellij.openapi.util.NlsContexts;
|
||||
import com.intellij.openapi.util.NlsSafe;
|
||||
import me.zhouxi.slint.lang.Slint;
|
||||
import me.zhouxi.slint.lang.SlintLanguage;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -17,7 +17,7 @@ public class SlintFileType extends LanguageFileType {
|
||||
public static final SlintFileType INSTANCE = new SlintFileType();
|
||||
|
||||
protected SlintFileType() {
|
||||
super(Slint.INSTANCE);
|
||||
super(SlintLanguage.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,6 +37,6 @@ public class SlintFileType extends LanguageFileType {
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return Slint.ICON;
|
||||
return SlintLanguage.ICON;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package me.zhouxi.slint.lang.psi;
|
||||
package me.zhouxi.slint.lang.psi.impl;
|
||||
|
||||
import com.intellij.extapi.psi.ASTWrapperPsiElement;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import me.zhouxi.slint.lang.psi.SlintPsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SlintPsiElementImpl extends ASTWrapperPsiElement implements SlintPsiElement {
|
||||
public abstract class SlintPsiElementImpl extends ASTWrapperPsiElement implements SlintPsiElement {
|
||||
|
||||
public SlintPsiElementImpl(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
@@ -3,7 +3,6 @@ package me.zhouxi.slint.lang.psi.impl;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
|
||||
import me.zhouxi.slint.lang.psi.SlintPsiElementImpl;
|
||||
import me.zhouxi.slint.lang.psi.SlintPsiReferencedIdentifier;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package me.zhouxi.slint.lang.psi.impl
|
||||
|
||||
import com.intellij.extapi.psi.StubBasedPsiElementBase
|
||||
import com.intellij.lang.ASTNode
|
||||
import com.intellij.openapi.util.NlsSafe
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.stubs.IStubElementType
|
||||
import com.intellij.psi.stubs.StubElement
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import com.intellij.util.IncorrectOperationException
|
||||
import me.zhouxi.slint.lang.createIdentifier
|
||||
import me.zhouxi.slint.lang.psi.SlintNamed
|
||||
import me.zhouxi.slint.lang.psi.SlintPsiElement
|
||||
import me.zhouxi.slint.lang.psi.SlintPsiNamedElement
|
||||
import me.zhouxi.slint.stubs.SlintPsiStub
|
||||
|
||||
/**
|
||||
* @author zhouxi 2024/5/23
|
||||
*/
|
||||
abstract class SlintStubBasedPsiNamedElementImpl<T : StubElement<out PsiElement>> :
|
||||
StubBasedPsiElementBase<T>, SlintPsiElement, SlintPsiNamedElement {
|
||||
|
||||
constructor(node: ASTNode) : super(node)
|
||||
|
||||
constructor(stub: T, nodeType: IStubElementType<*, *>) : super(stub, nodeType)
|
||||
|
||||
override fun getNameIdentifier(): PsiElement? {
|
||||
return findChildByClass(SlintNamed::class.java)
|
||||
}
|
||||
|
||||
override fun getName(): String? {
|
||||
return nameIdentifier?.text ?: this.text
|
||||
}
|
||||
|
||||
override fun canNavigate(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun getTextOffset(): Int {
|
||||
return nameIdentifier?.textOffset ?: super.getTextOffset()
|
||||
}
|
||||
|
||||
@Throws(IncorrectOperationException::class)
|
||||
override fun setName(name: @NlsSafe String): PsiElement {
|
||||
val element = nameIdentifier ?: throw IncorrectOperationException()
|
||||
element.replace(createIdentifier(project, name))
|
||||
return this
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import com.intellij.psi.TokenType
|
||||
import com.intellij.psi.impl.source.codeStyle.SemanticEditorPosition.SyntaxElement
|
||||
import com.intellij.psi.impl.source.codeStyle.lineIndent.JavaLikeLangLineIndentProvider
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import me.zhouxi.slint.lang.Slint
|
||||
import me.zhouxi.slint.lang.SlintLanguage
|
||||
import me.zhouxi.slint.lang.psi.SlintTypes
|
||||
|
||||
class SlintLineIndentProvider : JavaLikeLangLineIndentProvider() {
|
||||
@@ -16,7 +16,7 @@ class SlintLineIndentProvider : JavaLikeLangLineIndentProvider() {
|
||||
|
||||
|
||||
override fun isSuitableForLanguage(language: Language): Boolean {
|
||||
return language.isKindOf(Slint.INSTANCE)
|
||||
return language.isKindOf(SlintLanguage.INSTANCE)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -12,7 +12,7 @@ import me.zhouxi.slint.lang.psi.SlintFile
|
||||
|
||||
fun createIdentifier(project: Project?, text: String): PsiElement {
|
||||
val factory = PsiFileFactory.getInstance(project)
|
||||
val file = factory.createFileFromText("dummy.slint", Slint.INSTANCE, "component $text{}") as SlintFile
|
||||
val file = factory.createFileFromText("dummy.slint", SlintLanguage.INSTANCE, "component $text{}") as SlintFile
|
||||
return file.findChildByClass(SlintComponent::class.java)!!.componentName!!.identifier
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package me.zhouxi.slint.preview
|
||||
|
||||
import com.intellij.execution.configurations.ConfigurationTypeBase
|
||||
import com.intellij.openapi.util.NotNullLazyValue
|
||||
import me.zhouxi.slint.lang.Slint
|
||||
import me.zhouxi.slint.lang.SlintLanguage
|
||||
|
||||
/**
|
||||
* @author zhouxi 2024/5/16
|
||||
@@ -11,7 +11,7 @@ object PreviewConfigurationType : ConfigurationTypeBase(
|
||||
"SlintViewerConfiguration",
|
||||
"Slint viewer",
|
||||
"Slint component preview",
|
||||
NotNullLazyValue.createValue { Slint.ICON }
|
||||
NotNullLazyValue.createValue { SlintLanguage.ICON }
|
||||
) {
|
||||
init {
|
||||
addFactory(PreviewConfigurationFactory(this))
|
||||
|
||||
@@ -3,7 +3,7 @@ package me.zhouxi.slint.preview
|
||||
import com.intellij.execution.lineMarker.ExecutorAction
|
||||
import com.intellij.execution.lineMarker.RunLineMarkerContributor
|
||||
import com.intellij.psi.PsiElement
|
||||
import me.zhouxi.slint.lang.Slint
|
||||
import me.zhouxi.slint.lang.SlintLanguage
|
||||
import me.zhouxi.slint.lang.psi.SlintComponentName
|
||||
|
||||
/**
|
||||
@@ -13,7 +13,7 @@ class PreviewRunLineMarkerContributor : RunLineMarkerContributor() {
|
||||
override fun getInfo(element: PsiElement): Info? {
|
||||
if (element.parent is SlintComponentName) {
|
||||
return Info(
|
||||
Slint.ICON, null,
|
||||
SlintLanguage.ICON, null,
|
||||
*ExecutorAction.getActions(1)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user