diff --git a/README.md b/README.md index 3cda2f17..061a4f1a 100644 --- a/README.md +++ b/README.md @@ -506,6 +506,9 @@ MiniDeps.add({ auto_show = false, auto_show_delay_ms = 500, update_delay_ms = 50, + -- whether to use treesitter highlighting for the documentation window, disable if you run into performance issues + -- WARN: temporary, eventually blink will support regex highlighting + treesitter_highlighting = true, }, signature_help = { min_width = 1, @@ -520,6 +523,9 @@ MiniDeps.add({ -- which directions to show the window, -- falling back to the next direction when there's not enough space direction_priority = { 'n', 's' }, + -- whether to use treesitter highlighting for the documentation window, disable if you run into performance issues + -- WARN: temporary, eventually blink will support regex highlighting + treesitter_highlighting = true, }, ghost_text = { enabled = false, diff --git a/lua/blink/cmp/config.lua b/lua/blink/cmp/config.lua index 24e0576b..88284a82 100644 --- a/lua/blink/cmp/config.lua +++ b/lua/blink/cmp/config.lua @@ -152,6 +152,7 @@ --- @field auto_show? boolean --- @field auto_show_delay_ms? number Delay before showing the documentation window --- @field update_delay_ms? number Delay before updating the documentation window +--- @field treesitter_highlighting? boolean Whether to use treesitter highlighting for the documentation window, disable if you run into performance issues --- @class blink.cmp.SignatureHelpConfig --- @field min_width? number @@ -162,6 +163,7 @@ --- @field winhighlight? string --- @field scrollbar? boolean --- @field direction_priority? ("n" | "s")[] +--- @field treesitter_highlighting? boolean Whether to use treesitter highlighting for the documentation window, disable if you run into performance issues --- @class GhostTextConfig --- @field enabled? boolean @@ -493,6 +495,9 @@ local config = { auto_show = false, auto_show_delay_ms = 500, update_delay_ms = 50, + -- whether to use treesitter highlighting for the documentation window, disable if you run into performance issues + -- WARN: temporary, eventually blink will support regex highlighting + treesitter_highlighting = true, }, signature_help = { min_width = 1, @@ -507,6 +512,9 @@ local config = { -- which directions to show the window, -- falling back to the next direction when there's not enough space direction_priority = { 'n', 's' }, + -- whether to use treesitter highlighting for the documentation window, disable if you run into performance issues + -- WARN: temporary, eventually blink will support regex highlighting + treesitter_highlighting = true, }, ghost_text = { enabled = false, diff --git a/lua/blink/cmp/windows/documentation.lua b/lua/blink/cmp/windows/documentation.lua index a17c656c..a0e82ada 100644 --- a/lua/blink/cmp/windows/documentation.lua +++ b/lua/blink/cmp/windows/documentation.lua @@ -62,7 +62,8 @@ function docs.show_item(item) docs.win:get_buf(), item.detail, item.documentation, - docs.win.config.max_width + docs.win.config.max_width, + config.treesitter_highlighting ) end docs.shown_item = item diff --git a/lua/blink/cmp/windows/lib/docs.lua b/lua/blink/cmp/windows/lib/docs.lua index 7eedc2ca..318ac4ba 100644 --- a/lua/blink/cmp/windows/lib/docs.lua +++ b/lua/blink/cmp/windows/lib/docs.lua @@ -3,7 +3,9 @@ local docs = {} --- @param bufnr number --- @param detail? string --- @param documentation? lsp.MarkupContent | string -function docs.render_detail_and_documentation(bufnr, detail, documentation, max_width) +--- @param max_width number +--- @param use_treesitter_highlighting boolean +function docs.render_detail_and_documentation(bufnr, detail, documentation, max_width, use_treesitter_highlighting) local detail_lines = {} if detail and detail ~= '' then detail_lines = docs.split_lines(detail) end @@ -30,7 +32,7 @@ function docs.render_detail_and_documentation(bufnr, detail, documentation, max_ -- Highlight with treesitter vim.api.nvim_buf_clear_namespace(bufnr, require('blink.cmp.config').highlight.ns, 0, -1) - if #detail_lines > 0 then docs.highlight_with_treesitter(bufnr, vim.bo.filetype, 0, #detail_lines) end + if #detail_lines > 0 and use_treesitter_highlighting then docs.highlight_with_treesitter(bufnr, vim.bo.filetype, 0, #detail_lines) end -- Only add the separator if there are documentation lines (otherwise only display the detail) if #detail_lines > 0 and #doc_lines > 0 then @@ -42,7 +44,7 @@ function docs.render_detail_and_documentation(bufnr, detail, documentation, max_ }) end - if #doc_lines > 0 then + if #doc_lines > 0 and use_treesitter_highlighting then local start = #detail_lines + (#detail_lines > 0 and 1 or 0) docs.highlight_with_treesitter(bufnr, 'markdown', start, start + #doc_lines) end diff --git a/lua/blink/cmp/windows/signature.lua b/lua/blink/cmp/windows/signature.lua index 19b66228..f0d200dc 100644 --- a/lua/blink/cmp/windows/signature.lua +++ b/lua/blink/cmp/windows/signature.lua @@ -51,7 +51,8 @@ function signature.open_with_signature_help(context, signature_help) signature.win:get_buf(), active_signature.label, active_signature.documentation, - config.max_width + config.max_width, + config.treesitter_highlighting ) end signature.shown_signature = active_signature