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
1 change: 1 addition & 0 deletions server/src/completion/WeightedCompletionItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export enum CompletionWeight {
CONSTANT = 100,
GLOBAL_VARIABLE = 105,
STRUCT = 110,
ENUM = 115,
TYPE_ALIAS = 120,
LOWEST = 500,
}
Expand Down
7 changes: 6 additions & 1 deletion server/src/e2e/tolk/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ suite("Completion Test Suite", () => {
const testSuite = new (class extends BaseTestSuite {
public async getCompletions(
input: string,
matchStrategy: string,
triggerCharacter?: string,
): Promise<CompletionItem[]> {
const textWithoutCaret = input.replace("<caret>", "")
Expand All @@ -34,6 +35,9 @@ suite("Completion Test Suite", () => {

const finalItems = items.items.filter(item => {
const label = typeof item.label === "object" ? item.label.label : item.label
if (matchStrategy === "includes") {
return label.includes(textBeforeCursor.trim())
}
return label.startsWith(textBeforeCursor.trim())
})

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

const completions = await this.getCompletions(testCase.input, ".")
const matchStrategy = testCase.properties.get("strategy") ?? "startsWith"
const completions = await this.getCompletions(testCase.input, matchStrategy, ".")

const items = completions
.filter(item => Number(item.kind) !== 0)
Expand Down
41 changes: 41 additions & 0 deletions server/src/e2e/tolk/testcases/completion-select/enums.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
========================================================================
Enum member completion as expression
========================================================================
enum Color {
Red = 10,
Blue,
}

fun main() {
Red<caret>
}
------------------------------------------------------------------------
enum Color {
Red = 10,
Blue,
}

fun main() {
Color.Red<caret>
}

========================================================================
Enum member completion after enum name
========================================================================
enum Color {
Red = 10,
Blue,
}

fun main() {
Color.<caret>
}
------------------------------------------------------------------------
enum Color {
Red = 10,
Blue,
}

fun main() {
Color.Blue<caret>
}
104 changes: 104 additions & 0 deletions server/src/e2e/tolk/testcases/completion-select/match.test
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,107 @@ fun foo(value: int) {
Fill<caret> => {}
}
}

========================================================================
Match over enum completion
========================================================================
enum Color {
Red = 10,
Blue,
}

fun foo(color: Color) {
match (color) {
Red<caret>
}
}
------------------------------------------------------------------------
enum Color {
Red = 10,
Blue,
}

fun foo(color: Color) {
match (color) {
Color.Red<caret> => {}
}
}

========================================================================
Match over enum completion with single filled arm
========================================================================
enum Color {
Red = 10,
Blue,
}

fun foo(color: Color) {
match (color) {
Color.Red => {}
Blue<caret>
}
}
------------------------------------------------------------------------
enum Color {
Red = 10,
Blue,
}

fun foo(color: Color) {
match (color) {
Color.Red => {}
Color.Blue<caret> => {}
}
}

========================================================================
Match over enum completion with enum name
========================================================================
enum Color {
Red = 10,
Blue,
}

fun foo(color: Color) {
match (color) {
Color.<caret>
}
}
------------------------------------------------------------------------
enum Color {
Red = 10,
Blue,
}

fun foo(color: Color) {
match (color) {
Color.Blue<caret>
}
}

========================================================================
Match over enum else completion
========================================================================
enum Color {
Red = 10,
Blue,
}

fun foo(color: Color) {
match (color) {
Color.Red => {}
els<caret>
}
}
------------------------------------------------------------------------
enum Color {
Red = 10,
Blue,
}

fun foo(color: Color) {
match (color) {
Color.Red => {}
else => {<caret>},
}
}
102 changes: 102 additions & 0 deletions server/src/e2e/tolk/testcases/completion/enums.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
========================================================================
Enum completion as type
========================================================================
enum Color {
Red = 10,
Blue,
}

fun main() {
val foo: Colo<caret>
}
------------------------------------------------------------------------
12 Color

========================================================================
Enum completion as expression
========================================================================
enum Color {
Red = 10,
Blue,
}

fun main() {
Colo<caret>
}
------------------------------------------------------------------------
19 Color.Blue of Color
19 Color.Red = 10 of Color
12 Color

========================================================================
@strategy includes
Enum member completion as expression
========================================================================
enum Color {
Red = 10,
Blue,
}

fun main() {
Red<caret>
}
------------------------------------------------------------------------
19 Color.Red = 10 of Color

========================================================================
Enum member completion after enum name
========================================================================
enum Color {
Red = 10,
Blue,
}

fun main() {
Color.<caret>
}
------------------------------------------------------------------------
19 Blue of Color
19 Red = 10 of Color
1 forceLoadLazyObject(self): slice
1 fromCell(packedCell: cell, options: UnpackOptions = {}): T of T
1 fromSlice(rawSlice: slice, options: UnpackOptions = {}): T of T
1 getDeclaredPackPrefix(): int of T
1 getDeclaredPackPrefixLen(): int of T
1 stackMoveToTop(mutate self): void
1 toCell(self, options: PackOptions = {}): Cell<T>

========================================================================
Enum static method completion
========================================================================
enum Color {
Red = 10,
Blue = 200 + 100,
}

fun Color.max() {
return Color.Red;
}

fun main() {
Color.max<caret>;
}
------------------------------------------------------------------------
1 max() of Color

========================================================================
Enum instance method completion
========================================================================
enum Color {
Red = 10,
Blue = 200 + 100,
}

fun Color.isRed(self) {
return self == Color.Red;
}

fun main(c: Color) {
c.isR<caret>;
}
------------------------------------------------------------------------
1 isRed(self)
105 changes: 105 additions & 0 deletions server/src/e2e/tolk/testcases/completion/match.test
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,108 @@ fun foo(value: Foo) {
}
------------------------------------------------------------------------
No completion items

========================================================================
@strategy includes
Match over enum completion
========================================================================
enum Color {
Red = 10,
Blue,
}

fun foo(color: Color) {
match (color) {
Red<caret>
}
}
------------------------------------------------------------------------
19 Color.Red = 10 of Color

========================================================================
@strategy includes
Match over enum completion with single filled arm
========================================================================
enum Color {
Red = 10,
Blue,
}

fun foo(color: Color) {
match (color) {
Color.Red => {}
Blue<caret>
}
}
------------------------------------------------------------------------
19 Color.Blue of Color

========================================================================
@strategy includes
Match over enum completion with single filled arm with same name
========================================================================
enum Color {
Red = 10,
Blue,
}

fun foo(color: Color) {
match (color) {
Color.Red => {}
Red<caret>
}
}
------------------------------------------------------------------------
No completion items

========================================================================
Match over enum completion with enum name
========================================================================
enum Color {
Red = 10,
Blue,
}

fun foo(color: Color) {
match (color) {
Color.<caret>
}
}
------------------------------------------------------------------------
19 Blue of Color
19 Red = 10 of Color

========================================================================
Match over enum completion with enum name with single filled arm
========================================================================
enum Color {
Red = 10,
Blue,
}

fun foo(color: Color) {
match (color) {
Color.Red => {}
Color.<caret>
}
}
------------------------------------------------------------------------
19 Blue of Color
19 Red = 10 of Color

========================================================================
Match over enum else completion
========================================================================
enum Color {
Red = 10,
Blue,
}

fun foo(color: Color) {
match (color) {
Color.Red => {}
els<caret>
}
}
------------------------------------------------------------------------
22 else => {}
Loading
Loading