Skip to content

Commit

Permalink
feat: enable treesiter highlight in menu per source (#526)
Browse files Browse the repository at this point in the history
* feat: enable treesiter highlight in menu per source

Closes #438

* docs: recommended treesitter highlight configuration

---------

Co-authored-by: Liam Dyer <[email protected]>
  • Loading branch information
stefanboca and Saghen authored Dec 13, 2024
1 parent 240f439 commit f99b03c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,10 @@ 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 = {},
-- Recommended to enable it just for the LSP source
-- treesitter = { 'lsp' }

-- Components to render, grouped by column
columns = { { 'kind_icon' }, { 'label', 'label_description', gap = 1 } },
Expand Down Expand Up @@ -816,8 +818,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 @@ -59,7 +59,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 @@ -101,7 +101,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 @@ -189,7 +189,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 f99b03c

Please sign in to comment.