Skip to content

Fix/84847 source generated rename conflict - #84849

Merged
akhera99 merged 4 commits into
dotnet:mainfrom
AdmiralSnyder:fix/84847-source-generated-rename-conflict
Aug 17, 2026
Merged

akhera99 merged 4 commits into
dotnet:mainfrom
AdmiralSnyder:fix/84847-source-generated-rename-conflict

Conversation

@AdmiralSnyder

@AdmiralSnyder AdmiralSnyder commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #84847
Claude generated fixes for #84847 :

  • include source generated files (razor) in rename operations,

  • use GetRequiredDocumentAsync instead of GetRequiredDocument

  • a test was also added, it contains a comment quite large, but LLMs are wordy...
    ... and feels a little incomplete since it only tests that that rename didn't modify
    ... and shouldn't the field in the Unrelated class have the original name (i.e. Type) to test that the rename operation didn't mistakenly change it?

PRing untested in coordination with @CyrusNajmabadi after conversation in discord.

just creating the PR for now, it's easier to talk about stuff that is there.

Microsoft Reviewers: Open in CodeFlow

Added a regression test for renaming with unrelated generated documents to ensure proper handling of source-generated DocumentIds.
Copilot AI lite review requested due to automatic review settings August 11, 2026 13:25
@AdmiralSnyder
AdmiralSnyder requested a review from a team as a code owner August 11, 2026 13:25
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

' documents being annotated/renamed, but it remains part of the full per-project document set that is
' consulted when looking for declaration conflicts. That path used to call the DocumentId overload of
' GetRequiredDocument, which throws for source-generated DocumentIds instead of returning the document -
' this crashed with "GetRequiredDocument was given a source-generated DocumentId".

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.

Drop comment

var newDocument = conflictResolution.CurrentSolution.GetRequiredDocument(documentId);
// documentIdsForConflictResolution may contain ids for source-generated documents (for
// example, a rename location that lives in Razor-generated code), so we must use the
// overload that knows how to look those up instead of throwing on them.

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.

Drop commnent

@dotnet-policy-service dotnet-policy-service Bot added Community The pull request was submitted by a contributor who is not a Microsoft employee. VSCode labels Aug 11, 2026
@CyrusNajmabadi

Copy link
Copy Markdown
Contributor

We generally don't comment this way. As the failing test if you change it is better explanation for why it is needed.

Copilot AI 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.

Pull request overview

This PR fixes a crash in Roslyn’s Rename conflict resolution pipeline when the per-project document set includes source-generated DocumentIds (e.g., Razor/source generator outputs). It updates the conflict identification step to retrieve documents via the async APIs that can resolve source-generated documents, and adds a regression test covering the reported scenario.

Changes:

  • Switch conflict-resolution document lookup from GetRequiredDocument(DocumentId) to GetRequiredDocumentAsync(..., includeSourceGenerated: true, ...) in ConflictResolver.Session.IdentifyConflictsAsync.
  • Ensure both new and old solutions use source-generated-aware document retrieval when mapping declaration-conflict spans.
  • Add a regression test exercising rename when an unrelated source-generated document contains the replacement text (work item #84847).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Workspaces/Core/Portable/Rename/ConflictEngine/ConflictResolver.Session.cs Uses source-generated-aware document retrieval during conflict identification to avoid GetRequiredDocument failures on source-generated DocumentIds.
src/EditorFeatures/Test2/Rename/CSharp/SourceGeneratorTests.vb Adds a regression test ensuring rename succeeds (and does not crash) when a source-generated document is included in conflict analysis due to containing the replacement text.

Remove outdated comments from RenameWithUnrelatedGeneratedDocumentContainingReplacementText test.
Copilot AI review requested due to automatic review settings August 11, 2026 13:33
Removed comments regarding source-generated documents in conflict resolution.
@AdmiralSnyder

Copy link
Copy Markdown
Contributor Author

I edited the comments out of those files and committed. apparently github knows that those commits should be added to the PR. nice.

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings August 11, 2026 13:37

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Suppressed comments (1)

src/EditorFeatures/Test2/Rename/CSharp/SourceGeneratorTests.vb:119

  • This test currently only verifies the rename succeeds without throwing, but it doesn't assert that an unrelated source-generated document containing the original identifier text remains unchanged. Adding the original identifier (Type) into the generated document and asserting it still exists in the generated output after rename would make the regression test able to catch accidental edits to unrelated generated documents.
        Public Sub RenameWithUnrelatedGeneratedDocumentContainingReplacementText(host As RenameTestHost)
            Using result = RenameEngineResult.Create(_outputHelper,
                    <Workspace>
                        <Project Language="C#" AssemblyName="ClassLibrary1" CommonReferences="true">
                            <Document>
public class TypeData
{
    public int [|$$Type|];
}
                            </Document>
                            <DocumentFromSourceGenerator>
public class Unrelated
{
    public int Value;
}
                            </DocumentFromSourceGenerator>
                        </Project>
                    </Workspace>, host:=host, renameTo:="Value")

<Theory, CombinatorialData>
<WorkItem("https://github.com/dotnet/roslyn/issues/84847")>
Public Sub RenameWithUnrelatedGeneratedDocumentContainingReplacementText(host As RenameTestHost)
Using result = RenameEngineResult.Create(_outputHelper,

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.

out of curiosity, can you run this test before/after the resolver changes?

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.

hey, sorry, i can't. As i said in the PR: i don't have a roslyn dev environment, and so cannot do any testing for it. @CyrusNajmabadi explicitly told me to do this PR nonetheless - i also mentioned my doubts regarding the usefullness/exhaustiveness of this additional test - which copilot k*inda agrees?

I can get a dev environment up, but that will have to wait for the weekend :-|

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.

ooh I see, sorry I missed that comment. I can do that bit and will suggest another test, since it does not seem like it exhausts the changed code

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.

in lieu of modifying this PR, I'll just create a follow-up with the test. approving, thank you for the contribution!

@akhera99
akhera99 merged commit c138cb0 into dotnet:main Aug 17, 2026
25 checks passed
@AdmiralSnyder
AdmiralSnyder deleted the fix/84847-source-generated-rename-conflict branch August 23, 2026 00:16
333fred added a commit that referenced this pull request Aug 24, 2026
* upstream/main: (730 commits)
  Improve recovery for repeated partial type modifiers (#84934)
  Add standalone C# LSP telemetry (#84874)
  Suppress AI artifact audit failure issues (#84925)
  Remove empty ExternalAccessAspNetCoreResources.resx (#84939)
  Update helix job monitor version (#84940)
  Add HasPendingUpdates to HotReloadService.Updates to be used in dotnet-watch (#84891)
  Add LocalizableBranches parameter for OneLocBuild (#84933)
  Pin version of Microsoft.CodeAnalysis.Analyzers (#84924)
  Centralize record and union keyword checks (#84928)
  Caching compiler: support binary additional texts (#84916)
  Remove unused AdditionalTextComparer (#84917)
  Remove Try-Both matching mode for unions. (#84897)
  Update CodeStyleAnalyzerVersion to 5.9.0 (#84919)
  Fix/84847 source generated rename conflict (#84849)
  Return MethodNotFound for unsupported LSP method dispatch (#84892)
  [main] Update dependencies from dotnet/arcade (#84896)
  [main] Update dependencies from dotnet/arcade (#84882)
  Track status for feature "Type Parameter Inference from Constraints" (#84869)
  [main] Source code updates from dotnet/dotnet (#84879)
  Stop labeling Loc PRs as community (#84878)
  ...
@jjonescz jjonescz added this to the 18.11 milestone Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. Feature - Source Generators Source Generators VSCode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VS creates error bar on property rename complaining about GetRequiredDocument

5 participants