Skip to content

Commit

Permalink
feat: option to disable treesitter highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
Saghen committed Nov 15, 2024
1 parent 8ba2069 commit 1c14f8e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions lua/blink/cmp/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion lua/blink/cmp/windows/documentation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions lua/blink/cmp/windows/lib/docs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lua/blink/cmp/windows/signature.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1c14f8e

Please sign in to comment.