neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 68c674af0fbc4158690319aa6125a098a592412d
parent d31ee6664d3b8d37ac4bb95b3adad397e90a8da1
Author: Mathias Fußenegger <mfussenegger@users.noreply.github.com>
Date:   Mon,  8 Aug 2022 18:30:17 +0200

feat(lsp): set formatexpr by default (#19677)

Follow up to https://github.com/neovim/neovim/pull/19003
Diffstat:
Mruntime/doc/lsp.txt | 3+++
Mruntime/lua/vim/lsp.lua | 15+++++++++++++--
2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt @@ -59,6 +59,9 @@ language server supports the functionality. - |tagfunc| is set to |vim.lsp.tagfunc|. This enables features like go-to-definition, |:tjump|, and keymaps like |CTRL-]|, |CTRL-W_]|, |CTRL-W_}| to utilize the language server. +- |formatexpr| is set to |vim.lsp.formatexpr| if both |formatprg| and + |formatexpr| are empty. This allows to format lines via |gq| if the language + server supports it. To use other LSP features like hover, rename, etc. you can setup some additional keymaps. It's recommended to setup them in a |LspAttach| autocmd to diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua @@ -968,12 +968,20 @@ function lsp.start_client(config) ---@private local function set_defaults(client, bufnr) - if client.server_capabilities.definitionProvider and vim.bo[bufnr].tagfunc == '' then + local capabilities = client.server_capabilities + if capabilities.definitionProvider and vim.bo[bufnr].tagfunc == '' then vim.bo[bufnr].tagfunc = 'v:lua.vim.lsp.tagfunc' end - if client.server_capabilities.completionProvider and vim.bo[bufnr].omnifunc == '' then + if capabilities.completionProvider and vim.bo[bufnr].omnifunc == '' then vim.bo[bufnr].omnifunc = 'v:lua.vim.lsp.omnifunc' end + if + capabilities.documentRangeFormattingProvider + and vim.bo[bufnr].formatprg == '' + and vim.bo[bufnr].formatexpr == '' + then + vim.bo[bufnr].formatexpr = 'v:lua.vim.lsp.formatexpr()' + end end ---@private @@ -986,6 +994,9 @@ function lsp.start_client(config) if vim.bo[bufnr].omnifunc == 'v:lua.vim.lsp.omnifunc' then vim.bo[bufnr].omnifunc = nil end + if vim.bo[bufnr].formatexpr == 'v:lua.vim.lsp.formatexpr()' then + vim.bo[bufnr].formatexpr = nil + end end ---@private