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
nsnamespace 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