From f2aec5ca1434ff4dc43c51b47faa8347e1ebf3e2 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 4 Jan 2026 23:37:57 -0800 Subject: Better impl --- src/index.ts | 76 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 36 deletions(-) (limited to 'src/index.ts') diff --git a/src/index.ts b/src/index.ts index 14b4ffe..690572b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,51 +1,55 @@ -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 { highlighting } from "./highlight"; +import { tabloidCompletion } from "./autocomplete"; +import { autocompletion } from "@codemirror/autocomplete"; + +// Wrap parser to debug +const originalParse = parser.parse.bind(parser); +parser.parse = function (input, fragments, ranges) { + console.log( + "[PARSER] parse called with input:", + typeof input === "string" ? input.substring(0, 100) : input, + ); + const result = originalParse(input, fragments, ranges); + console.log("[PARSER] parse result:", result.toString()); + return result; +}; export const tabloidLanguage = LRLanguage.define({ parser: parser.configure({ props: [ indentNodeProp.add({ - Block: delimitedIndent({closing: "endOfStory", align: false}), - ParenBlock: delimitedIndent({closing: ")", align: false}), - FunctionDecl: context => context.baseIndent + context.unit, - IfStatement: context => context.baseIndent + context.unit, + Block: delimitedIndent({ closing: "endOfStory", align: false }), + ParenBlock: delimitedIndent({ closing: ")", align: false }), + FunctionDecl: (context) => context.baseIndent + context.unit, + IfStatement: (context) => context.baseIndent + context.unit, }), foldNodeProp.add({ Block: foldInside, ParenBlock: foldInside, }), - styleTags({ - Identifier: t.variableName, - NumberLiteral: t.number, - StringLiteral: t.string, - BooleanLiteral: t.bool, - FunctionCall: t.function(t.variableName), - discoverHowTo: t.definitionKeyword, - expertsClaim: t.definitionKeyword, - toBe: t.operatorKeyword, - rumorHasIt: t.keyword, - endOfStory: t.keyword, - whatIf: t.controlKeyword, - liesBang: t.controlKeyword, - shockingDevelopment: t.controlKeyword, - youWontWantToMiss: t.keyword, - latestNewsOn: t.keyword, - pleaseLikeAndSubscribe: t.keyword, - "with of": t.keyword, - "isActually beats smallerThan": t.compareOperator, - "and or": t.logicOperator, - "plus minus times dividedBy modulo": t.arithmeticOperator, - "( )": t.paren, - ",": t.separator - }) - ] + highlighting, + ], }), languageData: { - commentTokens: {} - } -}) + commentTokens: {}, + closeBrackets: { brackets: ["(", '"', "'"] }, + autocomplete: tabloidCompletion, + }, +}); export function tabloid() { - return new LanguageSupport(tabloidLanguage) + return new LanguageSupport(tabloidLanguage, [ + autocompletion({ override: [tabloidCompletion] }), + ]); } + +export { tabloidCompletion }; -- cgit v1.2.3-70-g09d2