mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 10:45:16 -07:00
docs: provide example for configuring LSP foldexpr (#31411)
Using the "supports_method" function with a client capability inside of an LspAttach autocommand is the preferred method to do this, so we should be showing users how to do it.
This commit is contained in:
parent
c7ec010ade
commit
49d6cd1da8
@ -720,6 +720,19 @@ 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
|
||||||
|
|LspAttach| autocommand. Example: >lua
|
||||||
|
vim.api.nvim_create_autocommand('LspAttach', {
|
||||||
|
callback = function(args)
|
||||||
|
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||||
|
if client:supports_method('textDocument/foldingRange') then
|
||||||
|
vim.wo.foldmethod = 'expr'
|
||||||
|
vim.wo.foldexpr = 'v:lua.vim.lsp.foldexpr()'
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
<
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {lnum} (`integer`) line number
|
• {lnum} (`integer`) line number
|
||||||
|
|
||||||
|
@ -1097,6 +1097,22 @@ function lsp.tagfunc(pattern, flags)
|
|||||||
end
|
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
|
||||||
|
--- |LspAttach| autocommand. Example:
|
||||||
|
---
|
||||||
|
--- ```lua
|
||||||
|
--- vim.api.nvim_create_autocommand('LspAttach', {
|
||||||
|
--- callback = function(args)
|
||||||
|
--- local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||||
|
--- if client:supports_method('textDocument/foldingRange') then
|
||||||
|
--- vim.wo.foldmethod = 'expr'
|
||||||
|
--- vim.wo.foldexpr = 'v:lua.vim.lsp.foldexpr()'
|
||||||
|
--- end
|
||||||
|
--- end,
|
||||||
|
--- })
|
||||||
|
--- ```
|
||||||
|
---
|
||||||
---@param lnum integer line number
|
---@param lnum integer line number
|
||||||
function lsp.foldexpr(lnum)
|
function lsp.foldexpr(lnum)
|
||||||
return vim.lsp._folding_range.foldexpr(lnum)
|
return vim.lsp._folding_range.foldexpr(lnum)
|
||||||
|
Loading…
Reference in New Issue
Block a user