Skip to content
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

Allow VS Code to provide razor source geneator references. #72482

Merged
merged 4 commits into from
Mar 18, 2024

Conversation

maryamariyan
Copy link
Member

@maryamariyan maryamariyan commented Mar 11, 2024

Fixes Work Item 1926900

/cc @CyrusNajmabadi @davidwengier @chsienki @dibarbet
Needs dotnet/vscode-csharp#6960 to complete the end to end workflow.

{
// This method is used to load an analyzer assembly from the specified path.
// In this simple implementation, we use Assembly.LoadFrom to load the assembly.
return Assembly.LoadFrom(fullPath);
Copy link
Member

Choose a reason for hiding this comment

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

Did you talk with Jason at all about which assembly load context the source generator should be loaded in?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't recall that conversation.

- Rename option to be `RazorSourceGenerator`
- Cache results in analyzer provider, since result is fixed per roslyn instance
- Remove duped names taken out of ProjectSystemProject
@@ -1002,6 +1002,7 @@ public void RemoveAnalyzerReference(string fullPath)

private OneOrMany<string> GetMappedAnalyzerPaths(string fullPath)
{
fullPath = Path.GetFullPath(fullPath);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still necessary, now that the full path is being passed in by the client?

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe this is needed.

Without this change, variable will be:

s_razorSourceGeneratorSdkDirectory

"Sdks\\Microsoft.NET.Sdk.Razor\\source-generators\\"

fullPath

"C:\\Program Files\\dotnet\\sdk\\6.0.420\\Sdks\\Microsoft.NET.Sdk.Razor\\targets\\..\\\\source-generators\\Microsoft.NET.Sdk.Razor.SourceGenerators.dll"

Path.DirectorySeparatorChar

 92 '\\'

and the if condition below would be false and we won't go through getting analyzer references at all:

if (fullPath.LastIndexOf(s_razorSourceGeneratorSdkDirectory, StringComparison.OrdinalIgnoreCase) + s_razorSourceGeneratorSdkDirectory.Length - 1 ==
    fullPath.LastIndexOf(Path.DirectorySeparatorChar))

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, that's a surprising value for fullPath. I thought this code also ran in VS, so I'm confused as to how it works there.

@davidwengier
Copy link
Contributor

Removing auto-merge, just in case :)

@dibarbet dibarbet merged commit 7809895 into dotnet:main Mar 18, 2024
27 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Mar 18, 2024
@RikkiGibson RikkiGibson modified the milestones: Next, 17.10 P3 Mar 25, 2024
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. untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants