Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable treesiter highlight in menu per source #526

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,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 @@ -814,8 +816,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
Loading