aboutsummaryrefslogtreecommitdiff
path: root/runtime/doc/lsp.txt
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/doc/lsp.txt')
-rw-r--r--runtime/doc/lsp.txt59
1 files changed, 24 insertions, 35 deletions
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt
index c4322e9c24..4f2c457107 100644
--- a/runtime/doc/lsp.txt
+++ b/runtime/doc/lsp.txt
@@ -46,38 +46,40 @@ Follow these steps to get LSP features:
See |lsp-config|.
*lsp-config*
-
-Starting a LSP client will automatically report diagnostics via
-|vim.diagnostic|. Read |vim.diagnostic.config()| to learn how to customize the
-display.
-
-It also sets some buffer options if the language server supports the
-functionality and if the options are otherwise empty or have the default
-values set by Nvim runtime files (e.g. a ftplugin). In the latter case,
-the default values are not restored when the LSP client is detached from
-the buffer.
-
-- 'omnifunc' is set to |vim.lsp.omnifunc()|. This allows to trigger completion
- using |i_CTRL-X_CTRL-O|
+ *lsp-defaults*
+When the LSP client starts it enables diagnostics |vim.diagnostic| (see
+|vim.diagnostic.config()| to customize). It also sets various default options,
+listed below, if (1) the language server supports the functionality and (2)
+the options are empty or were set by the builtin runtime (ftplugin) files. The
+options are not restored when the LSP client is stopped or detached.
+
+- 'omnifunc' is set to |vim.lsp.omnifunc()|, use |i_CTRL-X_CTRL-O| to trigger
+ completion.
- '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.
+- 'formatexpr' is set to |vim.lsp.formatexpr()|, so you can format lines via
+ |gq| if the language server supports it.
+ - To opt out of this use |gw| instead of gq, or set 'formatexpr' on LspAttach.
-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
-ensure they're only active if there is a LSP client running. An example:
->lua
+ *lsp-defaults-disable*
+To override the above defaults, set or unset the options on |LspAttach|: >lua
+ vim.api.nvim_create_autocmd('LspAttach', {
+ callback = function(ev)
+ vim.bo[ev.buf].formatexpr = nil
+ vim.bo[ev.buf].omnifunc = nil
+ end,
+ })
+
+To use other LSP features like hover, rename, etc. you can set other keymaps
+on |LspAttach|. Example: >lua
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = args.buf })
end,
})
-<
-The most used functions are:
+The most common functions are:
- |vim.lsp.buf.hover()|
- |vim.lsp.buf.format()|
@@ -138,19 +140,6 @@ FAQ *lsp-faq*
" (async = false is the default for format)
autocmd BufWritePre *.rs lua vim.lsp.buf.format({ async = false })
<
-- Q: How can I disable LSP formatting when using the |gq| command?
- A: To use the default internal formatting method and bypass the LSP client's
- 'formatexpr', use |gw| instead.
- Alternatively you can completely disable LSP formatting with gq by
- unsetting 'formatexpr':
-
->lua
- vim.api.nvim_create_autocmd('LspAttach', {
- callback = function(args)
- vim.bo[args.buf].formatexpr = nil
- end,
- })
-<
*lsp-vs-treesitter*
- Q: How do LSP and Treesitter compare?
A: LSP requires a client and language server. The language server uses