From 49d6cd1da86cab49c7a5a8c79e59d48d016975fa Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Mon, 2 Dec 2024 12:13:09 -0600 Subject: 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. --- runtime/doc/lsp.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'runtime/doc') diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt index f7157df0f2..e311831bd3 100644 --- a/runtime/doc/lsp.txt +++ b/runtime/doc/lsp.txt @@ -720,6 +720,19 @@ foldexpr({lnum}) *vim.lsp.foldexpr()* 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, + }) +< + Parameters: ~ • {lnum} (`integer`) line number -- cgit