OrganizeImports CodeAction, how does it work #2419
-
Hi. I'm using Emacs with eglot. Regards |
Beta Was this translation helpful? Give feedback.
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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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? |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
OK, thanks. I kind of got this working.
So, I'm not sure what's wrong here. |
Beta Was this translation helpful? Give feedback.
-
OK, the I think this is sufficient info for me. |
Beta Was this translation helpful? Give feedback.
Thanks for the question @mdbergmann.
So after the
initialize
comes 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 …