feat(lsp): highlight foldtext via treesitter #38789

Problem:
To support `collapsedText`, which allows the LSP server to determine the
content of the foldtext, we provided `vim.lsp.foldtext()`. However, such
content does not have highlighting.

Solution
Treat the filetype of `collapsedText` as the filetype of the corresponding
buffer and use tree-sitter to highlight it.
This commit is contained in:
Yi Ming
2026-04-15 22:27:44 +08:00
committed by GitHub
parent d0af4cd909
commit 1740d51ede
5 changed files with 145 additions and 9 deletions

View File

@@ -1506,8 +1506,11 @@ end
--- Provides a `foldtext` function that shows the `collapsedText` retrieved,
--- defaults to the first folded line if `collapsedText` is not provided.
function lsp.foldtext()
return vim.lsp._folding_range.foldtext()
---
--- The displayed foldtext will be highlighted via treesitter.
---@param lnum? integer line number (default: current fold start)
function lsp.foldtext(lnum)
return vim.lsp._folding_range.foldtext(lnum)
end
---@deprecated Use |vim.lsp.get_client_by_id()| instead.