-
Notifications
You must be signed in to change notification settings - Fork 232
Fix cross project span and edit mapping #12614
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
Conversation
…ate that inputs are correct
… success and all that
| """; | ||
|
|
||
| var solution = LocalWorkspace.CurrentSolution; | ||
| var project1 = AddProjectAndRazorDocument(solution, TestProjectData.SomeProject.FilePath, someProjectId, surveyPromptId, TestProjectData.SomeProjectComponentFile1.FilePath, surveyPrompt.Text).Project; |
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.
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.
Yes, to simulate OOP syncing in tests we create two solutions with identical projects and documents, but different MEF compositions, so the IDs have to match.
| ?? ThrowHelper.ThrowInvalidOperationException<Project>($"The project {projectKey} did not exist in {solution}."); | ||
| } | ||
|
|
||
| public static bool TryGetSourceGeneratedDocumentIdentity(this Solution solution, Uri generatedDocumentUri, out RazorGeneratedDocumentIdentity identity) |
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.
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.
AFAIK getting the source generated document would mean running the source generators, this can get the identity without doing that. Also, getting the source generated document is only useful if that's what you need to work with. To get the originating Razor document for a source generated document, you'd need to go back to the identity anyway.
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.
Just to clarify, I was thinking along something like:
public static async Task<SourceGeneratedDocument?> TryGetSourceGeneratedDocumentAsync(this Solution solution, Uri generatedDocumentUri, CancellationToken cancellationToken)
{
if (!RazorUri.IsGeneratedDocumentUri(generatedDocumentUri) ||
!solution.TryGetSourceGeneratedDocumentIdentity(generatedDocumentUri, out var identity) ||
!solution.TryGetProject(identity.DocumentId.ProjectId, out var project))
{
return null;
}
return await project.TryGetCSharpDocumentForGeneratedDocumentAsync(identity, cancellationToken).ConfigureAwait(false);
}
in SolutionExtensions.cs and something like:
public async Task<RazorCodeDocument?> TryGetSourceGeneratedDocumentAsync(Solution solution, Uri generatedDocumentUri, CancellationToken cancellationToken)
{
if (!RazorUri.IsGeneratedDocumentUri(generatedDocumentUri) ||
!solution.TryGetSourceGeneratedDocumentIdentity(generatedDocumentUri, out var identity) ||
!identity.IsRazorSourceGeneratedDocument() ||
!solution.TryGetProject(identity.DocumentId.ProjectId, out var project))
{
return null;
}
return await GetSnapshot(project).TryGetCodeDocumentForGeneratedDocumentAsync(identity, cancellationToken).ConfigureAwait(false);
}
in RemoteSnapshotManager.cs. But maybe that still has the issues that you called out?
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.
ohhh, I see what you're saying, helper methods for the common scenarios. Yes, that would work. This method might still need to stay too, but I should be able to simplify some of the calling code. Will take a look
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.
Logged #12637 to follow up, probably post-snap
ToddGrun
left a comment
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.
![]()
Fixes #12608
Previous code was making bad assumptions about everything being in one project, and just using hint name to identify a generated document. New code uses SourceGeneratedDocumentIdentity, which can reason about projects, and hides direct hint name use as much as possible.