Skip to content

Commit

Permalink
feat: enable treesiter hl in menu per source
Browse files Browse the repository at this point in the history
Closes #483
  • Loading branch information
stefanboca committed Dec 13, 2024
1 parent 54d1a98 commit 6f40d26
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ MiniDeps.add({
padding = 1,
-- Gap between columns
gap = 1,
-- Use treesitter to highlight the label text
treesitter = false,
-- Use treesitter to highlight the label text of completions from these sources
treesitter = {},

-- Components to render, grouped by column
columns = { { 'kind_icon' }, { 'label', 'label_description', gap = 1 } },
Expand Down Expand Up @@ -814,8 +814,8 @@ completion.menu.draw = {
padding = 1,
-- Gap between columns
gap = 1,
-- Use treesitter to highlight the label text
treesitter = false,
-- Use treesitter to highlight the label text of completions from these sources
treesitter = {},

-- Components to render, grouped by column
columns = { { 'kind_icon' }, { 'label', 'label_description', gap = 1 } },
Expand Down
2 changes: 1 addition & 1 deletion lua/blink/cmp/completion/windows/render/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
--- @field gap? number Gap between columns
--- @field columns? { [number]: string, gap?: number }[] Components to render, grouped by column
--- @field components? table<string, blink.cmp.DrawComponent> Component definitions
--- @field treesitter? boolean Use treesitter to highlight the label text
--- @field treesitter? string[] Use treesitter to highlight the label text of completions from these sources
---
--- @class blink.cmp.DrawHighlight
--- @field [number] number Start and end index of the highlight
Expand Down
6 changes: 3 additions & 3 deletions lua/blink/cmp/config/completion/menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ local window = {
padding = 1,
-- Gap between columns
gap = 1,
treesitter = false, -- Use treesitter to highlight the label text
treesitter = {}, -- Use treesitter to highlight the label text of completions from these sources
-- Components to render, grouped by column
columns = { { 'kind_icon' }, { 'label', 'label_description', gap = 1 } },
-- Definitions for possible components to render. Each component defines:
Expand Down Expand Up @@ -100,7 +100,7 @@ local window = {
table.insert(highlights, { #label, #label + #ctx.label_detail, group = 'BlinkCmpLabelDetail' })
end

if ctx.self.treesitter then
if vim.list_contains(ctx.self.treesitter, ctx.source_id) then
-- add treesitter highlights
vim.list_extend(highlights, require('blink.cmp.completion.windows.render.treesitter').highlight(ctx))
end
Expand Down Expand Up @@ -188,7 +188,7 @@ function window.validate(config)
},
gap = { config.draw.gap, 'number' },

treesitter = { config.draw.treesitter, 'boolean' },
treesitter = { config.draw.treesitter, 'table' },

columns = {
config.draw.columns,
Expand Down

0 comments on commit 6f40d26

Please sign in to comment.