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/autocomplete.ts | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/autocomplete.ts (limited to 'src/autocomplete.ts') diff --git a/src/autocomplete.ts b/src/autocomplete.ts new file mode 100644 index 0000000..6f894ad --- /dev/null +++ b/src/autocomplete.ts @@ -0,0 +1,66 @@ +import { + CompletionContext, + CompletionResult, + Completion, +} from "@codemirror/autocomplete"; + +const keywords: Completion[] = [ + // Function and variable declarations + { label: "DISCOVER HOW TO", type: "keyword", info: "Function declaration" }, + { label: "WITH", type: "keyword", info: "Function parameters" }, + { label: "EXPERTS CLAIM", type: "keyword", info: "Variable assignment" }, + { label: "TO BE", type: "keyword", info: "Assignment operator" }, + + // Control flow + { label: "WHAT IF", type: "keyword", info: "If statement" }, + { label: "LIES!", type: "keyword", info: "Else statement" }, + { label: "SHOCKING DEVELOPMENT", type: "keyword", info: "Return statement" }, + + // Blocks + { label: "RUMOR HAS IT", type: "keyword", info: "Block start" }, + { label: "END OF STORY", type: "keyword", info: "Block end" }, + + // I/O + { label: "YOU WON'T WANT TO MISS", type: "keyword", info: "Print statement" }, + { label: "LATEST NEWS ON", type: "keyword", info: "Input statement" }, + + // Boolean literals + { label: "TOTALLY RIGHT", type: "keyword", info: "True" }, + { label: "COMPLETELY WRONG", type: "keyword", info: "False" }, + + // Operators + { label: "IS ACTUALLY", type: "keyword", info: "Equality comparison" }, + { label: "BEATS", type: "keyword", info: "Greater than" }, + { label: "SMALLER THAN", type: "keyword", info: "Less than" }, + { label: "AND", type: "keyword", info: "Logical AND" }, + { label: "OR", type: "keyword", info: "Logical OR" }, + { label: "PLUS", type: "keyword", info: "Addition" }, + { label: "MINUS", type: "keyword", info: "Subtraction" }, + { label: "TIMES", type: "keyword", info: "Multiplication" }, + { label: "DIVIDED BY", type: "keyword", info: "Division" }, + { label: "MODULO", type: "keyword", info: "Modulus" }, + { label: "OF", type: "keyword", info: "Function call" }, + + // Program end + { + label: "PLEASE LIKE AND SUBSCRIBE", + type: "keyword", + info: "End of program", + }, +]; + +export function tabloidCompletion( + context: CompletionContext, +): CompletionResult | null { + const word = context.matchBefore(/[A-Z'][A-Z\-'\s]*/); + + if (!word || (word.from === word.to && !context.explicit)) { + return null; + } + + return { + from: word.from, + options: keywords, + filter: false, // Let CodeMirror handle filtering + }; +} -- cgit v1.2.3-70-g09d2