From 35756022cbcd16ad72ec1f7cd1fea523da4aba1f Mon Sep 17 00:00:00 2001 From: Riley Bruins Date: Mon, 16 Jun 2025 13:05:00 -0700 Subject: [PATCH] fix(lsp): advertise supported fold kinds (#34461) This commit also makes it so that folds which have an unsupported fold kind have their `kind` ignored. --- runtime/lua/vim/lsp/_folding_range.lua | 18 +++++++++++++++--- runtime/lua/vim/lsp/protocol.lua | 3 +++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/runtime/lua/vim/lsp/_folding_range.lua b/runtime/lua/vim/lsp/_folding_range.lua index ac7f0e0b9f..365ea40008 100644 --- a/runtime/lua/vim/lsp/_folding_range.lua +++ b/runtime/lua/vim/lsp/_folding_range.lua @@ -3,6 +3,13 @@ local log = require('vim.lsp.log') local ms = require('vim.lsp.protocol').Methods local api = vim.api +---@type table +local supported_fold_kinds = { + ['comment'] = true, + ['imports'] = true, + ['region'] = true, +} + local M = {} ---@class (private) vim.lsp.folding_range.BufState @@ -49,9 +56,14 @@ local function renew(bufnr) local kind = range.kind if kind then - local kinds = row_kinds[start_row] or {} - kinds[kind] = true - row_kinds[start_row] = kinds + -- Ignore unsupported fold kinds. + if supported_fold_kinds[kind] then + local kinds = row_kinds[start_row] or {} + kinds[kind] = true + row_kinds[start_row] = kinds + else + log.info(('Received unsupported fold kind: "%s"'):format(kind)) + end end for row = start_row, end_row do diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua index d85f26c38c..d73c8c08bd 100644 --- a/runtime/lua/vim/lsp/protocol.lua +++ b/runtime/lua/vim/lsp/protocol.lua @@ -441,6 +441,9 @@ function protocol.make_client_capabilities() foldingRange = { dynamicRegistration = false, lineFoldingOnly = true, + foldingRangeKind = { + valueSet = { 'comment', 'imports', 'region' }, + }, foldingRange = { collapsedText = true, },