aboutsummaryrefslogtreecommitdiff
path: root/src/autocomplete.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <me@liz.coffee>2026-01-04 23:37:57 -0800
committerElizabeth Hunt <me@liz.coffee>2026-01-04 23:39:56 -0800
commitf2aec5ca1434ff4dc43c51b47faa8347e1ebf3e2 (patch)
tree087b028bf56f008823d5f135888ac0252fa8fc66 /src/autocomplete.ts
parent1f5d5ae9de3c87be7faf60b0a0f028e7b7c3507e (diff)
downloadcodemirror-lang-tabloid-f2aec5ca1434ff4dc43c51b47faa8347e1ebf3e2.tar.gz
codemirror-lang-tabloid-f2aec5ca1434ff4dc43c51b47faa8347e1ebf3e2.zip
Better impl
Diffstat (limited to 'src/autocomplete.ts')
-rw-r--r--src/autocomplete.ts66
1 files changed, 66 insertions, 0 deletions
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
+ };
+}