omnisharp-roslyn icon indicating copy to clipboard operation
omnisharp-roslyn copied to clipboard

Code actions not making any changes to documents when selected

Open mcraveiro opened this issue 11 months ago • 2 comments

Thanks very much for an extremely useful product. I have a bit of an exploratory question. I am using Omnisharp on Windows with Emacs:

  • Operative System: Windows 10
  • LSP server: Omnisharp 1.39
  • Emacs: 29.1
  • Programming language: C# (csharp-mode)

Omnisharp works great except for the code actions. I get a list of code actions but when I select them, nothing happens. I am investigating the issue here: https://github.com/joaotavora/eglot/discussions/1322

What I'd like to know is, are the files modified by Omnisharp or by Emacs on a code action request? I tried debugging, and it seems like the editor is requesting the server for the changes. If that is the case, is there a log in Omnisharp I could consult to see why the files are not changing?

Many thanks for your time,

mcraveiro avatar Mar 07 '24 19:03 mcraveiro

I created a discussion in reddit to see if I can gather more information on this matter. [1]

[1] https://www.reddit.com/r/emacs/comments/1bawgko/eglot_code_actions_do_not_change_the_buffer/

mcraveiro avatar Mar 10 '24 00:03 mcraveiro

After a fair bit of debugging with the eglot developer [1], we finally understand the problem a bit better. It seems that Omnisharp is not sending either edit or command in the code actions message. Here is an example message as we see it in Emacs:

(:title "Generate variable 'xConnssole' -> Generate field 'xConnssole'" :kind "quickfix" :diagnostics
               []
               :data
               (:Uri "file:///home/user/dotnet/Program.cs" :Identifier "Generate field 'xConnssole'" :Name "Generate variable 'xConnssole' -> Generate field 'xConnssole'" :Range
                     (:Start
                       (:Line 12 :Character 12)
                       :End
                       (:Line 12 :Character 22))
                     :$$__handler_id__$$ "2e314f16-b735-46d8-ab39-2c20ee0d8960"))

Is there any reason why Omnisharp would do that? I have been reading through the code action spec [2] but unfortunately it isn't obvious if these parameters are mandatory or not.

[1] https://github.com/joaotavora/eglot/discussions/1322#discussioncomment-8833688 [2] https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_codeAction

mcraveiro avatar Mar 20 '24 07:03 mcraveiro