OrganizeImports CodeAction, how does it work #2419
|
Hi. I'm using Emacs with eglot. Regards |
Replies: 6 comments 3 replies
|
Thanks for the question @mdbergmann.
So after the So eglot should pick that up and see that Metals supports it.
There should be a general way to just trigger this for a file with an
Just a small correction, this feature in Metals is actually implemented with Scalafix and the scalafix-organize-imports rule whereas the formatting feature is done with Scalafmt. |
|
Also as a total aside, our eglot section probably hasn't been touched in quite some time. Please feel free to let us know if there is anything out of date on there and send in a pr to either fix anything, add anything you find useful, etc. |
|
Yep, thanks. I'll have a look if there is something out of date for eglot.
Is this part of the LSP protocol to trigger such a thing? |
|
So, OK. Please help me understand. A CodeAction request by the client makes the server respond with available CodeActions for the given Range.
It can also be both. I am tracing the RPC communication, so I could see what command it might be, but Metals doesn't seem to send a CodeAction for organizing imports to eglot even after explicitly adding unused imports. |
|
OK, thanks. I kind of got this working. So, I'm not sure what's wrong here. |
|
OK, the I think this is sufficient info for me. |
Thanks for the question @mdbergmann.
So after the
initializecomes in, Metals declares that it supports the organize imports code action here:metals/metals/src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala
Lines 726 to 738 in a5bb60d
So …