csharp-language-server-protocol icon indicating copy to clipboard operation
csharp-language-server-protocol copied to clipboard

CodeActions on visual studio

Open marknfawaz opened this issue 4 years ago • 3 comments

Hi,

Thank you for the great library. I had a question about CodeActions and how they work with Visual Studio (not VS Code). We are seeing a weird behavior and wondering if there's something we're missing.

The scenario is simple. Using the ITextDocumentSyncHandler, we are publishing diagnostics with the below properties: Range, Message, Severity, RelatedInfo, Source, Code, and CodeDescription.

And using the ICodeActionHandler, we are returning a codeAction with the below properties: Title, Edit, Diagnostics, IsPreferred

The weird behavior is that the codeAction will display with no issues, as long as there are no diagnostics that we published. It doesn't display for any range where there is a diagnostic (again, that we created). For other diagnostics, there are no issues.

I have tried multiple combinations of the properties above and seem to always get this behavior. Have you seen this issue before? Let me know.

Thanks again for building this awesome library!

marknfawaz avatar Mar 31 '21 18:03 marknfawaz

@marknfawaz my best guess is that it doesn't like you haven't provided a Command.

I ran thins demo at dotnet conf and code actions were working, but I am setting the command. https://github.com/david-driscoll/dotnet-conf-2020/blob/1a73d216cc179aaf516900e5259ab3a106b3fd6d/server/CodeActionProvider.cs

david-driscoll avatar Apr 01 '21 04:04 david-driscoll

@david-driscoll thanks for the response. When including the command, we are now seeing the code actions. I am still seeing an issue with code actions disappearing in some cases (in a c# file, while the user is still on the file). I am wondering if that's an issue you have seen in Visual studio 2019 or if there are any pointers you can help us with.

Thanks again for your help on this!

marknfawaz avatar Apr 06 '21 04:04 marknfawaz

It looks like the issue is from Intellicode in visual studio. When its LS starts, code actions will stop showing up. If you disable it, there are no issues with CS files.

marknfawaz avatar Apr 07 '21 01:04 marknfawaz