Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gagbo/consult-lsp

LSP-mode and consult.el helping each other
https://github.com/gagbo/consult-lsp

Last synced: about 1 month ago
JSON representation

LSP-mode and consult.el helping each other

Awesome Lists containing this project

README

        

#+TITLE: Consult LSP-mode integration
#+AUTHOR: Gerry Agbobada
#+LANGUAGE: en

#+HTML: MELPA
#+HTML: 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 [[https://github.com/emacs-lsp/helm-lsp][helm-lsp]] and
[[https://github.com/emacs-lsp/lsp-ivy][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.

#+caption: consult-lsp-diagnostics
[[https://github.com/gagbo/consult-lsp/blob/screenshots/media/consult-lsp-diagnostics.png?raw=true]]

#+caption: consult-lsp-symbols
[[https://github.com/gagbo/consult-lsp/blob/screenshots/media/consult-lsp-symbols.png?raw=true]]

#+caption: consult-lsp-file-symbols
[[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 [[https://microsoft.github.io/language-server-protocol/specification.html#textDocument_documentSymbol][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:

#+begin_src emacs-lisp
(define-key lsp-mode-map [remap xref-find-apropos] #'consult-lsp-symbols)
#+end_src