aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/lsp.txt3
-rw-r--r--runtime/lua/vim/lsp.lua15
2 files changed, 16 insertions, 2 deletions
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt
index 48b3f6b4bb..94726ceaab 100644
--- 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
index b26ed0c759..7f3237bdd0 100644
--- 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