<!--
  ~ Copyright 2026 Sergey S. Chernov real.sergeych@gmail.com
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  ~
  -->

<idea-plugin>
    <!-- Open-ended compatibility: 2024.1+ (build 241 and newer) -->
    <idea-version since-build="241"/>
    <id>net.sergeych.lyng.idea</id>
    <name>Lyng</name>
    <vendor email="real.sergeych@gmail.com">Sergey Chernov</vendor>

    <description>
        <![CDATA[
        Basic Lyng language support: file type, syntax highlighting,
        editing assistance (on Enter indent), reformatting code (indents and spaces),
        and quick docs.
        ]]>
    </description>

    <depends>com.intellij.modules.platform</depends>
    <!-- Needed for editor language features (syntax highlighting, etc.) -->
    <depends>com.intellij.modules.lang</depends>
    <!-- Spellchecker support (optional). If present, load spellchecker.xml which registers our strategy. -->
    <depends optional="true" config-file="spellchecker.xml">com.intellij.spellchecker</depends>
    <!-- Grazie (Lite/Pro) grammar checker support (optional). If present, load grazie-lite.xml -->
    <depends optional="true" config-file="grazie-lite.xml">tanvd.grazi</depends>
    <!-- Some IDE builds may expose Grazie/Natural Languages under another ID; load grazie-bundled.xml -->
    <depends optional="true" config-file="grazie-bundled.xml">com.intellij.grazie</depends>

    <extensions defaultExtensionNs="com.intellij">
        <!-- Language and file type -->
        <fileType implementationClass="net.sergeych.lyng.idea.LyngFileType" name="Lyng" extensions="lyng" fieldName="INSTANCE" language="Lyng"/>
        <fileTypeFactory implementation="net.sergeych.lyng.idea.LyngFileTypeFactory"/>

        <!-- Minimal parser/PSI to fully wire editor services for the language -->
        <lang.parserDefinition language="Lyng" implementationClass="net.sergeych.lyng.idea.psi.LyngParserDefinition"/>

        <!-- Syntax highlighter: register under language EP -->
        <lang.syntaxHighlighterFactory language="Lyng" implementationClass="net.sergeych.lyng.idea.highlight.LyngSyntaxHighlighterFactory"/>

        <!-- Color settings page -->
        <colorSettingsPage implementation="net.sergeych.lyng.idea.highlight.LyngColorSettingsPage"/>

        <!-- External annotator for semantic highlighting -->
        <externalAnnotator language="Lyng" implementationClass="net.sergeych.lyng.idea.annotators.LyngExternalAnnotator"/>

        <!-- Quick documentation provider bound to Lyng language -->
        <lang.documentationProvider language="Lyng" implementationClass="net.sergeych.lyng.idea.docs.LyngDocumentationProvider"/>

        <!-- Basic code completion (MVP) -->
        <completion.contributor language="Lyng" implementationClass="net.sergeych.lyng.idea.completion.LyngCompletionContributor"/>

        <!-- Comment toggling support -->
        <lang.commenter language="Lyng" implementationClass="net.sergeych.lyng.idea.comment.LyngCommenter"/>

        <!-- Indentation provider to improve auto-indent and reformat behavior -->
        <lineIndentProvider implementation="net.sergeych.lyng.idea.format.LyngLineIndentProvider"/>

        <!-- Formatting model so Reformat Code (Ctrl+Alt+L) applies indentation across the file -->
        <lang.formatter language="Lyng" implementationClass="net.sergeych.lyng.idea.format.LyngFormattingModelBuilder"/>

        <!-- Ensure idempotent line indentation before formatting using our LineIndentProvider -->
        <preFormatProcessor implementation="net.sergeych.lyng.idea.format.LyngPreFormatProcessor"/>

        <!-- Settings UI -->
        <projectConfigurable instance="net.sergeych.lyng.idea.settings.LyngFormatterSettingsConfigurable"
                              displayName="Lyng Formatter"/>

        <!-- Smart Enter handler -->
        <enterHandlerDelegate implementation="net.sergeych.lyng.idea.editor.LyngEnterHandler"/>

        <!-- Trigger reindent of enclosed block when typing a standalone '}' -->
        <typedHandler implementation="net.sergeych.lyng.idea.editor.LyngTypedHandler"/>

        <!-- Smart Backspace handler (deferred) -->
        <!-- <backspaceHandlerDelegate implementation="net.sergeych.lyng.idea.editor.LyngBackspaceHandler"/> -->

        <!-- Smart Paste via action handler (ensure our handler participates first) -->
        <editorActionHandler action="EditorPaste" order="first" implementationClass="net.sergeych.lyng.idea.editor.LyngPasteHandler"/>

        <!-- If targeting SDKs with stable RawText API, the EP below can be enabled instead: -->
        <!-- <copyPastePreProcessor implementation="net.sergeych.lyng.idea.editor.LyngCopyPastePreProcessor"/> -->

        <!-- Navigation and Find Usages -->
        <psi.referenceContributor language="Lyng" implementation="net.sergeych.lyng.idea.navigation.LyngPsiReferenceContributor"/>
        <gotoDeclarationHandler implementation="net.sergeych.lyng.idea.navigation.LyngGotoDeclarationHandler"/>
        <lang.findUsagesProvider language="Lyng" implementationClass="net.sergeych.lyng.idea.navigation.LyngFindUsagesProvider"/>
        <iconProvider implementation="net.sergeych.lyng.idea.navigation.LyngIconProvider"/>

    </extensions>

    <actions>
        <action id="net.sergeych.lyng.idea.actions.RunLyngScriptAction"
                class="net.sergeych.lyng.idea.actions.RunLyngScriptAction"
                text="Run Lyng Script"
                description="Run the current Lyng script and show output in console">
            <add-to-group group-id="EditorPopupMenu" anchor="last"/>
            <add-to-group group-id="ProjectViewPopupMenu" anchor="last"/>
            <add-to-group group-id="RunMenu" anchor="last"/>
            <keyboard-shortcut keymap="$default" first-keystroke="control shift F10"/>
        </action>
    </actions>
</idea-plugin>
