diff --git a/grammar/package.json b/grammar/package.json index fbd9fe65..78168e2d 100644 --- a/grammar/package.json +++ b/grammar/package.json @@ -27,6 +27,7 @@ "types": "dist/index.d.ts", "sideEffects": false, "dependencies": { + "@codemirror/autocomplete": "^6.18.0", "@codemirror/language": "^6.0.0", "@lezer/highlight": "^1.0.0", "@lezer/lr": "^1.0.0" diff --git a/grammar/src/index.ts b/grammar/src/index.ts index b3dae535..eb60d1c7 100644 --- a/grammar/src/index.ts +++ b/grammar/src/index.ts @@ -2,33 +2,43 @@ // // SPDX-License-Identifier: AGPL-3.0-or-later -import {parser} from "./syntax.grammar" -import {LRLanguage, LanguageSupport, indentNodeProp, foldNodeProp, foldInside, delimitedIndent} from "@codemirror/language" -import {styleTags, tags as t} from "@lezer/highlight" +import { parser } from "./syntax.grammar" +import { LRLanguage, LanguageSupport, indentNodeProp, foldNodeProp, foldInside, delimitedIndent } from "@codemirror/language" +import { styleTags, tags as t } from "@lezer/highlight" +import { completeFromList } from "@codemirror/autocomplete" export const SlangroomLanguage = LRLanguage.define({ - parser: parser.configure({ - props: [ - indentNodeProp.add({ - Application: delimitedIndent({closing: ")", align: false}) - }), - foldNodeProp.add({ - Application: foldInside - }), - styleTags({ - Identifier: t.variableName, - Boolean: t.bool, - String: t.string, - LineComment: t.lineComment, - "( )": t.paren - }) - ] - }), - languageData: { - commentTokens: {line: ";"} - } + parser: parser.configure({ + props: [ + indentNodeProp.add({ + Application: delimitedIndent({ closing: ")", align: false }) + }), + foldNodeProp.add({ + Application: foldInside + }), + styleTags({ + Identifier: t.variableName, + WhenStatement: t.variableName, + ThenStatement: t.bool, + Rule: t.string, + StringLitteral: t.string, + LineComment: t.lineComment + }) + ] + }), + languageData: { + commentTokens: { line: "#" } + } +}) + +export const ac = SlangroomLanguage.data.of({ + autocomplete: completeFromList([ + { label: "given", type: "keyword" }, + { label: "then", type: "keyword" }, + { label: "when", type: "keyword" } + ]) }) export function Slangroom() { - return new LanguageSupport(SlangroomLanguage) + return new LanguageSupport(SlangroomLanguage, [ac]) }