Refactor Code with Clojure LSPλ︎
, r opens Clojure LSP refactor menu
The majority of refactor tools from Clojure LSP are code actions, providing context specific tools that are only available when relevant.
Renamingλ︎
Symbols such as namespace names, function definitions, names bound to values and keywords can be renamed across a whole project
, r r
to rename symbol at point
Refactor namespaceλ︎
, rr (lsp-rename
) with the cursor on a namespace will prompt for changes to that namespace.
Enter to save the change to the namespace, updating
ns
namespace definition name- file name of the current file, including converting
-
to_
in the file name where relevant - all reference to the changed namespace name across all source code files in the project (on the class path)
Code Actionsλ︎
, a a
opens the LSP code actions menu to provide context specific refactor tools
lsp-ui sidebar shows available code actions when the following variables are added to the lsp
layer in the .spacemacs layer configuration:
Clojure LSP features includes examples of code actions.
Converting Parensλ︎
Convert between literal hash-map {}
, vector []
, set #{}
and list ()
forms
Add library namespace to current namespaceλ︎
Add the suggested library to the ns namespace definition using a require form with an alias
Add import form for known Java methods and classes
Move to let bindingλ︎
Move an expression to be a value of a new local name in an existing let
form
Move a value to a new local name in an existing let binding (inline symbol)
Extract expression to new functionλ︎
Create a new public function definition with the expression at point the body of that new function.
Replace the expression at point with a call to the new function with arguments extracted from the expression at point where relevant.
Convert to thread macroλ︎
Convert (nested) expression to a thread first or thread last form
Convert function definition to privateλ︎
Toggle function formλ︎
Toggle between short and normal forms of a function definition
Re-order data structuresλ︎
Move elements of a data structure using lsp-clojure-coll-move-entry-up
and lsp-clojure-coll-move-entry-up
, which have no key binding in Spacemacs by default (Doom Emacs uses Meta up/down arrow keys)
WARNING: does not seem to work and does not show as a code action