Skip to content

Use the correct span to rename after invoking extract-method manually.#61369

Merged
CyrusNajmabadi merged 1 commit into
dotnet:mainfrom
CyrusNajmabadi:extractMethodFix
May 18, 2022
Merged

Use the correct span to rename after invoking extract-method manually.#61369
CyrusNajmabadi merged 1 commit into
dotnet:mainfrom
CyrusNajmabadi:extractMethodFix

Conversation

@CyrusNajmabadi

Copy link
Copy Markdown
Contributor

Fixes #58971

Test incoming.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner May 17, 2022 21:38
@ghost ghost added the Area-IDE label May 17, 2022
using var undoTransaction = _undoManager.GetTextBufferUndoManager(subjectBuffer).TextBufferUndoHistory.CreateTransaction("Extract Method");

// apply extract method code to buffer
var (document, _) = extractMethodResult.GetFormattedDocumentAsync(cleanupOptions, cancellationToken).WaitAndGetResult(cancellationToken);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the bug was here. we were throwing away the second part of the result of GetFormattedDocumentASync. That part of hte result tells us where the name token is to start inline-rename after the formatting occurs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation here :)

// apply the change to buffer
// get method name token
ApplyChangesToBuffer(result, textBuffer, cleanupOptions, cancellationToken);
SyntaxToken methodNameAtInvocation;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we ever expect this to be a default value? From code it is hard to tell

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

no. it can't ever be a default value. NOte: this is not assigned anything at the decl point. It's purely a declaration of the variable. there is one and only one value assignment to it from the method invoked.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oh yea, I meant is it guaranteed to always be something or do we have cases where the returned value is wrong? Not blocking on this PR, just curious

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We weren't using it before, so I could see that this might be an area for a bug we don't know about :) Don't spend time on it, just if you know off hand.

@ryzngard ryzngard left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving with assumption of incoming test

@CyrusNajmabadi CyrusNajmabadi merged commit 87fe251 into dotnet:main May 18, 2022
@CyrusNajmabadi CyrusNajmabadi deleted the extractMethodFix branch May 18, 2022 04:36
@ghost ghost added this to the Next milestone May 18, 2022
@Neme12

Neme12 commented May 18, 2022

Copy link
Copy Markdown
Contributor

I'm just surprised and curious, why was this added without a test? Adding it later is something that can be easily forgotten. Also, I don't think the issue should be marked as closed until there's a test that verifies the behavior to prevent a regression.

@CyrusNajmabadi

Copy link
Copy Markdown
Contributor Author

I'm just surprised and curious, why was this added without a test?

Because i'm working on tests as part of another PR in this area.

@Cosifne Cosifne modified the milestones: Next, 17.3 P2 May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C# Extract method selects wrong part of code

4 participants