-
Notifications
You must be signed in to change notification settings - Fork 212
Analyzer redirector #11972
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
Analyzer redirector #11972
Conversation
@dotnet/razor-compiler for reviews please. |
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.
LGTM in general, very happy to see this progressing. Just not sure how strict we need to be about the version of Roslyn we use.
<Dependencies> | ||
<Source Uri="https://github.com/dotnet/dotnet" Mapping="razor" Sha="f5705c8f4c5079bba77bae8698ba1583bde0388c" BarId="269610" /> | ||
<ProductDependencies> | ||
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="5.0.0-1.25316.1"> | ||
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="5.0.0-1.25321.1"> |
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.
It doesn't look like this version has been inserted into VS main yet, so merging this PR could possibly break people, or our integration tests. It looks like if we downgrade this to 5.0.0-1.25319.11
then we get a version that has the Razor redirector and is in VS main.
The alternative is to wait a few days, or roll the dice that this will be fine. Or I guess we could kick off an integration test run for this branch?
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.
Scratch that, looks like 5.0.0-1.25323.2
has been inserted now, so this version should be fine.
[Export(typeof(IRazorAnalyzerAssemblyRedirector))] | ||
[method: ImportingConstructor] | ||
#pragma warning restore RS0030 // Do not use banned APIs | ||
internal class RazorAnalyzerAssemblyRedirector() : IRazorAnalyzerAssemblyRedirector |
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.
internal class RazorAnalyzerAssemblyRedirector() : IRazorAnalyzerAssemblyRedirector | |
internal sealed class RazorAnalyzerAssemblyRedirector() : IRazorAnalyzerAssemblyRedirector |
|
||
namespace Microsoft.VisualStudio.Razor; | ||
|
||
#pragma warning disable RS0030 // Do not use banned APIs |
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.
What's the banned API? And why is it banned?
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.
The export attributes and its friends are MEF v2, which is banned in the LanguageServices.Razor project, which uses this shared library. I'm not sure I can remember why, but whats a little cargo culting between friends.
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'm not sure I can remember why, but whats a little cargo culting between friends.
MS.VS.LanguageServers.Razor enforces MEFv1 because Visual Studio's MEF attributes are MEFv1. VS MEF supports importing both MEFv1 and MEFv2 attributes, but things can get in certain scenarios if their attributes are mixed on the same types.
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.
but whats a little cargo culting between friends
This precisely. It wasn't getting imported into VSCode when using one version, so I looked at the other exported parts and they had the other version and the suppression, so I copied it and it worked.
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.
Should we consider leaving a comment about this for future readers?
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.
It's replicated across most of the files in this shared project.
src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/RazorAnalyzerAssemblyRedirector.cs
Outdated
Show resolved
Hide resolved
|
||
namespace Microsoft.VisualStudio.Razor; | ||
|
||
#pragma warning disable RS0030 // Do not use banned APIs |
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'm not sure I can remember why, but whats a little cargo culting between friends.
MS.VS.LanguageServers.Razor enforces MEFv1 because Visual Studio's MEF attributes are MEFv1. VS MEF supports importing both MEFv1 and MEFv2 attributes, but things can get in certain scenarios if their attributes are mixed on the same types.
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.
oops. Accidentally blocked the PR. 😄
FYI, I merged the cleanup PR so the file header on your new file will be incorrect in CI. You probably want to merge in main :) |
This is waiting on dotnet/roslyn#79154 to prevent the extra assembly load in non-razor cases. |
|
||
namespace Microsoft.VisualStudio.Razor; | ||
|
||
#pragma warning disable RS0030 // Do not use banned APIs |
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.
Should we consider leaving a comment about this for future readers?
{ | ||
private static readonly ImmutableArray<Type> s_compilerAssemblyTypes = [ | ||
|
||
typeof(CodeAnalysis.Razor.CompilerFeatures), // Microsoft.CodeAnalysis.Razor.Compiler.dll |
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 assert these comments somehow? Or at least assert that they are different assemblies? Maybe there's some reflection-based asserts we can do to ensure that there's no unexpected assemblies being referenced that would need to be redirected in the face of a future refactoring?
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 ended up adding a unit test that 'pins' the expected assemblies, so if they change or get moved etc it will fail and we can't accidentally break things. I added a comment explaining the purpose.
2378993
to
a606e79
Compare
Mostly fixes #11942 We still currently get "Couldn't get code document" errors when the source generator is hooked up, but didn't run, but I'm leaving that because it should be fixed by #11972, and if it isn't then we either want to know, or can add handling of it in then. Commit-at-a-time is probably easiest, mostly because the 2nd commit changes every cohost endpoint to inherit from a new base class, so it's pretty noisy.
Merging as internal insertion now shows clean metrics: https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/648244 |
This is the Razor half of dotnet/roslyn#78852
It provides a redirector that will redirect the razor generator and its dependencies.