@@ -91,47 +91,30 @@ function M.info(bufnr)
9191 require (" astrocore" ).notify (table.concat (lines , " \n " ), vim .log .levels .INFO , { title = " AstroNvim Folding" })
9292end
9393
94- -- TODO: remove helper function when dropping support for Neovim v0.10
95-
96- --- @param client vim.lsp.Client
97- --- @param method string
98- --- @param bufnr ? integer
99- local function supports_method (client , method , bufnr )
100- if vim .fn .has " nvim-0.11" == 1 then
101- return client :supports_method (method , bufnr )
102- else
103- --- @diagnostic disable-next-line : param-type-mismatch
104- return client .supports_method (method , { bufnr = bufnr })
105- end
106- end
107-
10894function M .setup ()
10995 vim .api .nvim_create_user_command (" AstroFoldInfo" , function () M .info () end , { desc = " Display folding information" })
110- -- TODO: remove check when dropping support for Neovim v0.10
111- if vim .lsp .foldexpr then
112- local augroup = vim .api .nvim_create_augroup (" astroui_foldexpr" , { clear = true })
113- vim .api .nvim_create_autocmd (" LspAttach" , {
114- desc = " Monitor attached LSP clients with fold providers" ,
115- group = augroup ,
116- callback = function (args )
117- local client = assert (vim .lsp .get_client_by_id (args .data .client_id ))
118- if supports_method (client , " textDocument/foldingRange" , args .buf ) then lsp_bufs [args .buf ] = true end
119- end ,
120- })
121- vim .api .nvim_create_autocmd (" LspDetach" , {
122- group = augroup ,
123- desc = " Safely remove LSP folding providers when language servers detach" ,
124- callback = function (args )
125- if not vim .api .nvim_buf_is_valid (args .buf ) then return end
126- for _ , client in pairs (vim .lsp .get_clients { bufnr = args .buf }) do
127- if client .id ~= args .data .client_id and supports_method (client , " textDocument/foldingRange" , args .buf ) then
128- return
129- end
96+ local augroup = vim .api .nvim_create_augroup (" astroui_foldexpr" , { clear = true })
97+ vim .api .nvim_create_autocmd (" LspAttach" , {
98+ desc = " Monitor attached LSP clients with fold providers" ,
99+ group = augroup ,
100+ callback = function (args )
101+ local client = assert (vim .lsp .get_client_by_id (args .data .client_id ))
102+ if client :supports_method (" textDocument/foldingRange" , args .buf ) then lsp_bufs [args .buf ] = true end
103+ end ,
104+ })
105+ vim .api .nvim_create_autocmd (" LspDetach" , {
106+ group = augroup ,
107+ desc = " Safely remove LSP folding providers when language servers detach" ,
108+ callback = function (args )
109+ if not vim .api .nvim_buf_is_valid (args .buf ) then return end
110+ for _ , client in pairs (vim .lsp .get_clients { bufnr = args .buf }) do
111+ if client .id ~= args .data .client_id and client :supports_method (" textDocument/foldingRange" , args .buf ) then
112+ return
130113 end
131- lsp_bufs [ args . buf ] = nil
132- end ,
133- })
134- end
114+ end
115+ lsp_bufs [ args . buf ] = nil
116+ end ,
117+ })
135118 is_setup = true
136119end
137120
0 commit comments