aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2024-10-06 13:53:29 -0500
committerGitHub <noreply@github.com>2024-10-06 11:53:29 -0700
commit5da2a171f72cb11f70cf5568d800a0d672b07548 (patch)
treeb906873fbb4fb8f52a53bf162cba76a0512d378a
parent6628741ada73bcf60dd1cb249178aa18e60dbebc (diff)
downloadrneovim-5da2a171f72cb11f70cf5568d800a0d672b07548.tar.gz
rneovim-5da2a171f72cb11f70cf5568d800a0d672b07548.tar.bz2
rneovim-5da2a171f72cb11f70cf5568d800a0d672b07548.zip
docs: LspAttach, LspDetach examples #30661
The current LspAttach example shows setting options which are already set by default. We should expect that users are going to copy-paste these examples, so we shouldn't use examples that are superfluous and unnecessary.
-rw-r--r--runtime/doc/lsp.txt33
1 files changed, 15 insertions, 18 deletions
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt
index 47d8e190d4..dc810c0214 100644
--- a/runtime/doc/lsp.txt
+++ b/runtime/doc/lsp.txt
@@ -87,8 +87,11 @@ To override or delete any of the above defaults, set or unset the options on
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
+ -- Unset 'formatexpr'
vim.bo[args.buf].formatexpr = nil
+ -- Unset 'omnifunc'
vim.bo[args.buf].omnifunc = nil
+ -- Unmap K
vim.keymap.del('n', 'K', { buffer = args.buf })
end,
})
@@ -119,6 +122,7 @@ server. Example: >lua
vim.lsp.buf.format({bufnr = args.buf, id = client.id})
end,
})
+ end
end,
})
<
@@ -523,32 +527,25 @@ EVENTS *lsp-events*
LspAttach *LspAttach*
After an LSP client attaches to a buffer. The |autocmd-pattern| is the
name of the buffer. When used from Lua, the client ID is passed to the
- callback in the "data" table. Example: >lua
-
- vim.api.nvim_create_autocmd("LspAttach", {
- callback = function(args)
- local bufnr = args.buf
- local client = vim.lsp.get_client_by_id(args.data.client_id)
- if client.supports_method("textDocument/completion") then
- vim.bo[bufnr].omnifunc = "v:lua.vim.lsp.omnifunc"
- end
- if client.supports_method("textDocument/definition") then
- vim.bo[bufnr].tagfunc = "v:lua.vim.lsp.tagfunc"
- end
- end,
- })
-<
+ callback in the "data" table. See |lsp-config| for an example.
LspDetach *LspDetach*
Just before an LSP client detaches from a buffer. The |autocmd-pattern|
is the name of the buffer. When used from Lua, the client ID is passed
to the callback in the "data" table. Example: >lua
- vim.api.nvim_create_autocmd("LspDetach", {
+ vim.api.nvim_create_autocmd('LspDetach', {
callback = function(args)
+ -- Get the detaching client
local client = vim.lsp.get_client_by_id(args.data.client_id)
- -- Do something with the client
- vim.cmd("setlocal tagfunc< omnifunc<")
+
+ -- Remove the autocommand to format the buffer on save, if it exists
+ if client.supports_method('textDocument/formatting') then
+ vim.api.nvim_clear_autocmds({
+ event = 'BufWritePre',
+ buffer = args.buf,
+ })
+ end
end,
})
<