Skip to content

Add Using code action doesn't work in a world where Roslyn and Razor lack span mapping service #8671

@davidwengier

Description

@davidwengier

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 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

Some very minor more context internally at https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1813520

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions