aboutsummaryrefslogtreecommitdiff
path: root/src/autocomplete.ts
blob: 6f894ad5950c687e984a92dbcadb8f688c5c68d6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
  };
}