My Authors
Read all threads
1/ clojure-lsp is the most important #Clojure dev tool you're not using. Here's why you owe it to yourself to give it a try if you're an #Emacs or #Vim user. Thread:

First, what is LSP (Language Server Protocol)?
2/ LSP is the name of a language-agnostic interface that lets editors provide IDE-like code navigation features like find-definition and find-references. A language server (like clojure-lsp) is a process that implements this interface for a target language.
3/ In a pluralistic world, LSP provides an escape from the NxM problem (the dreaded matrix of N editors and M languages).
4/ Because any editor that implements the protocol can launch a language server as a background process, the hard work of writing a parser for a target language only needs to be done once.

Does LSP depend on an active REPL, you ask?
5/ The answer, fortunately, is no. Using a REPL for tooling is clunky at best: it's hard to set up, slow to start, awkward for CLJS and unhappily couples the editor to the runtime env.
6/ The right approach to Clojure(Script) tooling, pioneered by Cursive, is also clojure-lsp's: static analysis.

With LSP enabled, your Emacs or Vim is more interactive because it now groks Clojure. Here are a few examples of what you can do.
7/ I'll talk about Emacs commands but the functionality exists in all supported editors.

`lsp-find-definition` (often mapped to ctrl-click) allows you do jump from a name to the corresponding defn (or def or ns).
8/ `lsp-find-references` takes the reverse route: starting from a definition, you can go through a list of places in the codebase where the var has been used.

If all you want is to view the docstring, try `lsp-describe-thing-at-point`.
9/ This command works with vars in your project as well as dependencies read from classpath jars.

Also if you move the cursor on top of a let binding, your editor will highlight all references within the body.
10/ The highlighter isn't string-based: it knows the language well enough to understand what's in scope and what isn't.

Can the static approach work if Clojure is a dynamic language? Yes! In fact Clojure(Script) lends itself well to static analysis - better than Python or Ruby.
11/ In a codebase with tens of thousands of LOC and many dependencies, navigation works well (although there is always room for improvement). Try it with your own project!
12/ Once you get over the initial speed bump (you may want to override source paths or ignore classpath in `.lsp/config.edn`), clojure-lsp works reliably today. And it's only going to get better as more and more people use it. github.com/snoe/clojure-l…
13/ PS, did I mention that clojure-lsp also supports IDE-like edits and refactorings like `lsp-rename` (rename functions or arguments) and `lsp-clojure-add-missing-libspec` (automatically add ns requires)?
Missing some Tweet in this thread? You can try to force a refresh.

Enjoying this thread?

Keep Current with Paulus Esterhazy

Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!