-
Notifications
You must be signed in to change notification settings - Fork 225
Description
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:
- 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 hiddenwill 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
- 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
- Have some alternative way to tell Roslyn to tweak the value of the
AddImportOptions.AllowInHiddenCodeoption for our code actions LSP request to Roslyn- This would solve the problem for this specific code action, but it would be interesting to discuss more general approaches for other things that fall into the same category (eg, Import completion, Generate method (see Allow LSP code action requests to set the (new) AllowGenerateInHiddenCode option roslyn#66917))
- 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
Some very minor more context internally at https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1813520