Debian Codegraph @

src/harlequin_mysql/completions.py

raw symbols SCIP
1 from __future__ import annotations
2
3 import csv
4 import re
5 from pathlib import Path
6
7 from harlequin import HarlequinCompletion
8
9 WORD = re.compile(r"\w+")
10
11
12 def load_completions() -> list[HarlequinCompletion]:
13 completions: list[HarlequinCompletion] = []
14
15 keywords_path = Path(__file__).parent / "keywords.csv"
16 with keywords_path.open("r") as f:
17 reader = csv.reader(f, dialect="unix")
18 for name, reserved, removed in reader:
19 if removed == "False":
20 completions.append(
21 HarlequinCompletion(
22 label=name.lower(),
23 type_label="kw",
24 value=name.lower(),
25 priority=100 if reserved else 1000,
26 context=None,
27 )
28 )
29
30 functions_path = Path(__file__).parent / "functions.tsv"
31 with functions_path.open("r") as f:
32 reader = csv.reader(f, dialect="unix", delimiter="\t")
33 for name, _, _, deprecated in reader:
34 if deprecated:
35 continue
36 for alias in name.split(", "):
37 if WORD.match(alias):
38 completions.append(
39 HarlequinCompletion(
40 label=alias.split("...")[0].split("(")[0].lower(),
41 type_label="fn",
42 value=alias.split("...")[0].split("(")[0].lower(),
43 priority=1000,
44 context=None,
45 )
46 )
47
48 return completions