Skip to content

Commit 38133ef

Browse files
first steps
1 parent e029e4d commit 38133ef

File tree

7 files changed

+817182
-566594
lines changed

7 files changed

+817182
-566594
lines changed

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"Bash(cargo check:*)",
99
"Bash(cargo fmt:*)",
1010
"Bash(cargo doc:*)",
11-
"Bash(just tree-print:*)"
11+
"Bash(just tree-print:*)",
12+
"Bash(npx tree-sitter generate)"
1213
],
1314
"deny": []
1415
}

PLAN_KEYWORD_COMPLETION.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Keyword Completion Implementation Plan
2+
3+
This plan implements partial keyword matching in the Tree-sitter grammar to enable SQL keyword autocompletion in the LSP.
4+
5+
## How It Works
6+
7+
The `completableKeyword($, "keyword", { minLength: N })` function creates a grammar rule that matches:
8+
1. The full keyword (e.g., `keyword_select`)
9+
2. Partial prefixes via regex (e.g., `sel|sele|selec` for SELECT with minLength: 3)
10+
3. Partial matches are aliased as `partial_keyword:<keyword>` for identification by the LSP
11+
12+
## Implementation Summary
13+
14+
**Total keywords implemented: 40+**
15+
16+
### Statement-Starting Keywords (21)
17+
18+
| minLength | Keywords |
19+
|-----------|----------|
20+
| 1 | EXPLAIN, GRANT, INSERT, MERGE, TRUNCATE, VACUUM, WITH |
21+
| 2 | ALTER, ANALYZE, CREATE, DELETE, DROP, SET, SHOW, UNLOAD, UPDATE |
22+
| 3 | COPY, RESET, REVOKE, SELECT |
23+
| 4 | COMMENT |
24+
25+
### Clause Keywords (8)
26+
27+
| minLength | Keywords |
28+
|-----------|----------|
29+
| 1 | FROM, WHERE, GROUP, HAVING, ORDER, LIMIT |
30+
| 2 | OFFSET |
31+
| 3 | RETURNING |
32+
33+
### CREATE/ALTER/DROP Subtype Keywords (12)
34+
35+
| minLength | Keywords |
36+
|-----------|----------|
37+
| 1 | VIEW, INDEX, FUNCTION, DATABASE, EXTENSION, POLICY |
38+
| 2 | TABLE, TYPE, TRIGGER, SCHEMA, SEQUENCE |
39+
40+
### Other Secondary Keywords
41+
42+
| minLength | Keywords |
43+
|-----------|----------|
44+
| 1 | JOIN, INTO, VALUES |
45+
46+
---
47+
48+
## All Completed Tasks ✅
49+
50+
### Phase 1: High-Priority Statement Keywords
51+
- [x] SELECT (minLength: 3)
52+
- [x] INSERT (minLength: 1)
53+
- [x] UPDATE (minLength: 2)
54+
- [x] DELETE (minLength: 2)
55+
- [x] CREATE (minLength: 2)
56+
- [x] ALTER (minLength: 2)
57+
- [x] DROP (minLength: 2)
58+
59+
### Phase 2: Medium-Priority Statement Keywords
60+
- [x] SET (minLength: 2)
61+
- [x] GRANT (minLength: 1)
62+
- [x] WITH (minLength: 1)
63+
- [x] SHOW (minLength: 2)
64+
- [x] TRUNCATE (minLength: 1)
65+
- [x] COPY (minLength: 3)
66+
- [x] COMMENT (minLength: 4)
67+
- [x] RESET (minLength: 3)
68+
- [x] REVOKE (minLength: 3)
69+
70+
### Phase 3: Lower-Priority Statement Keywords
71+
- [x] EXPLAIN (minLength: 1)
72+
- [x] ANALYZE (minLength: 2)
73+
- [x] VACUUM (minLength: 1)
74+
- [x] MERGE (minLength: 1)
75+
- [x] UNLOAD (minLength: 2)
76+
77+
### Phase 4a: Clause Keywords
78+
- [x] FROM (minLength: 1)
79+
- [x] WHERE (minLength: 1)
80+
- [x] ORDER (minLength: 1)
81+
- [x] GROUP (minLength: 1)
82+
- [x] HAVING (minLength: 1)
83+
- [x] LIMIT (minLength: 1)
84+
- [x] OFFSET (minLength: 2)
85+
- [x] RETURNING (minLength: 3)
86+
87+
### Phase 4b: CREATE/ALTER/DROP Subtypes
88+
- [x] TABLE (minLength: 2)
89+
- [x] VIEW (minLength: 1)
90+
- [x] INDEX (minLength: 1)
91+
- [x] FUNCTION (minLength: 1)
92+
- [x] TYPE (minLength: 2)
93+
- [x] DATABASE (minLength: 1)
94+
- [x] SCHEMA (minLength: 2)
95+
- [x] SEQUENCE (minLength: 2)
96+
- [x] EXTENSION (minLength: 1)
97+
- [x] TRIGGER (minLength: 2)
98+
- [x] POLICY (minLength: 1)
99+
100+
### Phase 4c: JOIN Keywords
101+
- [x] JOIN (minLength: 1)
102+
103+
### Phase 4d: Other Secondary Keywords
104+
- [x] INTO (minLength: 1)
105+
- [x] VALUES (minLength: 1)
106+
107+
---
108+
109+
## Testing Protocol
110+
111+
For each keyword change:
112+
1. Add test SQL to `test.sql` with partial keywords
113+
2. Run `just tree-print test.sql`
114+
3. Verify:
115+
- Partial keywords parse as `partial_keyword:<name>`
116+
- Full keywords still parse as `keyword_<name>`
117+
- No grammar conflicts or ambiguity errors
118+
4. Only proceed to next keyword if tests pass
119+
120+
---
121+
122+
## Status: ✅ COMPLETE
123+
124+
All phases implemented and tested.
125+
126+
Last updated: 2025-12-19

0 commit comments

Comments
 (0)