Fork me on GitHub
#lsp
<
2021-04-20
>
borkdude12:04:24

Someone on twitter suggested a new refactoring in lsp: rewrite namespaced map to normal map

ericdallo12:04:13

like #:foo{:bar 1} -> {:foo/bar 1} ?

borkdude12:04:45

and perhaps also vice versa, but the first one would be good to start with

ericdallo12:04:10

yes, I like both, not sure how to do it with rewrite-clj, but I can take a look later

borkdude12:04:32

note that you can also have #:foo{:x/bar 1} and #:foo{:_/bar 1}

borkdude12:04:48

the last one if equivalent to {:bar 1}

ericdallo12:04:01

yeah, corner cases haha

borkdude12:04:12

clj-kondo analysis accounts for these cases

borkdude12:04:29

related to the above tweet

bartuka18:04:16

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

bartuka18:04:52

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?

ericdallo18:04:40

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

ericdallo19:04:15

Anyway, refactoring call does not rely on any context

ericdallo19:04:09

@UBSREKQ5Q I just tested manually calling lsp-clojure-add-missing-libspec and it worked properly instead of calling Add missing '...' require code action

bartuka19:04:21

I will disable clj-refactor and cider and test again

ericdallo19:04:38

I use both, not sure they could affect that feature if you are calling it manually

bartuka19:04:10

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

ericdallo19:04:44

that doesn't work for java imports

ericdallo19:04:03

you can check that already as clojure-lsp doesn't return add missing code actions for that line

ericdallo19:04:17

that's why trust the code actions is always better

ericdallo19:04:33

if there is available, clojure-lsp will return, if not, there will not exist a code action for that line/char

ericdallo19:04:01

at least for me SPC c a RET (doom-emacs) is enough to apply the code action

ericdallo19:04:30

and add missing code actions are always preferred , so they appear on top of the code actions list

bartuka19:04:15

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?

bartuka19:04:24

(for this case)

bartuka19:04:56

it does show me

ericdallo19:04:19

Oh, forgot about that, that is another action

ericdallo19:04:26

add-missing-import

ericdallo19:04:45

That work only for common java classes

bartuka19:04:49

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

ericdallo19:04:08

java.util only I think

ericdallo19:04:01

Rename it's another lsp specific method, so it's not a refactor

ericdallo19:04:32

You can use lsp-mode whichkey which has all lsp commands

bartuka19:04:50

rename is a refactor btw hehe

ericdallo19:04:17

Anyway, the keybindings page from emacs-lsp should help you as this is a common question

bartuka19:04:26

yes, thanks 🎉

😉 3
Drew Verlee20:04:49

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.

Drew Verlee20:04:32

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

Drew Verlee20:04:59

if i create sibling directory to b, then i don't have this issue.

ericdallo20:04:28

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

ericdallo20:04:34

then import the correct path

ericdallo20:04:47

with that, lsp-mode will start watching from the project root and use that as the root for a lot other features