Fork me on GitHub
#calva
<
2023-01-06
>
Matthew Odendahl20:01:48

Is there a way for Calva to move a form to another namespace and update all references? (For vars used inside the form itself and any namespaces that used to point to it.) I'm not finding it.

Matthew Odendahl20:01:16

When I use the Clojure LSP in Spacemacs, there's an lsp-clojure-move-form command. There's also a CIDER plugin to do refactorings.

skylize20:01:32

Calva offers some LSP refactors, but that one is currently not included. I suggest opening an Issue to request it.

skylize20:01:56

@U0ETXRFEW, What is involved in adding a refactor command? My cursory look makes me think it could be as simple as adding {command: 'move-form'}, to https://github.com/BetterThanTomorrow/calva/blob/e8d68ee0541ce87368cb0b109b586100a8f1db64/src/lsp/main.ts#L200. Assuming that is true (I could of course be wildly off), is there any reason to not enable every command listed at https://github.com/clojure-emacs/clj-refactor.el/tree/master/examples?

pez21:01:51

I think mostly it is only about enumeration, like you suggest. Can’t see a reason to exclude any existing refactor. As long as it works. PR welcome. (EDITED)

Matthew Odendahl16:01:59

> Can’t see a reason to exclude any existing refactor. As long as it works. @U0ETXRFEW What if it only partially works? Some of the refactors seems to have bugs in Spacemacs. Not sure if that's the layer or the LSP itself. Also, some of the clojure-mode refactorings in Spacemacs are through https://github.com/clojure-emacs/clj-refactor.el. Could Calva support those too, or would that only work in Emacs? Even buggy refactorings are sometimes easier than doing everything by hand, and the more people that use them, the more likely the bugs get found, reported, and fixed upstream.

Stefan16:01:25

Today I went through the Clojure-lsp docs and I didn’t find any other missing refactorings. Did you have anything specific in mind, other than the move-form refactoring, @U04ERSXPHGR ?

Matthew Odendahl17:01:49

Are all of the Calva ones listed in its package.json? I looked in there and didn't see the following from the LSP refactor method:

add-missing-import
add-require-suggestion
cycle-coll
change-coll
destructure-keys
restructure-keys
promote-fn
demote-fn
drag-forward ; does paredit do this instead?
drag-backward ; ?
drag-param-backward
drag-param-forward
extract-to-def
get-in-more
get-in-less
get-in-none
sort-clauses
sort-map ; deprecated for sort-clauses
move-coll-entry-up ; deprecated for drag-backward
move-coll-entry-down ; deprecated for drag-forward
suppress-diagnostic
create-function
create-test
move-form ; the one we're discussing now
cycle-keyword-auto-resolve
https://github.com/clojure-lsp/clojure-lsp/blob/master/lib/src/clojure_lsp/feature/refactor.clj

skylize17:01:35

Yes, they need to be listed in package.json. They also need to be registered as commands in the extension code. For refactors, Calva does that by walking through this dict. https://github.com/BetterThanTomorrow/calva/blob/ef533e063988fa62ca2d8feb3f1a568b1607c0a1/src/lsp/main.ts#L200

Stefan17:01:47

Those in Calva source are NOT the only ones, more are provided as quick fixes.

skylize17:01:51

Are there quick fixes that are "refactor"s (as opposed to some other action that also happens to be provided by LSP)? If so, do they only make sense as quick fixes? Or might some users potentially want a command they can pull up in the command palette or bind a hotkey to?