Skip to content

Commit 6b04c57

Browse files
authored
feat(tolk): support enums from Tolk 1.1 (#143)
Fixes #142
1 parent fa7f669 commit 6b04c57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+26118
-23433
lines changed

server/src/completion/WeightedCompletionItem.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export enum CompletionWeight {
1313
CONSTANT = 100,
1414
GLOBAL_VARIABLE = 105,
1515
STRUCT = 110,
16+
ENUM = 115,
1617
TYPE_ALIAS = 120,
1718
LOWEST = 500,
1819
}

server/src/e2e/tolk/completion.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ suite("Completion Test Suite", () => {
1010
const testSuite = new (class extends BaseTestSuite {
1111
public async getCompletions(
1212
input: string,
13+
matchStrategy: string,
1314
triggerCharacter?: string,
1415
): Promise<CompletionItem[]> {
1516
const textWithoutCaret = input.replace("<caret>", "")
@@ -34,6 +35,9 @@ suite("Completion Test Suite", () => {
3435

3536
const finalItems = items.items.filter(item => {
3637
const label = typeof item.label === "object" ? item.label.label : item.label
38+
if (matchStrategy === "includes") {
39+
return label.includes(textBeforeCursor.trim())
40+
}
3741
return label.startsWith(textBeforeCursor.trim())
3842
})
3943

@@ -47,7 +51,8 @@ suite("Completion Test Suite", () => {
4751
test(`Completion: ${testCase.name}`, async () => {
4852
await this.setupAdditionalFiles(testCase)
4953

50-
const completions = await this.getCompletions(testCase.input, ".")
54+
const matchStrategy = testCase.properties.get("strategy") ?? "startsWith"
55+
const completions = await this.getCompletions(testCase.input, matchStrategy, ".")
5156

5257
const items = completions
5358
.filter(item => Number(item.kind) !== 0)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
========================================================================
2+
Enum member completion as expression
3+
========================================================================
4+
enum Color {
5+
Red = 10,
6+
Blue,
7+
}
8+
9+
fun main() {
10+
Red<caret>
11+
}
12+
------------------------------------------------------------------------
13+
enum Color {
14+
Red = 10,
15+
Blue,
16+
}
17+
18+
fun main() {
19+
Color.Red<caret>
20+
}
21+
22+
========================================================================
23+
Enum member completion after enum name
24+
========================================================================
25+
enum Color {
26+
Red = 10,
27+
Blue,
28+
}
29+
30+
fun main() {
31+
Color.<caret>
32+
}
33+
------------------------------------------------------------------------
34+
enum Color {
35+
Red = 10,
36+
Blue,
37+
}
38+
39+
fun main() {
40+
Color.Blue<caret>
41+
}

server/src/e2e/tolk/testcases/completion-select/match.test

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,107 @@ fun foo(value: int) {
405405
Fill<caret> => {}
406406
}
407407
}
408+
409+
========================================================================
410+
Match over enum completion
411+
========================================================================
412+
enum Color {
413+
Red = 10,
414+
Blue,
415+
}
416+
417+
fun foo(color: Color) {
418+
match (color) {
419+
Red<caret>
420+
}
421+
}
422+
------------------------------------------------------------------------
423+
enum Color {
424+
Red = 10,
425+
Blue,
426+
}
427+
428+
fun foo(color: Color) {
429+
match (color) {
430+
Color.Red<caret> => {}
431+
}
432+
}
433+
434+
========================================================================
435+
Match over enum completion with single filled arm
436+
========================================================================
437+
enum Color {
438+
Red = 10,
439+
Blue,
440+
}
441+
442+
fun foo(color: Color) {
443+
match (color) {
444+
Color.Red => {}
445+
Blue<caret>
446+
}
447+
}
448+
------------------------------------------------------------------------
449+
enum Color {
450+
Red = 10,
451+
Blue,
452+
}
453+
454+
fun foo(color: Color) {
455+
match (color) {
456+
Color.Red => {}
457+
Color.Blue<caret> => {}
458+
}
459+
}
460+
461+
========================================================================
462+
Match over enum completion with enum name
463+
========================================================================
464+
enum Color {
465+
Red = 10,
466+
Blue,
467+
}
468+
469+
fun foo(color: Color) {
470+
match (color) {
471+
Color.<caret>
472+
}
473+
}
474+
------------------------------------------------------------------------
475+
enum Color {
476+
Red = 10,
477+
Blue,
478+
}
479+
480+
fun foo(color: Color) {
481+
match (color) {
482+
Color.Blue<caret>
483+
}
484+
}
485+
486+
========================================================================
487+
Match over enum else completion
488+
========================================================================
489+
enum Color {
490+
Red = 10,
491+
Blue,
492+
}
493+
494+
fun foo(color: Color) {
495+
match (color) {
496+
Color.Red => {}
497+
els<caret>
498+
}
499+
}
500+
------------------------------------------------------------------------
501+
enum Color {
502+
Red = 10,
503+
Blue,
504+
}
505+
506+
fun foo(color: Color) {
507+
match (color) {
508+
Color.Red => {}
509+
else => {<caret>},
510+
}
511+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
========================================================================
2+
Enum completion as type
3+
========================================================================
4+
enum Color {
5+
Red = 10,
6+
Blue,
7+
}
8+
9+
fun main() {
10+
val foo: Colo<caret>
11+
}
12+
------------------------------------------------------------------------
13+
12 Color
14+
15+
========================================================================
16+
Enum completion as expression
17+
========================================================================
18+
enum Color {
19+
Red = 10,
20+
Blue,
21+
}
22+
23+
fun main() {
24+
Colo<caret>
25+
}
26+
------------------------------------------------------------------------
27+
19 Color.Blue of Color
28+
19 Color.Red = 10 of Color
29+
12 Color
30+
31+
========================================================================
32+
@strategy includes
33+
Enum member completion as expression
34+
========================================================================
35+
enum Color {
36+
Red = 10,
37+
Blue,
38+
}
39+
40+
fun main() {
41+
Red<caret>
42+
}
43+
------------------------------------------------------------------------
44+
19 Color.Red = 10 of Color
45+
46+
========================================================================
47+
Enum member completion after enum name
48+
========================================================================
49+
enum Color {
50+
Red = 10,
51+
Blue,
52+
}
53+
54+
fun main() {
55+
Color.<caret>
56+
}
57+
------------------------------------------------------------------------
58+
19 Blue of Color
59+
19 Red = 10 of Color
60+
1 forceLoadLazyObject(self): slice
61+
1 fromCell(packedCell: cell, options: UnpackOptions = {}): T of T
62+
1 fromSlice(rawSlice: slice, options: UnpackOptions = {}): T of T
63+
1 getDeclaredPackPrefix(): int of T
64+
1 getDeclaredPackPrefixLen(): int of T
65+
1 stackMoveToTop(mutate self): void
66+
1 toCell(self, options: PackOptions = {}): Cell<T>
67+
68+
========================================================================
69+
Enum static method completion
70+
========================================================================
71+
enum Color {
72+
Red = 10,
73+
Blue = 200 + 100,
74+
}
75+
76+
fun Color.max() {
77+
return Color.Red;
78+
}
79+
80+
fun main() {
81+
Color.max<caret>;
82+
}
83+
------------------------------------------------------------------------
84+
1 max() of Color
85+
86+
========================================================================
87+
Enum instance method completion
88+
========================================================================
89+
enum Color {
90+
Red = 10,
91+
Blue = 200 + 100,
92+
}
93+
94+
fun Color.isRed(self) {
95+
return self == Color.Red;
96+
}
97+
98+
fun main(c: Color) {
99+
c.isR<caret>;
100+
}
101+
------------------------------------------------------------------------
102+
1 isRed(self)

server/src/e2e/tolk/testcases/completion/match.test

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,108 @@ fun foo(value: Foo) {
260260
}
261261
------------------------------------------------------------------------
262262
No completion items
263+
264+
========================================================================
265+
@strategy includes
266+
Match over enum completion
267+
========================================================================
268+
enum Color {
269+
Red = 10,
270+
Blue,
271+
}
272+
273+
fun foo(color: Color) {
274+
match (color) {
275+
Red<caret>
276+
}
277+
}
278+
------------------------------------------------------------------------
279+
19 Color.Red = 10 of Color
280+
281+
========================================================================
282+
@strategy includes
283+
Match over enum completion with single filled arm
284+
========================================================================
285+
enum Color {
286+
Red = 10,
287+
Blue,
288+
}
289+
290+
fun foo(color: Color) {
291+
match (color) {
292+
Color.Red => {}
293+
Blue<caret>
294+
}
295+
}
296+
------------------------------------------------------------------------
297+
19 Color.Blue of Color
298+
299+
========================================================================
300+
@strategy includes
301+
Match over enum completion with single filled arm with same name
302+
========================================================================
303+
enum Color {
304+
Red = 10,
305+
Blue,
306+
}
307+
308+
fun foo(color: Color) {
309+
match (color) {
310+
Color.Red => {}
311+
Red<caret>
312+
}
313+
}
314+
------------------------------------------------------------------------
315+
No completion items
316+
317+
========================================================================
318+
Match over enum completion with enum name
319+
========================================================================
320+
enum Color {
321+
Red = 10,
322+
Blue,
323+
}
324+
325+
fun foo(color: Color) {
326+
match (color) {
327+
Color.<caret>
328+
}
329+
}
330+
------------------------------------------------------------------------
331+
19 Blue of Color
332+
19 Red = 10 of Color
333+
334+
========================================================================
335+
Match over enum completion with enum name with single filled arm
336+
========================================================================
337+
enum Color {
338+
Red = 10,
339+
Blue,
340+
}
341+
342+
fun foo(color: Color) {
343+
match (color) {
344+
Color.Red => {}
345+
Color.<caret>
346+
}
347+
}
348+
------------------------------------------------------------------------
349+
19 Blue of Color
350+
19 Red = 10 of Color
351+
352+
========================================================================
353+
Match over enum else completion
354+
========================================================================
355+
enum Color {
356+
Red = 10,
357+
Blue,
358+
}
359+
360+
fun foo(color: Color) {
361+
match (color) {
362+
Color.Red => {}
363+
els<caret>
364+
}
365+
}
366+
------------------------------------------------------------------------
367+
22 else => {}

0 commit comments

Comments
 (0)