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

feat(inlay-hints): don't show inlay hints in some cases #230

Merged
merged 2 commits into from
Feb 14, 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
2 changes: 1 addition & 1 deletion server/src/e2e/suite/testcases/inlayHints/calls.test
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fun foo(bar: Int) {}
struct Bar { bar: Int/* as int257 */ }

fun test() {
let instance/* : Bar */ = Bar { bar: 10 };
let instance = Bar { bar: 10 };
foo(instance.bar); // no hint here
}

Expand Down
32 changes: 5 additions & 27 deletions server/src/e2e/suite/testcases/inlayHints/contract.test
Original file line number Diff line number Diff line change
Expand Up @@ -111,43 +111,21 @@ contract Foo {
Show parameter name hints in function calls
========================================================================
contract Foo {

internal fun test1(x: Int) {
return x;
}

external fun test2(x: Int) {
return x;
}

get fun test3(x: Int) {
return x;
get fun test1(value: Int) {
return value;
}

init() {
const a = self.test1(42);
const b = self.test2(42);
const c = self.test3(42);
}
}
------------------------------------------------------------------------
contract Foo {

internal fun test1(x: Int) {
return x;
}

external fun test2(x: Int) {
return x;
}

get/* (0x1091c) */ fun test3(x: Int) {
return x;
get/* (0x1c89d) */ fun test1(value: Int) {
return value;
}

init() {
const a = self.test1(/* x: */42);
const b = self.test2(/* x: */42);
const c = self.test3(/* x: */42);
const a = self.test1(/* value: */42);
}
}
23 changes: 23 additions & 0 deletions server/src/e2e/suite/testcases/inlayHints/initOf.test
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,26 @@ contract Counter {
initOf Counter(/* some: */10, /* other: */"hello");
}
}

========================================================================
initOf with single letter parameter
========================================================================
primitive Int;

contract Counter {
init(s: Int) {}

fun test() {
initOf Counter(10);
}
}
------------------------------------------------------------------------
primitive Int;

contract Counter {
init(s: Int) {}

fun test() {
initOf Counter(10);
}
}
18 changes: 18 additions & 0 deletions server/src/e2e/suite/testcases/inlayHints/parameters.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
========================================================================
Single letter parameter
========================================================================
primitive Int;

fun foo(a: int, b: Int) {}

fun test() {
foo(1, 2);
}
------------------------------------------------------------------------
primitive Int;

fun foo(a: int, b: Int) {}

fun test() {
foo(1, 2);
}
19 changes: 19 additions & 0 deletions server/src/e2e/suite/testcases/inlayHints/variables.test
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,22 @@ fun foo() {
let a: map<Int, String> = emptyMap();
foreach (key/* : Int */, value/* : String */ in a) {}
}

========================================================================
Local variable initialized with struct init
========================================================================
primitive Int;

struct Foo { value: Int }

fun foo() {
let a = Foo { value: 10 };
}
------------------------------------------------------------------------
primitive Int;

struct Foo { value: Int/* as int257 */ }

fun foo() {
let a = Foo { value: 10 };
}
9 changes: 9 additions & 0 deletions server/src/inlays/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ function processParameterHints(
const arg = args[i]
const paramName = param.name()

if (paramName.length === 1) {
// don't show hints for single letter parameters
continue
}

if (arg.text === paramName || arg.text.endsWith(`.${paramName}`)) {
// no need to add hint for `takeFoo(foo)` or `takeFoo(val.foo)`
continue
Expand Down Expand Up @@ -93,6 +98,10 @@ export function collect(
const expr = decl.value()
if (!expr) return true

// don't show hint for:
// let params = SomeParams{}
if (expr.node.type === "instance_expression") return true

const name = decl.nameIdentifier()
if (!name) return true

Expand Down