There are several ways of finding and fixing a bug or implementing a new feature:
clojure-lsp
using make
each time you have made changes, and test it manually in your client. This is the slowest option.Whichever development path you choose: For final testing, it is good to rebuild the binary with make
.
There are two custom LSP methods clojure/serverInfo/log
and clojure/cursorInfo/log
. They can assist in debugging.
With a clojure-lsp + nREPL powered Clojure editor you can modify your editor session's clojure-lsp server using the Clojure REPL.
Here's demo video: https://www.youtube.com/watch?v=4UvT0yqBDw8
These are the steps:
make
- to build a clojure-lsp
executable that includes cider-nrepl in the jar. This executable will be saved at the root of the project.clojure-lsp
executableserverInfo
commandport
entry in the outputSeeing is believing. An easy way to convince yourself that you can actually change clojure-lsp mid-flight is to:
server-info
function in src/clojure_lsp/handlers.clj
:foo :bar
entry to the map returnedserver-info
function definitionserverInfo
command:foo :bar
in the outputYou have just modified the LSP server powering your editor while it was running! This is the Clojure way. No recompiling and restarting and reloading. That is some other, non-Clojure, way.
The details in how to perform these steps can vary a bit between the various Clojure editors/plugins.
clojure-lsp
executable built in step 1 above. You can skip step 2.(setq lsp-clojure-custom-server-command '("~/path/to/clojure-lsp/clojure-lsp"))
, adjusting the path as necessary. If you add this to your Emacs config, you can skip this step in the future.lsp-workspace-restart
.lsp-clojure-server-info
.cider-connect-clj
, with "localhost" and the port.If you re-connect regulary, you may want to add this Emacs shortcut:
(defun lsp-clojure-nrepl-connect ()
"Connect to the running nrepl debug server of clojure-lsp."
(interactive)
(let ((info (lsp-clojure-server-info-raw)))
(save-match-data
(when-let (port (and (string-match "\"port\":\\([0-9]+\\)" info)
(match-string 1 info)))
(cider-connect-clj `(:host "localhost"
:port ,port))))))
coc-settings.json
(:CocConfig
) clojure-lsp: {command: "~/path/to/clojure-lsp/clojure-lsp"}
, adjusting the past as necessary.:CocRestart
:echo CocRequest('clojure-lsp', 'clojure/serverInfo/raw')['port']
:echo CocRequest('clojure-lsp', 'clojure/serverInfo/raw')['log-path']
:Connect <port>
If you re-connect regulary, you may want to add something like this to your vimrc:
" Copies the log-path to your clipboard
nnoremap <silent> crsl :call setreg('*', CocRequest('clojure-lsp', 'clojure/serverInfo/raw')['log-path'])<CR>
" Connects to nrepl
nnoremap <silent> crsp :execute 'Connect' CocRequest('clojure-lsp', 'clojure/serverInfo/raw')['port']<CR>
TBD. PR welcome.
The nREPL includes tools for debugging and profiling clojure-lsp. See cli/dev/clojure_lsp/debug.clj
.
If you're interested in using the profiling tools in that file, you'll need to be familiar with criterium and clj-async-profiler.
Note that the performance of clojure-lsp is highly dependent on the size of its db. If you load a repl with -A:build
, you'll have access to the debugging tools, but the db will be nearly empty. Follow the [steps][#the-clojure-way] above to connect to an nREPL which has a populated db.
Can you improve this documentation? These fine people already did:
Jacob Maine, Eric Dallo, Peter Strömberg & Case NelsonEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close