Skip to content

Features#

Above you can find all available features that clojure-lsp provides with examples using Emacs lsp-mode as the client.

Find a function/var definition#

Find all references of a function, var, keyword or namespace alias#

Show all workspace/project symbols#

Show all symbols on current file#

Rename symbols#

Also, it's possible to live rename symbols on the same buffer with linkedEditingRange feature.

Document highlight on hover showing symbol usages#

Documentation and clojuredocs integration#

Completion#

Snippets#

Snippets are templates that make it easier to enter repeating code patterns, such as common functions/forms, they are available during completion. Tabstops are defined as $number with $0 as last tabstop.

Check all available snippets here
name description raw content
comment Create comment block (comment\n $0\n )
condp Create condp (condp ${1:pred} ${2:expr}\n $0)
def Create def (def ${1:name} $0)
defmethod Create defmethod (defmethod ${1:name} ${2:match}\n [${3:args}]\n $0)
defmulti Create defmulti (defmulti ${1:name} ${2:dispatch-fn})
defn- Create private function (defn%s ${1:name} [$2]\n $0)
defn Create public function (defn ${1:foo} [$2]\n $0)
defprotocol Create defprotocol (defprotocol ${1:Name}\n $0)
defrecord Create defrecord (defrecord ${1:Name} [${2:fields}]\n ${3:Protocol}\n $0)
deftype Create deftype (deftype ${1:Name} [${2:fields}]\n ${3:Protocol}\n $0)
fn Create fn (fn [${1:arg-list}] $0)
if Create if (if ${1:test-expr}\n ${2:then-expr}\n ${3:else-expr})
import Create import (:import [${1:package}])
kwargs Create keyword args {:keys [${1:keys}] :or {${2:defaults}}}
let Create let (let [$0])
letfn Create letfn (letfn [(${1:name} [${2:args}]\n $0)])
ns Create ns (ns $1\n $0)
require Create require (:require [${1:namespace} :as [$0]])
use Create use (:use [${1:namespace} :only [$0]])
Custom snippets#

User can register additional custom snippets, for more information on how to configure it, check the snippets settings section.

Code actions#

Name Example
Clean namespace require/imports
Add require
Add known common require
Add known common import
Add suggested alias require
Create private function
Resolve macro as...
Inline symbol
Change coll to map,vector,set,list
Move coll entry up/down
Move to let
Cycle privacy
Extract function
Thread first/all last
Unwind thread
Sort map
Suppress diagnostic
Create test for function

Code lenses showing symbol references#

Format a whole file or range#

Signature help#

Semantic tokens#

The LSP server is the best to say what is the semantic value of a token on the editor, semantic tokens allows server return to client all tokens of a buffer and how client show apply highlight.

Note: server return the semantic token (e.g. function) and the client/editor apply the color that matches the user's theme.

Call hierarchy#

Show the incoming or outgoing call hierarchy of a function/variable as a lazy tree

Incoming#

Show functions that call the current one recursively

Outgoing#

Show functions that the current one call, recursively

Test Tree#

Show the tests tree hierarchy of a file

Diagnostics (linter)#

All linters besides the ones below come from clj-kondo that clojure-lsp calls under the hood to lint the code and retrieve the analysis to make most of features work.

Every linter configuration should be done on clj-kondo side, so anything related to unresolved symbols or unknown macros are probably related to wrong clj-kondo for the project. For more information on how to configure clj-kondo check here.

Below you can find the custom linters implemented on clojure-lsp side that uses the :custom-lint-fn from clj-kondo:

clojure-lsp/unused-public-var#

For more information on how to configure it, check the diagnostics settings section.

Stub generation#

It's possible to configure clojure-lsp to generate and analyze stubs for specific namespaces available on your project classpath, this is useful for closed source dependencies like datomic.api, with that clojure-lsp will be able to make most features work with those dependencies. For more information check the stubs settings section.

Execute command#

Commands that client can request. Most code actions use these commands as actions.

Resolve macro as *#

This code action should be wrapped by the LSP client to provide the missing arguments beside the existing return by the code action:

  • The macro which should resolve as e.g. clojure.core/def
  • The clj-kondo configuration to save the new setting. e.g /home/user/.clj-kondo/config.edn

For an example, check how Emacs LSP client handles that.

* Available via code actions too

Refactoring#

Commands that change/refactor the code.

Note: Most of them are available via code actions and most of the time you want to call the code action and not the command manually

  • Clean namespace *
  • Add import to namespace
  • Add missing require *
  • Cycle privacy of def/defn
  • Cycle collection (#{}, {}, [], ())
  • Change collection to {}, (), #{}, []
  • Extract Function *
  • Create private function *
  • Inline Symbol *
  • Expand let
  • Introduce let
  • Move expression to let
  • Thread first expression
  • Thread last expression
  • Thread first all *
  • Thread last all *
  • Unwind all
  • Unwind thread
  • Create test
  • Sort map
  • Move coll entry up
  • Move coll entry down

Dev#

Server information#

Return basic information about the server.

Cursor information#

Return debug information about the element at point.


Last update: January 16, 2022