-
Notifications
You must be signed in to change notification settings - Fork 726
Fix signature help to prioritize outer calls over inner calls in nested invocations #1949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
5
commits into
main
Choose a base branch
from
copilot/fix-signature-help-nested-calls
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+436
−5
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
134d85b
Initial plan
Copilot 04c7ac7
Add test cases for signature help applicable range issues
Copilot 60db782
Fix signature help applicable range for nested calls (partial)
Copilot 26de9b0
Fix signature help nested call precedence
Copilot c7519dd
Address code review comments
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
internal/fourslash/tests/signatureHelpApplicableRange_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package fourslash_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/microsoft/typescript-go/internal/fourslash" | ||
| "github.com/microsoft/typescript-go/internal/testutil" | ||
| ) | ||
|
|
||
| // Test case 1: Basic applicable range test | ||
| // This test verifies the applicable range for signature help | ||
| // According to the issue, signature help should be provided: | ||
| // - Inside the parentheses (markers 1, 2) | ||
| // - NOT on the call target before the opening paren (marker a, b, c would test this) | ||
| // - NOT after the closing paren including whitespace (markers 3, 4) | ||
| func TestSignatureHelpApplicableRangeBasic(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| defer testutil.RecoverAndFail(t, "Panic on fourslash test") | ||
| const content = `let obj = { | ||
| foo(s: string): string { | ||
| return s; | ||
| } | ||
| }; | ||
|
|
||
| let s =/*a*/ /*b*/obj/*c*/./*d*/foo/*e*/(/*1*/"Hello, world!"/*2*/)/*3*/ | ||
| /*4*/;` | ||
| f := fourslash.NewFourslash(t, nil /*capabilities*/, content) | ||
|
|
||
| // Use VerifyBaselineSignatureHelp to check behavior at all markers | ||
| f.VerifyBaselineSignatureHelp(t) | ||
| } | ||
|
|
||
| // Test case 2: Nested calls - outer should take precedence | ||
| func TestSignatureHelpNestedCalls(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| defer testutil.RecoverAndFail(t, "Panic on fourslash test") | ||
| const content = `function foo(s: string) { return s; } | ||
| function bar(s: string) { return s; } | ||
| let s = foo(/*a*//*b*/bar/*c*/(/*d*/"hello"/*e*/)/*f*/);` | ||
| f := fourslash.NewFourslash(t, nil /*capabilities*/, content) | ||
|
|
||
| // Use VerifyBaselineSignatureHelp to check behavior at all markers | ||
| f.VerifyBaselineSignatureHelp(t) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
182 changes: 182 additions & 0 deletions
182
...ta/baselines/reference/fourslash/signatureHelp/signatureHelpApplicableRangeBasic.baseline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| // === SignatureHelp === | ||
| === /signatureHelpApplicableRangeBasic.ts === | ||
| // let obj = { | ||
| // foo(s: string): string { | ||
| // return s; | ||
| // } | ||
| // }; | ||
| // | ||
| // let s = obj.foo("Hello, world!") | ||
| // ^ | ||
| // | ---------------------------------------------------------------------- | ||
| // | No signaturehelp at /*a*/. | ||
| // | ---------------------------------------------------------------------- | ||
| // ^ | ||
| // | ---------------------------------------------------------------------- | ||
| // | No signaturehelp at /*b*/. | ||
| // | ---------------------------------------------------------------------- | ||
| // ^ | ||
| // | ---------------------------------------------------------------------- | ||
| // | No signaturehelp at /*c*/. | ||
| // | ---------------------------------------------------------------------- | ||
| // ^ | ||
| // | ---------------------------------------------------------------------- | ||
| // | No signaturehelp at /*d*/. | ||
| // | ---------------------------------------------------------------------- | ||
| // ^ | ||
| // | ---------------------------------------------------------------------- | ||
| // | No signaturehelp at /*e*/. | ||
| // | ---------------------------------------------------------------------- | ||
| // ^ | ||
| // | ---------------------------------------------------------------------- | ||
| // | foo(**s: string**): string | ||
| // | ---------------------------------------------------------------------- | ||
| // ^ | ||
| // | ---------------------------------------------------------------------- | ||
| // | foo(**s: string**): string | ||
| // | ---------------------------------------------------------------------- | ||
| // ^ | ||
| // | ---------------------------------------------------------------------- | ||
| // | No signaturehelp at /*3*/. | ||
| // | ---------------------------------------------------------------------- | ||
| // ; | ||
| // ^ | ||
| // | ---------------------------------------------------------------------- | ||
| // | No signaturehelp at /*4*/. | ||
| // | ---------------------------------------------------------------------- | ||
| [ | ||
| { | ||
| "marker": { | ||
| "Position": 76, | ||
| "LSPosition": { | ||
| "line": 6, | ||
| "character": 7 | ||
| }, | ||
| "Name": "a", | ||
| "Data": {} | ||
| }, | ||
| "item": null | ||
| }, | ||
| { | ||
| "marker": { | ||
| "Position": 77, | ||
| "LSPosition": { | ||
| "line": 6, | ||
| "character": 8 | ||
| }, | ||
| "Name": "b", | ||
| "Data": {} | ||
| }, | ||
| "item": null | ||
| }, | ||
| { | ||
| "marker": { | ||
| "Position": 80, | ||
| "LSPosition": { | ||
| "line": 6, | ||
| "character": 11 | ||
| }, | ||
| "Name": "c", | ||
| "Data": {} | ||
| }, | ||
| "item": null | ||
| }, | ||
| { | ||
| "marker": { | ||
| "Position": 81, | ||
| "LSPosition": { | ||
| "line": 6, | ||
| "character": 12 | ||
| }, | ||
| "Name": "d", | ||
| "Data": {} | ||
| }, | ||
| "item": null | ||
| }, | ||
| { | ||
| "marker": { | ||
| "Position": 84, | ||
| "LSPosition": { | ||
| "line": 6, | ||
| "character": 15 | ||
| }, | ||
| "Name": "e", | ||
| "Data": {} | ||
| }, | ||
| "item": null | ||
| }, | ||
| { | ||
| "marker": { | ||
| "Position": 85, | ||
| "LSPosition": { | ||
| "line": 6, | ||
| "character": 16 | ||
| }, | ||
| "Name": "1", | ||
| "Data": {} | ||
| }, | ||
| "item": { | ||
| "signatures": [ | ||
| { | ||
| "label": "foo(s: string): string", | ||
| "parameters": [ | ||
| { | ||
| "label": "s: string" | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "activeSignature": 0, | ||
| "activeParameter": 0 | ||
| } | ||
| }, | ||
| { | ||
| "marker": { | ||
| "Position": 100, | ||
| "LSPosition": { | ||
| "line": 6, | ||
| "character": 31 | ||
| }, | ||
| "Name": "2", | ||
| "Data": {} | ||
| }, | ||
| "item": { | ||
| "signatures": [ | ||
| { | ||
| "label": "foo(s: string): string", | ||
| "parameters": [ | ||
| { | ||
| "label": "s: string" | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "activeSignature": 0, | ||
| "activeParameter": 0 | ||
| } | ||
| }, | ||
| { | ||
| "marker": { | ||
| "Position": 101, | ||
| "LSPosition": { | ||
| "line": 6, | ||
| "character": 32 | ||
| }, | ||
| "Name": "3", | ||
| "Data": {} | ||
| }, | ||
| "item": null | ||
| }, | ||
| { | ||
| "marker": { | ||
| "Position": 106, | ||
| "LSPosition": { | ||
| "line": 7, | ||
| "character": 2 | ||
| }, | ||
| "Name": "4", | ||
| "Data": {} | ||
| }, | ||
| "item": null | ||
| } | ||
| ] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why we need this.
@copilot is there a test file that shows where this helps? What happens if you remove it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback logic (lines 645-647) is needed to handle edge cases where the cursor is inside a call's parentheses but outside the computed applicable span. This happens in several scenarios:
foo(/*cursor*/)- the cursor is inside the parentheses but there are no arguments, so the applicable span may not include this positionfoo(arg/*cursor*/)- when trivia/whitespace follows the last argumentWithout this fallback, 14 existing tests fail (e.g.,
TestSignatureHelpJSDocTagswhere markers likeFoo.method1(/*11*/)return null instead of showing signature help).The fallback ensures that if we find a call while walking up the tree but the position is slightly outside its span (and there's no outer call), we still show that call's signature help rather than returning null. This preserves the existing behavior for non-nested calls while still fixing the nested call precedence issue.