Skip to content

valtzu/codemirror-lang-el

 
 

Repository files navigation

Symfony Expression Language support for CodeMirror 6

⚠️ This is unstable: Expect breaking changes until v1 is out.

Features

Linting

image

Autocompletion

image

Hover tooltip

image

Function argument hints

image


Installation

Symfony AssetMapper

bin/console importmap:require @valtzu/codemirror-lang-el

npm

npm install @valtzu/codemirror-lang-el

Yarn

yarn add @valtzu/codemirror-lang-el

Example

Live demo

<div id="editor"></div>
<script type="module">
    import { EditorView, basicSetup } from "codemirror";
    import { acceptCompletion } from "@codemirror/autocomplete";
    import { keymap } from "@codemirror/view";
    import { expressionlanguage } from "@valtzu/codemirror-lang-el";
    import { defaultKeymap } from "@codemirror/commands";

    let editor = new EditorView({
        extensions: [
            basicSetup,
            keymap.of([...defaultKeymap, {key: "Tab", run: acceptCompletion}]),
            expressionlanguage({
                types: {
                    "User": {
                        identifiers: [
                            { name: "self", type: ["User"], info: 'Self-reference for property-access demonstration purposes' },
                            { name: "name", type: ["string"] },
                            { name: "age", type: ["int"], info: "Years since birthday", detail: "years" },
                        ],
                        functions: [
                            { name: "isActive", returnType: ["bool"] },
                            { name: "getGroup", args: [], returnType: ["Group"], info: 'Get the user group' },
                        ],
                    },
                    "Group": {
                        identifiers: [{ name: "name", type: ["string"] }]
                    }
                },
                identifiers: [
                    { name: "user", type: ["User"], info: 'This is the user' },
                ],
                functions: [
                    { name: "is_granted", args: [{name: "attributes", type: ["string"]}, {name: "object", type: ["object"], optional: true}], info: 'Check if subject has permission to the object', returnType: ['bool'] },
                ],
            })
        ],
        parent: document.getElementById('editor'),
        doc: 'is_granted(user, user.self.getGroup())',
    });
</script>

Contributing

Contributions are accepted.

Sponsor this project

Languages

  • TypeScript 63.8%
  • JavaScript 36.2%