Skip to content

Provide more accurate rename range in prepareRename LSP response - #3443

Merged
Jake Bailey (jakebailey) merged 1 commit into
microsoft:mainfrom
auvred:accurate-range-in-prepareRename
Apr 20, 2026
Merged

Provide more accurate rename range in prepareRename LSP response#3443
Jake Bailey (jakebailey) merged 1 commit into
microsoft:mainfrom
auvred:accurate-range-in-prepareRename

Conversation

@auvred

@auvred auvred commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Strada uses node.getStart, while Corsa uses node.Pos. This causes the textDocument/prepareRename method to return a range with leading trivia. As a result, that range doesn't match the one later returned returned by textDocument/rename.

@jakebailey

Copy link
Copy Markdown
Member

This seems fine but, no tests change?

@auvred

auvred commented Apr 20, 2026

Copy link
Copy Markdown
Contributor Author

This seems fine but, no tests change?

TextDocumentPrepareRenameInfo is used in fourslash only in VerifyRenameSucceeded and VerifyRenameFailed, and neither validates the response it returns:

func (f *FourslashTest) VerifyRenameSucceeded(t *testing.T, preferences *lsutil.UserPreferences) {
if preferences != nil {
defer f.ConfigureWithReset(t, *preferences)()
}
params := &lsproto.PrepareRenameParams{
TextDocument: lsproto.TextDocumentIdentifier{
Uri: lsconv.FileNameToDocumentURI(f.activeFilename),
},
Position: f.currentCaretPosition,
}
prefix := f.getCurrentPositionPrefix()
result := sendRequest(t, f, lsproto.TextDocumentPrepareRenameInfo, params)
if result.Range == nil && result.PrepareRenamePlaceholder == nil && result.PrepareRenameDefaultBehavior == nil {
t.Fatal(prefix + "Expected rename to succeed, but prepareRename returned null")
}
// Also verify that textDocument/rename produces edits, since prepareRename is optional.
renameResult := sendRequest(t, f, lsproto.TextDocumentRenameInfo, &lsproto.RenameParams{
TextDocument: lsproto.TextDocumentIdentifier{
Uri: lsconv.FileNameToDocumentURI(f.activeFilename),
},
Position: f.currentCaretPosition,
NewName: "RENAME_SUCCEEDED_TEST",
})
if renameResult.WorkspaceEdit == nil || renameResult.WorkspaceEdit.Changes == nil || len(*renameResult.WorkspaceEdit.Changes) == 0 {
t.Fatal(prefix + "prepareRename succeeded but textDocument/rename returned no changes")
}
}

Should I update them to save the results to the baseline?

@jakebailey Jake Bailey (jakebailey) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good, though, I'm not sure how that plays into our existing diffing. Probably it's not worth it, I can see that this is obviously correct.

@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queue Apr 20, 2026
Merged via the queue into microsoft:main with commit dfa7a1d Apr 20, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants