lsp

:clojure-lsp: Clojure implementation of the Language Server Protocol: https://clojure-lsp.io/
borkdude 2021-04-20T12:50:24.090Z

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

borkdude 2021-04-20T12:50:29.090200Z

related to the above tweet

ericdallo 2021-04-20T12:50:52.090300Z

looks valid

ericdallo 2021-04-20T12:51:13.090500Z

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

borkdude 2021-04-20T12:51:27.090700Z

yes

borkdude 2021-04-20T12:51:45.090900Z

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

ericdallo 2021-04-20T12:52:10.091100Z

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

borkdude 2021-04-20T12:52:32.091300Z

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

borkdude 2021-04-20T12:52:48.091500Z

the last one if equivalent to {:bar 1}

ericdallo 2021-04-20T12:53:01.091700Z

yeah, corner cases haha

borkdude 2021-04-20T12:53:12.091900Z

clj-kondo analysis accounts for these cases

ericdallo 2021-04-20T12:53:49.092100Z

nice

bartuka 2021-04-20T18:17:16.094800Z

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

bartuka 2021-04-20T18:19:52.094900Z

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?

ericdallo 2021-04-20T18:53:40.095100Z

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

ericdallo 2021-04-20T19:05:15.095300Z

Anyway, refactoring call does not rely on any context

ericdallo 2021-04-20T19:24:09.095500Z

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

bartuka 2021-04-20T19:26:21.095700Z

I will disable clj-refactor and cider and test again

ericdallo 2021-04-20T19:27:38.095900Z

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

bartuka 2021-04-20T19:29:10.096100Z

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

ericdallo 2021-04-20T19:29:44.096300Z

that doesn't work for java imports

ericdallo 2021-04-20T19:30:03.096500Z

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

ericdallo 2021-04-20T19:30:17.096700Z

that's why trust the code actions is always better

ericdallo 2021-04-20T19:30:33.096900Z

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

ericdallo 2021-04-20T19:31:01.097100Z

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

ericdallo 2021-04-20T19:31:30.097300Z

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

bartuka 2021-04-20T19:32:15.097500Z

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?

bartuka 2021-04-20T19:32:24.097700Z

(for this case)

ericdallo 2021-04-20T19:34:40.097900Z

Yep

bartuka 2021-04-20T19:34:56.098100Z

it does show me

ericdallo 2021-04-20T19:35:19.098500Z

Oh, forgot about that, that is another action

ericdallo 2021-04-20T19:35:26.098700Z

add-missing-import

ericdallo 2021-04-20T19:35:45.098900Z

That work only for common java classes

bartuka 2021-04-20T19:35:49.099100Z

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

ericdallo 2021-04-20T19:36:08.099300Z

java.util only I think

ericdallo 2021-04-20T19:37:01.099500Z

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

ericdallo 2021-04-20T19:37:32.099700Z

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

bartuka 2021-04-20T19:37:50.099900Z

rename is a refactor btw hehe

ericdallo 2021-04-20T19:37:58.100100Z

https://emacs-lsp.github.io/lsp-mode/page/keybindings/

ericdallo 2021-04-20T19:39:31.100500Z

> rename is a refactor btw hehe Not from Microsoft LSP eyes: https://microsoft.github.io/language-server-protocol/specification#textDocument_rename

ericdallo 2021-04-20T19:40:17.100900Z

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

bartuka 2021-04-20T19:41:26.101100Z

yes, thanks 🎉

😉 1
2021-04-20T20:41:49.103100Z

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.

2021-04-20T20:43:32.103200Z

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

2021-04-20T20:43:59.103400Z

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

ericdallo 2021-04-20T20:57:28.103600Z

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

ericdallo 2021-04-20T20:57:34.103800Z

then import the correct path

ericdallo 2021-04-20T20:57:47.104Z

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