Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion server/src/e2e/tolk/testcases/completion-select/match.test
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ fun main(msg: AllowedMessageToMinter) {
RequestWalletAddress => {},
ChangeMinterAdmin => {},
ChangeMinterContent => {},
AllowedMessageToMinter<caret>
else => {<caret>},
}
}

Expand All @@ -273,3 +273,33 @@ fun foo(value: int) {
FOO<caret> => {}
}
}

========================================================================
Match over type else completion
========================================================================
fun foo(a: int | slice) {
match (a) {
els<caret>
}
}
------------------------------------------------------------------------
fun foo(a: int | slice) {
match (a) {
else => {<caret>},
}
}

========================================================================
Match over value else completion
========================================================================
fun foo() {
match (10) {
els<caret>
}
}
------------------------------------------------------------------------
fun foo() {
match (10) {
else => {<caret>},
}
}
35 changes: 35 additions & 0 deletions server/src/e2e/tolk/testcases/completion/match.test
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fun foo(value: int | slice) {
------------------------------------------------------------------------
22 int => {}
22 slice => {}
22 else => {}

========================================================================
Match over type completion, union type 2
Expand Down Expand Up @@ -52,6 +53,7 @@ fun main(msg: AllowedMessageToMinter) {
22 ChangeMinterContent => {}
22 MintNewJettons => {}
22 RequestWalletAddress => {}
22 else => {}

========================================================================
Match over type completion, union type, match with single arm
Expand Down Expand Up @@ -80,6 +82,7 @@ fun main(msg: AllowedMessageToMinter) {
22 ChangeMinterAdmin => {}
22 ChangeMinterContent => {}
22 RequestWalletAddress => {}
22 else => {}

========================================================================
Match over type completion, union type, match with single arm, cursor before arm
Expand Down Expand Up @@ -109,6 +112,7 @@ fun main(msg: AllowedMessageToMinter) {
22 ChangeMinterContent => {}
22 MintNewJettons => {}
22 RequestWalletAddress => {}
22 else => {}

========================================================================
Match over type completion, union type, match with several arms
Expand Down Expand Up @@ -137,6 +141,7 @@ fun main(msg: AllowedMessageToMinter) {
}
------------------------------------------------------------------------
22 ChangeMinterContent => {}
22 else => {}

========================================================================
Match over type completion, union type, match with all arms
Expand Down Expand Up @@ -165,6 +170,21 @@ fun main(msg: AllowedMessageToMinter) {
}
}
------------------------------------------------------------------------
22 else => {}

========================================================================
Match over type with else completion
========================================================================
const FOO = 100

fun foo(value: int | slice) {
match (value) {
int => {},
else => {},
els<caret>
}
}
------------------------------------------------------------------------
No completion items

========================================================================
Expand All @@ -179,3 +199,18 @@ fun foo(value: int) {
}
------------------------------------------------------------------------
20 FOO: int = 100

========================================================================
Match over value with else completion
========================================================================
const FOO = 100

fun foo(value: int) {
match (value) {
FOO => {},
else => {},
els<caret>
}
}
------------------------------------------------------------------------
No completion items
6 changes: 2 additions & 4 deletions server/src/e2e/tolk/testcases/completion/struct-instance.test
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,10 @@ struct Foo {
}

fun test(value: int) {
Foo{ val<caret> value: 10 };
Foo{ a<caret>, value: 10 };
}
------------------------------------------------------------------------
5 value int
14 val
14 valt
9 age : int of Foo

========================================================================
Second field in struct init with variable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,44 @@ export class MatchArmsCompletionProvider implements CompletionProvider {
insertText: value.insertText + "$1 => {$0}",
})
}

let seenElse = false

const arms = body.namedChildren.filter(it => it?.type === "match_arm")
for (const arm of arms) {
if (arm?.childForFieldName("pattern_else")) {
seenElse = true
}
}

if (!seenElse) {
result.add({
label: "else",
labelDetails: {
detail: " => {}",
},
kind: CompletionItemKind.Event,
insertTextFormat: InsertTextFormat.Snippet,
insertText: "else => {$0},",
weight: CompletionWeight.SNIPPET + 10,
})
}
return
}

const arms = body.namedChildren.filter(it => it?.type === "match_arm")

let seenElse = false
const handledTypes: Set<string> = new Set()

for (const arm of arms) {
if (!arm) continue

if (arm.childForFieldName("pattern_else")) {
seenElse = true
continue
}

const patternType = arm.childForFieldName("pattern_type")
if (!patternType) continue

Expand All @@ -83,5 +111,18 @@ export class MatchArmsCompletionProvider implements CompletionProvider {
weight: CompletionWeight.SNIPPET,
})
}

if (!seenElse) {
result.add({
label: "else",
labelDetails: {
detail: " => {}",
},
kind: CompletionItemKind.Event,
insertTextFormat: InsertTextFormat.Snippet,
insertText: "else => {$0},",
weight: CompletionWeight.SNIPPET + 10,
})
}
}
}