You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On the Razor side, we are perfectly capable of handling the code action, and associated edit, but we have no way to tell Roslyn that, so it simply doesn't offer us the chance.
Potential solutions:
Don't generate hidden code
Obviously this needs sign off from the compiler folks. For the specific case of using declarations this will probably work fine, as they aren't debuggable code, but its important to remember that #line hidden will prevent the debugger from stepping through code, which we do want in most of the generated code
Related, it would be interesting to consider what breaks if we don't report the generated C# files as being generated code. There are a lot of Roslyn code actions that don't apply at all to generated code
Have some alternative way to tell Roslyn to tweak the value of the AddImportOptions.AllowInHiddenCode option for our code actions LSP request to Roslyn
Use some component in our EA layer to somehow maintain the document services, or just control document options, so Roslyn doesn't know anything is changing
Personally I like the idea of not generating hidden code for using declarations, assuming it has no other negative side-effects. In general I would love to see the generated code being a little bit more "realistic" so that Roslyn has as little "Razor magic" is has to allow for, however I do think there is a limit to this at some point, and we might not be able to achieve 100%.
phil-allen-msft
changed the title
Add Using code action doesn't work in a world where Roslyn and Razor are disconnected
Add Using code action doesn't work in a world where Roslyn and Razor lack span mapping service
Feb 29, 2024
Fall out from #6919, and specifically #8648, is that Razor and Roslyn will be slightly less connected, or at least differently connected, than they currently are. One of the things that is going to break when that happens is that Razor files will no longer be offered the Add Using code action by Roslyn, because it has an explicit check (https://github.com/dotnet/roslyn/blob/main/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/AddImport/AddImportPlacementOptions.cs#L65) that means it only offers that action in hidden code, if the Razor span mapping service is available.
On the Razor side, we are perfectly capable of handling the code action, and associated edit, but we have no way to tell Roslyn that, so it simply doesn't offer us the chance.
Potential solutions:
#line hidden
will prevent the debugger from stepping through code, which we do want in most of the generated codeAddImportOptions.AllowInHiddenCode
option for our code actions LSP request to RoslynSome very minor more context internally at https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1813520
The text was updated successfully, but these errors were encountered: