Someone on twitter suggested a new refactoring in lsp: rewrite namespaced map to normal map
related to the above tweet
looks valid
like #:foo{:bar 1}
-> {:foo/bar 1}
?
yes
and perhaps also vice versa, but the first one would be good to start with
yes, I like both, not sure how to do it with rewrite-clj, but I can take a look later
note that you can also have #:foo{:x/bar 1}
and #:foo{:_/bar 1}
the last one if equivalent to {:bar 1}
yeah, corner cases haha
clj-kondo analysis accounts for these cases
nice
hi, I am using lsp & clj-refactor side-by-side for now and I really like the clj-refactor mnemonics. I have added some functions from LSP to replace the operations that require code evaluation from clj-refactor's side e.g. (define-key clj-refactor-map (cljr--key-pairs-with-prefix "C-c C-m" "rs") 'lsp-rename)
instead of default rename. Nice, this works fine but not for some functions from lsp. If I bind lsp-clojure-add-missing-libspec
and try to call it directly, nothing happens but if I go down the path code actions -> add missing libspec
with the cursor on top of the same symbol, it does work
lsp-clojure-add-missing-libspec
is basically a sugar for this (lsp-clojure--refactoring-call "add-missing-libspec")
looks like refactoring-call
rely on some context?
There are at least 3 code actions about add missing something, the issue with calling the command manually is that you need to know which one use
Anyway, refactoring call does not rely on any context
@iagwanderson I just tested manually calling lsp-clojure-add-missing-libspec
and it worked properly instead of calling Add missing '...' require
code action
I will disable clj-refactor and cider and test again
I use both, not sure they could affect that feature if you are calling it manually
i think the problem is knowing which function to call. I tried (rop/>>=)
and rop.core
was added correctly, but (UUID/randomUUID)
does not work
that doesn't work for java imports
you can check that already as clojure-lsp doesn't return add missing code actions for that line
that's why trust the code actions is always better
if there is available, clojure-lsp will return, if not, there will not exist a code action for that line/char
at least for me SPC c a
RET
(doom-emacs) is enough to apply the code action
and add missing code actions are always preferred
, so they appear on top of the code actions list
w8, not sure if I am following, you are saying that for java imports I would not see a Add missing 'java.util.UUID' import?
(for this case)
Yep
it does show me
Oh, forgot about that, that is another action
add-missing-import
That work only for common java classes
if I do C-c l a
RET
I do apply the code action, but I find confusing to remember what is code action, what is refactor, etc. If I need to rename something, is this an code action or refactor? so I wanted to rely on clj-refactor mnemonics that I already have msucle memory
java.util only I think
Rename it's another lsp specific method, so it's not a refactor
You can use lsp-mode whichkey which has all lsp commands
rename is a refactor btw hehe
> rename is a refactor btw hehe Not from Microsoft LSP eyes: https://microsoft.github.io/language-server-protocol/specification#textDocument_rename
Anyway, the keybindings page from emacs-lsp should help you as this is a common question
yes, thanks 🎉
How do i tell LSP the root directory i want to watch? It seems to want to watch a level further down then I want. A lot of other tooling (helm?) seems to use the git directory level as root, which seems reasonable.
e.g whats happening now is i create a new project/git repo at one level "a" and it tries to watch at the parent "b". b/a/src/.../core.clj
if i create sibling directory to b, then i don't have this issue.
your issue is with the project root defined by lsp-mode, when you open a project for the first time, lsp-mode asks where is the project root, to fix a wrong path, you can lsp-workspace-folder-remove
, select and remove the wrong parent path and then lsp
on a buffer of the project
then import the correct path
with that, lsp-mode will start watching from the project root and use that as the root for a lot other features