diff --git a/src/main/kotlin/me/mattco/serenityos/gml/GMLBlockFoldingBuilder.kt b/src/main/kotlin/me/mattco/serenityos/gml/GMLBlockFoldingBuilder.kt index aac7b73..730fea9 100644 --- a/src/main/kotlin/me/mattco/serenityos/gml/GMLBlockFoldingBuilder.kt +++ b/src/main/kotlin/me/mattco/serenityos/gml/GMLBlockFoldingBuilder.kt @@ -10,7 +10,7 @@ import com.intellij.psi.util.PsiTreeUtil import com.intellij.refactoring.suggested.endOffset import com.intellij.refactoring.suggested.startOffset import me.mattco.serenityos.gml.psi.GMLPsiElement -import me.mattco.serenityos.gml.psi.api.GMLComponent +import me.mattco.serenityos.gml.psi.api.GMLWidget import me.mattco.serenityos.gml.psi.api.GMLVisitor class GMLBlockFoldingBuilder : CustomFoldingBuilder() { @@ -35,8 +35,8 @@ class GMLBlockFoldingBuilder : CustomFoldingBuilder() { override fun visitPsiElement(o: GMLPsiElement) { } - override fun visitComponent(o: GMLComponent) { - super.visitComponent(o) + override fun visitWidget(o: GMLWidget) { + super.visitWidget(o) val start = o.openCurly?.startOffset ?: return val end = o.closeCurly?.endOffset ?: return descriptors += FoldingDescriptor(o, TextRange(start, end)) diff --git a/src/main/kotlin/me/mattco/serenityos/gml/GMLColorSettingsPage.kt b/src/main/kotlin/me/mattco/serenityos/gml/GMLColorSettingsPage.kt index 12b29a4..1c50963 100644 --- a/src/main/kotlin/me/mattco/serenityos/gml/GMLColorSettingsPage.kt +++ b/src/main/kotlin/me/mattco/serenityos/gml/GMLColorSettingsPage.kt @@ -96,7 +96,7 @@ class GMLColorSettingsPage : DSLColorSettingsPage(GMLLanguage) { override fun getAdditionalHighlightingTagToDescriptorMap() = mapOf( "NS_NAME" to Highlights.NAMESPACE_NAME, - "CLASS_NAME" to Highlights.COMPONENT_NAME, + "CLASS_NAME" to Highlights.WIDGET_NAME, "PROPERTY" to Highlights.PROPERTY_NAME, "BOOLEAN" to Highlights.BOOLEAN ) @@ -105,7 +105,7 @@ class GMLColorSettingsPage : DSLColorSettingsPage(GMLLanguage) { "Comments" to Highlights.COMMENT, "Identifiers//Namespaces" to Highlights.NAMESPACE_NAME, - "Identifiers//Classes" to Highlights.COMPONENT_NAME, + "Identifiers//Classes" to Highlights.WIDGET_NAME, "Identifiers//Properties" to Highlights.PROPERTY_NAME, "Literals//Numbers" to Highlights.NUMBER, diff --git a/src/main/kotlin/me/mattco/serenityos/gml/GMLDocumentationProvider.kt b/src/main/kotlin/me/mattco/serenityos/gml/GMLDocumentationProvider.kt index 02e0495..ba1e186 100644 --- a/src/main/kotlin/me/mattco/serenityos/gml/GMLDocumentationProvider.kt +++ b/src/main/kotlin/me/mattco/serenityos/gml/GMLDocumentationProvider.kt @@ -8,7 +8,6 @@ import com.intellij.lang.documentation.DocumentationSettings import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.colors.TextAttributesKey import com.intellij.openapi.editor.richcopy.HtmlSyntaxInfoUtil -import com.intellij.openapi.util.text.HtmlChunk import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile import com.intellij.psi.PsiManager @@ -19,8 +18,8 @@ import com.intellij.psi.util.elementType import com.jetbrains.cidr.lang.psi.OCFile import com.jetbrains.cidr.lang.psi.OCStructLike import me.mattco.serenityos.common.ancestorOfType -import me.mattco.serenityos.gml.psi.api.GMLComponent -import me.mattco.serenityos.gml.psi.api.GMLComponentName +import me.mattco.serenityos.gml.psi.api.GMLWidget +import me.mattco.serenityos.gml.psi.api.GMLWidgetName import me.mattco.serenityos.gml.psi.api.GMLProperty import me.mattco.serenityos.gml.psi.api.GMLPropertyIdentifier @@ -51,36 +50,36 @@ class GMLDocumentationProvider : AbstractDocumentationProvider() { if (propIdent != null) return propIdent.ancestorOfType() - val compIdent = contextElement?.ancestorOfType() + val compIdent = contextElement?.ancestorOfType() if (compIdent != null) - return compIdent.ancestorOfType() + return compIdent.ancestorOfType() return null } - // Also include the '@' for component names + // Also include the '@' for widget names if (contextElement?.elementType == GMLTypes.AT) - return contextElement?.ancestorOfType() + return contextElement?.ancestorOfType() return super.getCustomDocumentationElement(editor, file, contextElement, targetOffset) } override fun generateDoc(element: PsiElement, originalElement: PsiElement?): String? { return when (element) { - is GMLComponent -> { - val component = element.gmlComponent ?: return null + is GMLWidget -> { + val widget = element.gmlWidget ?: return null buildString { append(DocumentationMarkup.DEFINITION_START) - appendStyled(component.name, Highlights.COMPONENT_NAME) - if (component.inherits != null) { + appendStyled(widget.name, Highlights.WIDGET_NAME) + if (widget.inherits != null) { append(" : ") - appendStyled(component.inherits, Highlights.COMPONENT_NAME) + appendStyled(widget.inherits, Highlights.WIDGET_NAME) } append(DocumentationMarkup.DEFINITION_END) - if (component.description != null) { + if (widget.description != null) { append(DocumentationMarkup.CONTENT_START) - append("

${component.description}

") + append("

${widget.description}

") append(DocumentationMarkup.CONTENT_END) } diff --git a/src/main/kotlin/me/mattco/serenityos/gml/GMLLineMarkerProvider.kt b/src/main/kotlin/me/mattco/serenityos/gml/GMLLineMarkerProvider.kt index 58f4306..ddfe073 100644 --- a/src/main/kotlin/me/mattco/serenityos/gml/GMLLineMarkerProvider.kt +++ b/src/main/kotlin/me/mattco/serenityos/gml/GMLLineMarkerProvider.kt @@ -7,18 +7,18 @@ import com.intellij.icons.AllIcons import com.intellij.psi.PsiElement import com.jetbrains.cidr.lang.psi.OCStructLike import me.mattco.serenityos.common.findChildrenOfType -import me.mattco.serenityos.gml.psi.api.GMLComponent +import me.mattco.serenityos.gml.psi.api.GMLWidget class GMLLineMarkerProvider : LineMarkerProvider { override fun collectSlowLineMarkers( elements: MutableList, result: MutableCollection> ) { - elements.filterIsInstance().forEach { + elements.filterIsInstance().forEach { NavigationGutterIconBuilder.create(AllIcons.Nodes.ModelClass) .setTarget((it.reference?.resolve() as? OCStructLike)?.nameIdentifier ?: return@forEach) .setTooltipText("Jump to C++ Widget") - .createLineMarkerInfo(it.componentName.findChildrenOfType(GMLTypes.IDENTIFIER).first()) + .createLineMarkerInfo(it.widgetName.findChildrenOfType(GMLTypes.IDENTIFIER).first()) .let(result::add) } } diff --git a/src/main/kotlin/me/mattco/serenityos/gml/GMLService.kt b/src/main/kotlin/me/mattco/serenityos/gml/GMLService.kt index cf5e307..08eff14 100644 --- a/src/main/kotlin/me/mattco/serenityos/gml/GMLService.kt +++ b/src/main/kotlin/me/mattco/serenityos/gml/GMLService.kt @@ -15,9 +15,9 @@ import me.mattco.serenityos.common.userlandDirectory import kotlin.collections.set interface GMLService { - val components: Map + val widgets: Map - fun lookupComponent(name: String) = components[name] + fun lookupWidget(name: String) = widgets[name] fun load() } @@ -25,7 +25,7 @@ interface GMLService { class GMLServiceImpl( private val project: Project, ) : GMLService { - override val components = mutableMapOf() + override val widgets = mutableMapOf() override fun load() { if (!project.isSerenity) @@ -43,14 +43,14 @@ class GMLServiceImpl( for (file in propertyFiles) { try { - Json.Default.decodeFromString>(file.readText()).forEach { - components[it.name] = it + Json.Default.decodeFromString>(file.readText()).forEach { + widgets[it.name] = it } } catch (_: SerializationException) { } } - postComponentLoad() + postWidgetsLoad() } } @@ -64,33 +64,33 @@ class GMLServiceImpl( return try { - val components = Json.Default.decodeFromString>(event.file!!.text) + val widgets = Json.Default.decodeFromString>(event.file!!.text) ApplicationManager.getApplication().runReadAction { - components.forEach { - service.components[it.name] = it + widgets.forEach { + service.widgets[it.name] = it } } - service.postComponentLoad() + service.postWidgetsLoad() } catch (_: SerializationException) { // If we fail to serialize the file, it is likely being edited } } } - private fun postComponentLoad() { + private fun postWidgetsLoad() { // Widget::layout is special-cased in the compiler and won't appear in the json files - val widgetComponent = components["GUI::Widget"] ?: return - if (widgetComponent.properties.none { it.name == "layout" }) { - components["GUI::Widget"] = Component( - widgetComponent.name, - widgetComponent.header, - widgetComponent.inherits, - widgetComponent.description, - widgetComponent.properties + Property( + val widget = widgets["GUI::Widget"] ?: return + if (widget.properties.none { it.name == "layout" }) { + widgets["GUI::Widget"] = Widget( + widget.name, + widget.header, + widget.inherits, + widget.description, + widget.properties + Property( "layout", - "The layout of the component", - "GUI::Component", + "The layout of the widget", + "GUI::Widget", ) ) } diff --git a/src/main/kotlin/me/mattco/serenityos/gml/GMLSyntaxHighlighterFactory.kt b/src/main/kotlin/me/mattco/serenityos/gml/GMLSyntaxHighlighterFactory.kt index 1f3e1c3..316999c 100644 --- a/src/main/kotlin/me/mattco/serenityos/gml/GMLSyntaxHighlighterFactory.kt +++ b/src/main/kotlin/me/mattco/serenityos/gml/GMLSyntaxHighlighterFactory.kt @@ -25,7 +25,7 @@ object Highlights { val COLON = OPERATOR.extend("COLON") val NAMESPACE_NAME = Default.CLASS_NAME.extend("NAMESPACE_NAME") - val COMPONENT_NAME = NAMESPACE_NAME.extend("CLASS_NAME") + val WIDGET_NAME = NAMESPACE_NAME.extend("WIDGET_NAME") val PROPERTY_NAME = Default.INSTANCE_FIELD.extend("PROPERTY_NAME") private fun TextAttributesKey.extend(name: String) = TextAttributesKey.createTextAttributesKey("GML_$name", this) diff --git a/src/main/kotlin/me/mattco/serenityos/gml/annotators/GMLErrorAnnotator.kt b/src/main/kotlin/me/mattco/serenityos/gml/annotators/GMLErrorAnnotator.kt index bc7c769..0eed1f9 100644 --- a/src/main/kotlin/me/mattco/serenityos/gml/annotators/GMLErrorAnnotator.kt +++ b/src/main/kotlin/me/mattco/serenityos/gml/annotators/GMLErrorAnnotator.kt @@ -1,7 +1,6 @@ package me.mattco.serenityos.gml.annotators import ai.grazie.utils.dropPrefix -import com.intellij.lang.annotation.AnnotationHolder import com.intellij.openapi.components.service import com.intellij.psi.PsiElement import me.mattco.serenityos.common.DSLAnnotator @@ -13,16 +12,16 @@ import me.mattco.serenityos.gml.psi.api.* class GMLErrorAnnotator : DSLAnnotator() { override fun annotate(element: PsiElement) { when (element) { - is GMLComponentName -> { + is GMLWidgetName -> { val name = element.text.dropPrefix("@") - if (element.project.service().lookupComponent(name) == null) - element.highlightError("Unknown component") + if (element.project.service().lookupWidget(name) == null) + element.highlightError("Unknown widget") } is GMLPropertyIdentifier -> { - val parentWidget = element.ancestorOfType() ?: return + val parentWidget = element.ancestorOfType() ?: return val gmlService = element.project.service() - val component = gmlService.lookupComponent(parentWidget.identWithoutAt) ?: return - if (component.getProperty(element.identifier.text, gmlService) == null) + val widget = gmlService.lookupWidget(parentWidget.identWithoutAt) ?: return + if (widget.getProperty(element.identifier.text, gmlService) == null) element.highlightError("Unknown property") } is GMLProperty -> { @@ -56,7 +55,7 @@ class GMLErrorAnnotator : DSLAnnotator() { Type.Bitmap -> if (value.string == null) return Lint(value, "Expected String") Type.Bool -> if (value.boolean == null) return Lint(value, "Expected bool") Type.Color -> if (value.string == null) return Lint(value, "Expected String") - Type.Component -> if (value.component == null) return Lint(value, "Expected Component") + Type.Widget -> if (value.widget == null) return Lint(value, "Expected Widget") Type.Double -> if (value.number == null) return Lint(value, "Expected double") is Type.EnumType -> if (value.string == null) return Lint(value, "Expected String") is Type.ErrorType -> return Lint(value, type.message) diff --git a/src/main/kotlin/me/mattco/serenityos/gml/annotators/GMLSyntaxAnnotator.kt b/src/main/kotlin/me/mattco/serenityos/gml/annotators/GMLSyntaxAnnotator.kt index f45c249..96d185c 100644 --- a/src/main/kotlin/me/mattco/serenityos/gml/annotators/GMLSyntaxAnnotator.kt +++ b/src/main/kotlin/me/mattco/serenityos/gml/annotators/GMLSyntaxAnnotator.kt @@ -6,7 +6,7 @@ import me.mattco.serenityos.common.DSLAnnotator import me.mattco.serenityos.common.findChildrenOfType import me.mattco.serenityos.gml.GMLTypes import me.mattco.serenityos.gml.Highlights -import me.mattco.serenityos.gml.psi.api.GMLComponent +import me.mattco.serenityos.gml.psi.api.GMLWidget import me.mattco.serenityos.gml.psi.api.GMLProperty import me.mattco.serenityos.gml.psi.api.GMLValue @@ -20,11 +20,11 @@ class GMLSyntaxAnnotator : DSLAnnotator(), DumbAware { element.highlightError("Unexpected EOL in string literal") } } - is GMLComponent -> { - val parts = element.componentName.findChildrenOfType(GMLTypes.IDENTIFIER) + is GMLWidget -> { + val parts = element.widgetName.findChildrenOfType(GMLTypes.IDENTIFIER) parts.dropLast(1).forEach { it.highlight(Highlights.NAMESPACE_NAME) } if (parts.isNotEmpty()) - parts.last().highlight(Highlights.COMPONENT_NAME) + parts.last().highlight(Highlights.WIDGET_NAME) } is GMLProperty -> element.propertyIdentifier.identifier.highlight(Highlights.PROPERTY_NAME) } diff --git a/src/main/kotlin/me/mattco/serenityos/gml/completions/GMLCompletionContributor.kt b/src/main/kotlin/me/mattco/serenityos/gml/completions/GMLCompletionContributor.kt index b754d28..32bece7 100644 --- a/src/main/kotlin/me/mattco/serenityos/gml/completions/GMLCompletionContributor.kt +++ b/src/main/kotlin/me/mattco/serenityos/gml/completions/GMLCompletionContributor.kt @@ -5,7 +5,7 @@ import com.intellij.codeInsight.completion.CompletionType class GMLCompletionContributor : CompletionContributor() { init { - extend(GMLComponentCompletion) + extend(GMLWidgetCompletion) extend(GMLPropertyCompletion) } diff --git a/src/main/kotlin/me/mattco/serenityos/gml/completions/GMLPropertyCompletion.kt b/src/main/kotlin/me/mattco/serenityos/gml/completions/GMLPropertyCompletion.kt index d072778..01db310 100644 --- a/src/main/kotlin/me/mattco/serenityos/gml/completions/GMLPropertyCompletion.kt +++ b/src/main/kotlin/me/mattco/serenityos/gml/completions/GMLPropertyCompletion.kt @@ -1,12 +1,9 @@ package me.mattco.serenityos.gml.completions -import ai.grazie.utils.dropPrefix import com.intellij.codeInsight.completion.CompletionParameters import com.intellij.codeInsight.completion.CompletionResultSet import com.intellij.codeInsight.lookup.LookupElementBuilder import com.intellij.openapi.components.service -import com.intellij.patterns.ElementPattern -import com.intellij.psi.PsiElement import com.intellij.util.ProcessingContext import me.mattco.serenityos.common.PsiPattern import me.mattco.serenityos.common.ancestorOfType @@ -14,7 +11,7 @@ import me.mattco.serenityos.common.psiElement import me.mattco.serenityos.gml.GMLService import me.mattco.serenityos.gml.GMLTypes import me.mattco.serenityos.gml.Type -import me.mattco.serenityos.gml.psi.api.GMLComponent +import me.mattco.serenityos.gml.psi.api.GMLWidget import me.mattco.serenityos.gml.psi.api.GMLPropertyIdentifier object GMLPropertyCompletion : GMLCompletion() { @@ -27,10 +24,10 @@ object GMLPropertyCompletion : GMLCompletion() { result: CompletionResultSet, ) { val gmlService = parameters.editor.project!!.service() - val parentComponentName = - parameters.position.ancestorOfType()?.identWithoutAt ?: return - val parentComponent = gmlService.lookupComponent(parentComponentName) ?: return - val elements = parentComponent.getAllProperties(gmlService).map { property -> + val parentWidgetName = + parameters.position.ancestorOfType()?.identWithoutAt ?: return + val parentWidget = gmlService.lookupWidget(parentWidgetName) ?: return + val elements = parentWidget.getAllProperties(gmlService).map { property -> LookupElementBuilder.create(property.name) .withTypeText(property.type.presentation()) .withInsertHandler { context, _ -> diff --git a/src/main/kotlin/me/mattco/serenityos/gml/completions/GMLComponentCompletion.kt b/src/main/kotlin/me/mattco/serenityos/gml/completions/GMLWidgetCompletion.kt similarity index 81% rename from src/main/kotlin/me/mattco/serenityos/gml/completions/GMLComponentCompletion.kt rename to src/main/kotlin/me/mattco/serenityos/gml/completions/GMLWidgetCompletion.kt index 0fef9de..e0162be 100644 --- a/src/main/kotlin/me/mattco/serenityos/gml/completions/GMLComponentCompletion.kt +++ b/src/main/kotlin/me/mattco/serenityos/gml/completions/GMLWidgetCompletion.kt @@ -5,18 +5,16 @@ import com.intellij.codeInsight.completion.CompletionResultSet import com.intellij.codeInsight.lookup.LookupElementBuilder import com.intellij.openapi.components.service import com.intellij.openapi.progress.ProgressManager -import com.intellij.patterns.ElementPattern -import com.intellij.psi.PsiElement import com.intellij.util.ProcessingContext import me.mattco.serenityos.common.PsiPattern import me.mattco.serenityos.common.psiElement import me.mattco.serenityos.gml.GMLService import me.mattco.serenityos.gml.GMLTypes -import me.mattco.serenityos.gml.psi.api.GMLComponentName +import me.mattco.serenityos.gml.psi.api.GMLWidgetName -object GMLComponentCompletion : GMLCompletion() { +object GMLWidgetCompletion : GMLCompletion() { override val pattern: PsiPattern - get() = psiElement(GMLTypes.IDENTIFIER).withParent(psiElement()) + get() = psiElement(GMLTypes.IDENTIFIER).withParent(psiElement()) override fun addCompletions( parameters: CompletionParameters, @@ -25,7 +23,7 @@ object GMLComponentCompletion : GMLCompletion() { ) { ProgressManager.checkCanceled() try { - val elements = parameters.editor.project!!.service().components.values.map { + val elements = parameters.editor.project!!.service().widgets.values.map { LookupElementBuilder.create("@${it.name}") } result.addAllElements(elements) diff --git a/src/main/kotlin/me/mattco/serenityos/gml/formatting/GMLFormattingBlock.kt b/src/main/kotlin/me/mattco/serenityos/gml/formatting/GMLFormattingBlock.kt index 101280c..3379fe2 100644 --- a/src/main/kotlin/me/mattco/serenityos/gml/formatting/GMLFormattingBlock.kt +++ b/src/main/kotlin/me/mattco/serenityos/gml/formatting/GMLFormattingBlock.kt @@ -41,7 +41,7 @@ class GMLFormattingBlock( override fun buildChildren() = children override fun getChildAttributes(newChildIndex: Int): ChildAttributes { - if (node.elementType == GMLTypes.COMPONENT_BODY || node.elementType == GMLTypes.ARRAY) + if (node.elementType == GMLTypes.WIDGET_BODY || node.elementType == GMLTypes.ARRAY) return ChildAttributes(Indent.getNormalIndent(), null) return ChildAttributes(Indent.getNoneIndent(), null) } diff --git a/src/main/kotlin/me/mattco/serenityos/gml/formatting/rules.kt b/src/main/kotlin/me/mattco/serenityos/gml/formatting/rules.kt index 1abf5ab..018f772 100644 --- a/src/main/kotlin/me/mattco/serenityos/gml/formatting/rules.kt +++ b/src/main/kotlin/me/mattco/serenityos/gml/formatting/rules.kt @@ -11,8 +11,8 @@ fun buildGMLSpacingRules(settings: CommonCodeStyleSettings) = SpacingBuilder(set simple { between(OPEN_CURLY, CLOSE_CURLY).spacing(0, 0, 0, false, 0) between(PROPERTY, CLOSE_CURLY).spacing(0, 0, 0, false, 0) - between(OPEN_CURLY, COMPONENT_BODY).spacing(0, 0, 1, false, 0) - between(COMPONENT_BODY, CLOSE_CURLY).spacing(0, 0, 1, false, 0) + between(OPEN_CURLY, WIDGET_BODY).spacing(0, 0, 1, false, 0) + between(WIDGET_BODY, CLOSE_CURLY).spacing(0, 0, 1, false, 0) after(AT).spaces(0) before(OPEN_CURLY).spaces(1) @@ -27,13 +27,13 @@ fun buildGMLSpacingRules(settings: CommonCodeStyleSettings) = SpacingBuilder(set for (type in listOf(OPEN_BRACKET, CLOSE_BRACKET, BOOLEAN, STRING, NUMBER, NAMESPACE)) around(type).spaces(0) - between(COLON, COMPONENT).spacing(1, 1, 0, false, 0) + between(COLON, WIDGET).spacing(1, 1, 0, false, 0) between(PROPERTY, PROPERTY).spacing(0, 0, 1, false, 0) - between(PROPERTY, COMPONENT).spacing(0, 0, 2, false, 0) - between(COMPONENT, PROPERTY).spacing(0, 0, 2, false, 0) + between(PROPERTY, WIDGET).spacing(0, 0, 2, false, 0) + between(WIDGET, PROPERTY).spacing(0, 0, 2, false, 0) } - contextual(parent = COMPONENT_BODY, right = COMPONENT) { _, left, _ -> + contextual(parent = WIDGET_BODY, right = WIDGET) { _, left, _ -> val leftType = left?.elementType ?: return@contextual null if (leftType == COLON) return@contextual null @@ -43,7 +43,7 @@ fun buildGMLSpacingRules(settings: CommonCodeStyleSettings) = SpacingBuilder(set } fun findIndentForGMLNode(node: ASTNode): Indent? { - if (node.elementType == COMPONENT_BODY) + if (node.elementType == WIDGET_BODY) return Indent.getNormalIndent() return Indent.getNoneIndent() diff --git a/src/main/kotlin/me/mattco/serenityos/gml/psi/GMLPsiFactory.kt b/src/main/kotlin/me/mattco/serenityos/gml/psi/GMLPsiFactory.kt index 6d8cfef..aca4121 100644 --- a/src/main/kotlin/me/mattco/serenityos/gml/psi/GMLPsiFactory.kt +++ b/src/main/kotlin/me/mattco/serenityos/gml/psi/GMLPsiFactory.kt @@ -8,7 +8,7 @@ import me.mattco.serenityos.common.findChildOfType import me.mattco.serenityos.gml.GMLFile import me.mattco.serenityos.gml.GMLFileType import me.mattco.serenityos.gml.GMLTypes -import me.mattco.serenityos.gml.psi.api.GMLComponent +import me.mattco.serenityos.gml.psi.api.GMLWidget class GMLPsiFactory(private val project: Project) { private fun createFile(text: String, fileName: String = "dummy.gml") = PsiFileFactory @@ -19,8 +19,8 @@ class GMLPsiFactory(private val project: Project) { text ) as GMLFile - fun createIdentifier(name: String) = createFromText("@$name {}") - ?.componentName + fun createIdentifier(name: String) = createFromText("@$name {}") + ?.widgetName ?.findChildOfType(GMLTypes.IDENTIFIER) ?: error("Failed to create endpoint") diff --git a/src/main/kotlin/me/mattco/serenityos/gml/psi/interfaces/IGMLWidget.kt b/src/main/kotlin/me/mattco/serenityos/gml/psi/interfaces/IGMLWidget.kt index 1bea88a..8d76bfe 100644 --- a/src/main/kotlin/me/mattco/serenityos/gml/psi/interfaces/IGMLWidget.kt +++ b/src/main/kotlin/me/mattco/serenityos/gml/psi/interfaces/IGMLWidget.kt @@ -1,10 +1,10 @@ package me.mattco.serenityos.gml.psi.interfaces import com.intellij.psi.PsiElement -import me.mattco.serenityos.gml.Component +import me.mattco.serenityos.gml.Widget -interface IGMLComponent : PsiElement { - val gmlComponent: Component? +interface IGMLWidget : PsiElement { + val gmlWidget: Widget? val identWithoutAt: String } diff --git a/src/main/kotlin/me/mattco/serenityos/gml/psi/mixins/GMLPropertyMixin.kt b/src/main/kotlin/me/mattco/serenityos/gml/psi/mixins/GMLPropertyMixin.kt index 41a43db..f65445c 100644 --- a/src/main/kotlin/me/mattco/serenityos/gml/psi/mixins/GMLPropertyMixin.kt +++ b/src/main/kotlin/me/mattco/serenityos/gml/psi/mixins/GMLPropertyMixin.kt @@ -5,12 +5,12 @@ import com.intellij.openapi.components.service import me.mattco.serenityos.common.ancestorOfType import me.mattco.serenityos.gml.Property import me.mattco.serenityos.gml.psi.GMLNamedElement -import me.mattco.serenityos.gml.psi.api.GMLComponent +import me.mattco.serenityos.gml.psi.api.GMLWidget import me.mattco.serenityos.gml.psi.api.GMLProperty abstract class GMLPropertyMixin(node: ASTNode) : GMLNamedElement(node), GMLProperty { override val gmlProperty: Property? - get() = ancestorOfType() - ?.gmlComponent + get() = ancestorOfType() + ?.gmlWidget ?.getProperty(propertyIdentifier.identifier.text, project.service()) } diff --git a/src/main/kotlin/me/mattco/serenityos/gml/psi/mixins/GMLWidgetMixin.kt b/src/main/kotlin/me/mattco/serenityos/gml/psi/mixins/GMLWidgetMixin.kt index 4f3206b..256755c 100644 --- a/src/main/kotlin/me/mattco/serenityos/gml/psi/mixins/GMLWidgetMixin.kt +++ b/src/main/kotlin/me/mattco/serenityos/gml/psi/mixins/GMLWidgetMixin.kt @@ -10,25 +10,25 @@ import com.intellij.psi.util.PsiTreeUtil import com.jetbrains.cidr.lang.psi.OCElement import com.jetbrains.cidr.lang.psi.OCStructLike import me.mattco.serenityos.common.findChildrenOfType -import me.mattco.serenityos.gml.Component +import me.mattco.serenityos.gml.Widget import me.mattco.serenityos.gml.GMLService import me.mattco.serenityos.gml.GMLTypes import me.mattco.serenityos.gml.psi.GMLNamedElement -import me.mattco.serenityos.gml.psi.api.GMLComponent +import me.mattco.serenityos.gml.psi.api.GMLWidget import me.mattco.serenityos.gml.psi.singleRef -abstract class GMLComponentMixin(node: ASTNode) : GMLNamedElement(node), GMLComponent { - override val gmlComponent: Component? - get() = project.service().lookupComponent(identWithoutAt) +abstract class GMLWidgetMixin(node: ASTNode) : GMLNamedElement(node), GMLWidget { + override val gmlWidget: Widget? + get() = project.service().lookupWidget(identWithoutAt) - override val identWithoutAt by lazy { componentName.text.dropPrefix("@") } + override val identWithoutAt by lazy { widgetName.text.dropPrefix("@") } override fun getReference() = singleRef { resolveCppDecl() } - override fun getNameIdentifier() = componentName + override fun getNameIdentifier() = widgetName private fun resolveCppDecl(): OCElement? { - val nameParts = componentName.findChildrenOfType(GMLTypes.IDENTIFIER).mapTo(mutableListOf()) { it.text } + val nameParts = widgetName.findChildrenOfType(GMLTypes.IDENTIFIER).mapTo(mutableListOf()) { it.text } if (nameParts.isEmpty()) return null diff --git a/src/main/kotlin/me/mattco/serenityos/gml/typing.kt b/src/main/kotlin/me/mattco/serenityos/gml/typing.kt index d95ad2c..4afcfab 100644 --- a/src/main/kotlin/me/mattco/serenityos/gml/typing.kt +++ b/src/main/kotlin/me/mattco/serenityos/gml/typing.kt @@ -4,15 +4,15 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -data class Component( +data class Widget( val name: String, val header: String, val inherits: String? = null, val description: String? = null, val properties: List = emptyList(), ) { - fun getSuper(service: GMLService): Component? { - return inherits?.let(service::lookupComponent) + fun getSuper(service: GMLService): Widget? { + return inherits?.let(service::lookupWidget) } fun getProperty(name: String, service: GMLService): Property? { @@ -47,10 +47,6 @@ sealed interface Type { override fun presentation() = "bool" } - data object Component : Type { - override fun presentation() = "Component" - } - data class Int(val signed: Boolean) : Type { override fun presentation() = if (signed) "i64" else "u64" } @@ -100,6 +96,10 @@ sealed interface Type { override fun presentation() = types.joinToString(" | ") { it.presentation() } } + data object Widget : Type { + override fun presentation() = "Widget" + } + class EnumType(val name: kotlin.String) : Type { override fun presentation() = name } @@ -119,7 +119,7 @@ sealed interface Type { type == "bool" -> Bool type == "Gfx::Bitmap" -> Bitmap type == "Gfx::Color" -> Color - type == "GUI::Component" -> Component + type == "GUI::Widget" -> Widget type == "GUI::UIDimension" -> UIDimension type == "GUI::Margins" -> Margins type.startsWith("Array") -> { diff --git a/src/main/resources/grammar/SerenityOS GML.bnf b/src/main/resources/grammar/SerenityOS GML.bnf index 6968606..7ff5354 100644 --- a/src/main/resources/grammar/SerenityOS GML.bnf +++ b/src/main/resources/grammar/SerenityOS GML.bnf @@ -20,23 +20,23 @@ generateTokenAccessors=true } -File ::= Component +File ::= Widget -Component ::= ComponentName OPEN_CURLY ComponentBody? CLOSE_CURLY { - implements="me.mattco.serenityos.gml.psi.interfaces.IGMLComponent" - mixin="me.mattco.serenityos.gml.psi.mixins.GMLComponentMixin" +Widget ::= WidgetName OPEN_CURLY WidgetBody? CLOSE_CURLY { + implements="me.mattco.serenityos.gml.psi.interfaces.IGMLWidget" + mixin="me.mattco.serenityos.gml.psi.mixins.GMLWidgetMixin" pin=1 - recoverWhile=Component_recover + recoverWhile=Widget_recover } -private Component_recover ::= !(AT | CLOSE_CURLY | IDENTIFIER) +private Widget_recover ::= !(AT | CLOSE_CURLY | IDENTIFIER) -ComponentName ::= AT NAMESPACE? IDENTIFIER (NAMESPACE IDENTIFIER)* { - name="component name" +WidgetName ::= AT NAMESPACE? IDENTIFIER (NAMESPACE IDENTIFIER)* { + name="widget name" pin=1 } -ComponentBody ::= (Property | Component)+ +WidgetBody ::= (Property | Widget)+ Property ::= PropertyIdentifier COLON Value { implements="me.mattco.serenityos.gml.psi.interfaces.IGMLProperty" mixin="me.mattco.serenityos.gml.psi.mixins.GMLPropertyMixin" @@ -52,7 +52,7 @@ Value ::= | NUMBER | STRING | Array - | Component + | Widget // IDENTIFIER is not valid here, however when completion attempts to run inside // of an array, the identifier token it inserts completely breaks the grammar. The // only way to prevent that completion is to make IDENTIFIER a valid Value and