Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(completion): fix completion of variants with the same name #119

Merged
merged 1 commit into from
Feb 7, 2025
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
9 changes: 7 additions & 2 deletions server/src/completion/ReferenceCompletionProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,13 @@ export class ReferenceCompletionProcessor implements ScopeProcessor {

public addItem(node: WeightedCompletionItem) {
if (node.label === "") return
const prev = this.result.get(node.label)
const lookup = this.lookupString(node)
const prev = this.result.get(lookup)
if (prev && prev.kind === node.kind) return
this.result.set(node.label, node)
this.result.set(lookup, node)
}

private lookupString(item: WeightedCompletionItem): string {
return (item.kind ?? 1).toString() + item.label
}
}
23 changes: 23 additions & 0 deletions server/src/e2e/suite/testcases/completion/fields.test
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,26 @@ fun foo(f: User?) {
9 address: Address? of User
9 age: Int? of User
9 name: String of User

========================================================================
Field with same name method
========================================================================
primitive Int;
primitive Address;
primitive String;

trait Foo {
name: String;

fun name(): String {
return self.name;
}

fun bar() {
return self.<caret>;
}
}
------------------------------------------------------------------------
9 name: String of Foo
2 bar()
2 name(): String
32 changes: 32 additions & 0 deletions server/src/e2e/suite/testcases/completion/variables.test
Original file line number Diff line number Diff line change
Expand Up @@ -486,3 +486,35 @@ fun test() {
14 try-catch
14 until
14 while

========================================================================
Variable and function with the same name
========================================================================
primitive Int;

fun first() {}

fun test() {
let first = 1;
<caret>
}
------------------------------------------------------------------------
5 first Int
13 false
13 initOf Contract(params) StateInit
13 null
13 return;
13 true
2 first()
2 test()
14 do
14 foreach
14 if
14 ife
14 let
14 lett
14 repeat
14 try
14 try-catch
14 until
14 while