mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 11:58:17 +00:00
docs(lsp): simplify example of enabling LSP folding
This commit is contained in:

committed by
Christian Clason

parent
f5714994bc
commit
1862d3210d
@@ -882,14 +882,23 @@ foldexpr({lnum}) *vim.lsp.foldexpr()*
|
|||||||
Provides an interface between the built-in client and a `foldexpr`
|
Provides an interface between the built-in client and a `foldexpr`
|
||||||
function.
|
function.
|
||||||
|
|
||||||
To use, check for the "textDocument/foldingRange" capability in an
|
To use, set 'foldmethod' to "expr" and set the value of 'foldexpr': >lua
|
||||||
|LspAttach| autocommand. Example: >lua
|
vim.o.foldmethod = 'expr'
|
||||||
|
vim.o.foldexpr = 'v:lua.vim.lsp.foldexpr()'
|
||||||
|
<
|
||||||
|
|
||||||
|
Or use it only when supported by checking for the
|
||||||
|
"textDocument/foldingRange" capability in an |LspAttach| autocommand.
|
||||||
|
Example: >lua
|
||||||
|
vim.o.foldmethod = 'expr'
|
||||||
|
-- Default to treesitter folding
|
||||||
|
vim.o.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
|
||||||
|
-- Prefer LSP folding if client supports it
|
||||||
vim.api.nvim_create_autocmd('LspAttach', {
|
vim.api.nvim_create_autocmd('LspAttach', {
|
||||||
callback = function(args)
|
callback = function(args)
|
||||||
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||||
if client:supports_method('textDocument/foldingRange') then
|
if client:supports_method('textDocument/foldingRange') then
|
||||||
local win = vim.api.nvim_get_current_win()
|
local win = vim.api.nvim_get_current_win()
|
||||||
vim.wo[win][0].foldmethod = 'expr'
|
|
||||||
vim.wo[win][0].foldexpr = 'v:lua.vim.lsp.foldexpr()'
|
vim.wo[win][0].foldexpr = 'v:lua.vim.lsp.foldexpr()'
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
@@ -1365,16 +1365,26 @@ end
|
|||||||
|
|
||||||
--- Provides an interface between the built-in client and a `foldexpr` function.
|
--- Provides an interface between the built-in client and a `foldexpr` function.
|
||||||
---
|
---
|
||||||
--- To use, check for the "textDocument/foldingRange" capability in an
|
--- To use, set 'foldmethod' to "expr" and set the value of 'foldexpr':
|
||||||
--- |LspAttach| autocommand. Example:
|
|
||||||
---
|
---
|
||||||
--- ```lua
|
--- ```lua
|
||||||
|
--- vim.o.foldmethod = 'expr'
|
||||||
|
--- vim.o.foldexpr = 'v:lua.vim.lsp.foldexpr()'
|
||||||
|
--- ```
|
||||||
|
---
|
||||||
|
--- Or use it only when supported by checking for the "textDocument/foldingRange"
|
||||||
|
--- capability in an |LspAttach| autocommand. Example:
|
||||||
|
---
|
||||||
|
--- ```lua
|
||||||
|
--- vim.o.foldmethod = 'expr'
|
||||||
|
--- -- Default to treesitter folding
|
||||||
|
--- vim.o.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
|
||||||
|
--- -- Prefer LSP folding if client supports it
|
||||||
--- vim.api.nvim_create_autocmd('LspAttach', {
|
--- vim.api.nvim_create_autocmd('LspAttach', {
|
||||||
--- callback = function(args)
|
--- callback = function(args)
|
||||||
--- local client = vim.lsp.get_client_by_id(args.data.client_id)
|
--- local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||||
--- if client:supports_method('textDocument/foldingRange') then
|
--- if client:supports_method('textDocument/foldingRange') then
|
||||||
--- local win = vim.api.nvim_get_current_win()
|
--- local win = vim.api.nvim_get_current_win()
|
||||||
--- vim.wo[win][0].foldmethod = 'expr'
|
|
||||||
--- vim.wo[win][0].foldexpr = 'v:lua.vim.lsp.foldexpr()'
|
--- vim.wo[win][0].foldexpr = 'v:lua.vim.lsp.foldexpr()'
|
||||||
--- end
|
--- end
|
||||||
--- end,
|
--- end,
|
||||||
|
Reference in New Issue
Block a user