-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[plugin-ext] Fix WorkspaceEdits for rename providers #6304
Conversation
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've just tried with the python vscode extension with a file that contained:
a = 500
print(a)
for i in range(0, 100):
print('hello world ', i)
Attempting to use rename symbol
on a
and i
yields:
root ERROR Rename failed to execute.
Uncaught (in promise) TypeError: Cannot read property 'edits' of undefined
at toMonacoWorkspaceEdit (languages-main.ts:801)
With continuously calling rename I also got:
root ERROR Rename failed to execute.
Uncaught (in promise) TypeError: Cannot read property 'edits' of undefined
at toMonacoWorkspaceEdit (languages-main.ts:801)
for (const edit of data.edits) { | ||
if (typeof (<ResourceTextEditDto>edit).resource === 'object') { | ||
(<ResourceTextEditDto>edit).resource = URI.revive((<ResourceTextEditDto>edit).resource); | ||
export function toMonacoWorkspaceEdit(data: WorkspaceEditDto): monaco.languages.WorkspaceEdit { |
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.
Can we guarantee that data and data.edits are not undefined? It looks like the previous code had guards to check for 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.
thanks for testing @JPinkney and @benoitf!
indeed this was not the case with the happy path.
given this shape:
export interface WorkspaceEditDto {
edits: (ResourceFileEditDto | ResourceTextEditDto)[];
rejectReason?: string;
}
I adjusted the result of provideRenameEdits
in case of an error to not return undefined!
for edits
.
actually, I don't understand why the adapter isn't rejecting in this case but returning with something to be handled down the road. well, I couldn't find any use of rejectReason
either. what's the concept behind this?
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.
Can we guarantee that data and data.edits are not undefined?
@JPinkney as long as we're are creating these objects, the answer is "yes".
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.
@JPinkney I had to update again. Please retest.
I got
with https://www.pythonforbeginners.com/code-snippets-source-code/magic-8-ball-written-in-python/ |
Fixes #6295 Signed-off-by: Alex Tugarev <alex.tugarev@typefox.io>
@@ -57,7 +57,7 @@ export class RenameAdapter { | |||
if (rejectReason) { | |||
return <WorkspaceEditDto>{ | |||
rejectReason, | |||
edits: undefined! | |||
edits: [] |
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.
this shouldn't break with the expected handling of rejectReason
, which BTW is commented with a todo to be a proper rejection in the origin of this.
I was able to get the rename refactoring to work on:
it takes a bit of time (which I assume is just the plugin taking its time) but when it completes I get this error in the console:
|
that's usually the case for workspace edits.
@JPinkney please help me to reproduce it. I tried with your example and others after a clean build, and with both the jedi engine and the new LS. could you share a workspace snapshot? |
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.
Looks good code-wise.
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.
@AlexTugarev I can no longer reproduce that error on my side (I must have been doing something wrong). Code looks good to me!
@JPinkney, @benoitf, @svenefftinge thanks for checking! 🙏 |
What it does
WorkspaceEdit
s created inlanguages-main.ts
should includemonaco.Uri
s instead ofrequire("vscode-uri").URI
s. "Rename Symbol" is broken due to this, and this PR fixes it.Fixes #6295
How to test
Error applying workspace edits: Error: Unexpected edit type: {}
Review checklist
Reminder for reviewers