/consult-lsp

LSP-mode and consult.el helping each other

Primary LanguageEmacs LispMIT LicenseMIT

Consult LSP-mode integration

MELPA MELPA Stable

Introduction

Helm and Ivy users have extra commands that leverage lsp-mode extra information, let’s try to mimic a few features of helm-lsp and lsp-ivy in consult workflow (tested with selectrum and dogfed with vertico)

Screenshots

They tend not to be updated as often as changes happen, sorry if there are slight differences in UI. Those shots are more about giving an idea of what’s happening.

https://github.com/gagbo/consult-lsp/blob/screenshots/media/consult-lsp-diagnostics.png?raw=true

https://github.com/gagbo/consult-lsp/blob/screenshots/media/consult-lsp-symbols.png?raw=true

https://github.com/gagbo/consult-lsp/blob/screenshots/media/consult-lsp-file-symbols.png?raw=true

Commands

consult-lsp-diagnostics
Select diagnostics from current workspace. Pass prefix argument to search all workspaces
consult-lsp-symbols
Select symbols from current workspace. Pass prefix argument to search all workspaces.
consult-lsp-file-symbols
Interactively select a symbol from the current file, in a manner similar to consult-line.

There is currently no plan to add an interface to list and/or act on code-actions, but contributions are welcome!

Configuration

Customize Look and Feel

This package provides 2 entry points per command in order to customize the appearance of candidates in the selection/completion interface. This is mostly for advanced users who are somewhat familiar with consult API:

*-transformer-function
Adapter function, responsible for transforming lsp data into a valid consult candidate. a valid “consult candidate” is more often than not a propertized string, with specific properties to enable extra features.
*-annotate-builder-function
Builder function, which returns a valid lambda for annotation/affixation support. This allows to add extra information to the candidates in the interface. The returned lambda must take 1 argument and produce either a single string or a list of 3 elements (candidate prefix suffix), just as expected by either annotation-function or affixation-function

You are encouraged to take a look at the default values if you wish to customize these, especially the `file-symbols` one, which is probably the easiest ones to grok, and use marginalia.

Keys

Categories for symbols

consult-lsp-symbols and consult-lsp-file-symbols can have the set of “narrow” keys you like by customizing consult-lsp-symbols-narrow.

The cdrs of the alist must match the symbol types returned by LSP servers, AND have an “Other” key for everything that is not included.

You can find categories by looking for the SymbolKind enum in the LSP specification.

Bindings

As you can do with helm-lsp,

Use the following line to replace xref-find-apropos in lsp-mode controlled buffers:

(define-key lsp-mode-map [remap xref-find-apropos] #'consult-lsp-symbols)