Configure LSP and Ciderλ︎
The LSP Mode website provides examples of LSP features and there is a long list of LSP settings
Disable LSP for Clojure
Set the clojure layer variable
cider to disable LSP features and use CIDER for auto-completion and formatting of code.
Start with Minimal Features and add when useful
Practicalli recommends starting with a minimal LSP configuration to avoid conflict with features that are present in Cider. LSP features can be enabled when you find them valuable.
practicalli/spacemacs.d configuration for Spacemacs included a minimal configuration for Cider and Clojure-lsp. This configuration uses predominately CIDER features. Minimal LSP UI elements and features are added without distracting from the minimal Spacemacs experience.
SPC SPC all-the-icons-install-fonts command installs the required icons
Disable Live Linting toolsλ︎
clojure-lsp includes the latest clj-kondo binary which is used to generate the static analysis of the project code.
clojure-enable-linters 'clj-kondo from the
clojure layer variable in the Spacemacs configuration to avoid duplication of results.
Spacemacs Clojure layer configurationλ︎
practicalli/spacemacs.d configuration uses clojure-mode features for indenting and aligning forms as you type. Optomisations include using fipp to generate pretty print output and limiting the size of the repl buffer to keep Emacs responsive.
;; clojure-backend 'cider ;; use cider and disable lsp
;; clojure-enable-linters 'clj-kondo ;; clj-kondo included in lsp
cider-repl-display-help-banner nil ;; disable help banner
cider-pprint-fn 'fipp ;; fast pretty printing
clojure-indent-style 'align-arguments ;; vertically align forms
clojure-align-forms-automatically t ;; align form while typing
clojure-toplevel-inside-comment-form t ;; evaluate expressions in comment as top level
cider-result-overlay-position 'at-point ;; results shown right after expression
cider-overlays-use-font-lock t ;; use font face everywhere
cider-repl-buffer-size-limit 100 ;; limit lines shown in REPL buffer
SPC m = l aligns arguments in the current line or selected region. Automatic aligning of forms is not yet supported in LSP for Clojure.
LSP aligning forms not fully supported
Support for associative syntax alignment is an issue to add aligning forms to cljfmt, which is used by LSP for formatting.
Aggressive Indent Mode conflicts with LSP
Adding aggressive-indent-mode as a hoot to clojure-mode when Clojure LSP is configured to format and align code will cause a serious conflict, with each tool trying to change the alignment of the other tool, leading to very unpredictable events.
(add-hook 'clojure-mode-hook #'aggressive-indent-mode)
LSP layer variablesλ︎
lsp layer to
.spacemacs and include the following variables for an uncluttered LSP UI.
;; Formatting and indentation - use Cider instead
;; Set to nil to use CIDER features instead of LSP UI
lsp-enable-snippet t ;; to test again
;; symbol highlighting - `lsp-toggle-symbol-highlight` toggles highlighting
;; subtle highlighting for doom-gruvbox-light theme defined in dotspacemacs/user-config
;; Show lint error indicator in the mode line
;; lsp-modeline-diagnostics-scope :workspace
;; popup documentation boxes
;; lsp-ui-doc-enable nil ;; disable all doc popups
lsp-ui-doc-show-with-cursor nil ;; doc popup for cursor
;; lsp-ui-doc-show-with-mouse t ;; doc popup for mouse
;; lsp-ui-doc-delay 2 ;; delay in seconds for popup to display
lsp-ui-doc-include-signature t ;; include function signature
;; lsp-ui-doc-position 'at-point ;; positioning of doc popup: top bottom at-point
lsp-ui-doc-alignment 'window ;; relative location of doc popup: frame window
;; code actions and diagnostics text as right-hand side of buffer
;; lsp-ui-sideline-delay 500
;; lsp-ui-sideline-show-diagnostics nil
;; reference count for functions (assume their maybe other lenses in future)
;; Efficient use of space in treemacs-lsp display
;; Optimization for large files
Customising symbol highlightingλ︎
Symbol highlighting can be toggled using the command
lsp-toggle-symbol-highlighting and the startup state can be set using the lsp layer configuration variable
The face used for highlighting will vary by theme. Use the Emacs
customize command to configure the
lsp-syntax-highlight-read face or add the
theming layer to
.spacemacs and add a custom face to
dotspacemacs/user-init section of
In this example, the default orange background color is removed and the font weigh set to bold.