- Notifications
You must be signed in to change notification settings - Fork43
Utility functions for getting diagnostic status and progress messages from LSP servers, for use in the Neovim statusline
License
nvim-lua/lsp-status.nvim
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is a Neovim plugin/library for generating statusline components from the built-in LSP client.
- 2021/03/13: Some users report success using the Google "Noto Emoji" font for
status_symbolandindicator_hint. - 2020/11/19: Please note that the default diagnostics symbols require Font Awesome or aNerdFont. You may also change the diagnostics symbols as shown in theconfiguration section.
- 2020/11/13: Due tothis PR, you must update tothe latest Neovim
masterto avoid errors with the old diagnostics API. Seeissue#19 for more information. - 2020/05/25: There has been a minor breaking change to the API:
extension_callbacksis nownamedextensions. There have also been a number of additions and improvements; see the below(specificallyConfiguration andExample Use) for details.
Show the current containing function (likeb:coc_current_function):
Easily access diagnostic counts:
Show progress messages from servers:
You will need a version of Neovim that includes the built-in LSP client (right now, that meansnightly). Use your preferred package/plugin manager. Withvim-packager, this looks like:
callpackager#add('nvim-lua/lsp-status.nvim')
The plugin provides several utilities:
update_current_function()-- Set/reset the b:lsp_current_function variable-- Shows the current function, method, class, struct, interface, enum, module, or namespacediagnostics()-- Return a table with all diagnostic counts for the current buffermessages()-- Return a table listing progress and other status messages for displayregister_progress()-- Register the provided handler for progress messagesregister_client()-- Register a client for messages-- Integrate misc. LS protocol extensions into the messages framework-- Each extension table contains a set of handlers and a setup() function-- returning said handlersextensions= {clangd,pyls_ms }-- Set up a client for use with lsp-status. Calls register_client() and sets up-- buffer autocommandson_attach(client)config(config_vals)-- Configure lsp-status-- Table of client capabilities extended to signal support for progress messagescapabilitiesstatus()-- One example out-of-the-box statusline component (as shown in the images above)
lsp-status.nvim supports messaging-related protocol extensions offered byclangd andMicrosoft's Python languageserver (python/setStatusBarMessage,python/beginProgress,python/reportProgress, andpython/endProgress). To use these extensions,register the handlers provided in theextensions table (the keys for the handlers arethe relevant LSP method name).
Note: Forclangd, you must also setinit_options = { clangdFileStatus = true }.
New: You can also calllsp_status.extensions.<server name>.setup() to return the full set ofhandlers, as shown below.
You can configurelsp-status.nvim using theconfig function, which takes a table ofconfiguration values. The following configuration options are supported:
kind_labels: An optional map from LSP symbol kinds to label symbols. Used to decorate the current functionname. Default:{}select_symbol: An optional handler of the formfunction(cursor_pos, document_symbol)thatshould returntrueifdocument_symbol(aDocumentSymbol) should be accepted as the symbolcurrently containing the cursor.
For example, thesumneko lua server sendsvalueRange (which is not specified in the protocol) to give the range for a function's start andend. To respectvalueRange, you can use the following configuration:
lsp_status.config {select_symbol=function(cursor_pos,symbol)ifsymbol.valueRangethenlocalvalue_range= { ["start"]= {character=0,line=vim.fn.byte2line(symbol.valueRange[1]) }, ["end"]= {character=0,line=vim.fn.byte2line(symbol.valueRange[2]) } }returnrequire("lsp-status.util").in_range(cursor_pos,value_range)endend}
current_function: Boolean,trueif the current function should be updated and displayed in thedefault statusline component.show_filename: Boolean,trueif the filename should be displayed in the progress text.indicator_*-group: strings to show as diagnostic warnings. If you don't have Nerd/Awesome Fonts you can replace defaults with ASCII chars like this:
-- Put this somewhere near lsp_status.register_progress() lsp_status.config({ indicator_errors = 'E', indicator_warnings = 'W', indicator_info = 'i', indicator_hint = '?', indicator_ok = 'Ok', })indicator_separator: a string which goes between each diagnostic group symbol and its count.Defaults to whitespace.component_separator: a string which goes between each "chunk" of the statusline component (i.e.different diagnostic groups, messages). Defaults to whitespace.diagnostics: Boolean,trueby default. Iffalse, the default statusline component does notdisplay LSP diagnostics.
Here is an example configuration (also usingnvim-lsp)showing howlsp-status can be integrated into one's statusline and other LSP configuration.
In any Lua file you load:
locallsp_status=require('lsp-status')-- completion_customize_lsp_label as used in completion-nvim-- Optional: customize the kind labels used in identifying the current function.-- g:completion_customize_lsp_label is a dict mapping from LSP symbol kind-- to the string you want to display as a label-- lsp_status.config { kind_labels = vim.g.completion_customize_lsp_label }-- Register the progress handlerlsp_status.register_progress()
Before callingsetup for each relevant LSP client:
-- Set default client capabilities plus window/workDoneProgressconfig.capabilities=vim.tbl_extend('keep',config.capabilitiesor {},lsp_status.capabilities)
In anon_attach function for each relevant LSP client:
-- Register client for messages and set up buffer autocommands to update-- the statusline and the current function.-- NOTE: on_attach is called with the client object, which is the "client" parameter belowlsp_status.on_attach(client)
Specific client configuration (followingnvim-lsp conventions):
clangd= {handlers=lsp_status.extensions.clangd.setup()},pyls_ms= {handlers=lsp_status.extensions.pyls_ms.setup()},
An example statusline segment is provided inlua/lsp-status/statusline. You are encouraged to read the sourceand develop your own statusline segment, but if you'd like something reasonable out-of-the-box, youcan calllsp_status.status() somewhere in your statusline definition (make sure you haverequire'd thelsp-status module too!)
Here's a complete example:
lua << ENDlocal lsp_status=require('lsp-status')lsp_status.register_progress()local lspconfig=require('lspconfig')-- Some arbitrary serverslspconfig.clangd.setup({ handlers= lsp_status.extensions.clangd.setup(), init_options= { clangdFileStatus= true }, on_attach= lsp_status.on_attach, capabilities= lsp_status.capabilities})lspconfig.pyls_ms.setup({ handlers= lsp_status.extensions.pyls_ms.setup(), settings= {python= { workspaceSymbols= { enabled= true }}}, on_attach= lsp_status.on_attach, capabilities= lsp_status.capabilities})lspconfig.ghcide.setup({ on_attach= lsp_status.on_attach, capabilities= lsp_status.capabilities})lspconfig.rust_analyzer.setup({ on_attach= lsp_status.on_attach, capabilities= lsp_status.capabilities})END" Statuslinefunction!LspStatus()abortifluaeval('#vim.lsp.buf_get_clients() > 0')returnluaeval("require('lsp-status').status()")endifreturn''endfunction
This plugin is "complete" - it works in all the ways it was originally intended to, and it doesn'tseem to break. That said, it hasn't been tested much, and I'm open to adding new features if otherswant them.
One thing that probably should be added is proper documentation of some sort. The code could alsostand to be cleaned up.
Bug reports and feature requests are welcome! PRs are doubly welcome!
About
Utility functions for getting diagnostic status and progress messages from LSP servers, for use in the Neovim statusline
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.