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

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

Closed
Tracked by #6919
davidwengier opened this issue May 5, 2023 · 1 comment · Fixed by #9991
Closed
Tracked by #6919
Assignees
Milestone

Comments

@davidwengier
Copy link
Contributor

davidwengier commented May 5, 2023

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

@ghost ghost added the untriaged label May 5, 2023
@davidwengier
Copy link
Contributor Author

davidwengier commented May 5, 2023

FYI @phil-allen-msft @chsienki @genlu @CyrusNajmabadi

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 phil-allen-msft added this to the 17.7 Planning milestone May 18, 2023
@ghost ghost removed the untriaged label May 18, 2023
@davidwengier davidwengier self-assigned this Feb 26, 2024
@davidwengier davidwengier modified the milestones: 17.10 Planning, 17.10 P2 Feb 26, 2024
@phil-allen-msft 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants