Replies: 6 comments 21 replies
-
Still struggling to make this happen. Based on this recipe I tried the following but I'm still seeing copilot and dynamic snippet options in the blink suggestions when I'm in a comment block in Ruby or Lua code:
I'm using LazyVim if that matters. Everything is up-to-date. My full configuration is here. |
Beta Was this translation helpful? Give feedback.
-
Interested too |
Beta Was this translation helpful? Give feedback.
-
I DO NOT HAVE THE ANSWER...
|
Beta Was this translation helpful? Give feedback.
-
Seems to work good for me simply checking the spot 1 space to the left of the cursor! auto_show = function (ctx)
local row, column = unpack(vim.api.nvim_win_get_cursor(0))
local success, node = pcall(vim.treesitter.get_node, {
pos = { row - 1, math.max(0, column - 1) },
ignore_injections = false
})
local reject = { "comment", "line_comment", "block_comment", "string_start", "string_content", "string_end" }
if success and node and vim.tbl_contains(reject, node:type()) then
return false;
end
-- whatever other logic you want beyond this
return true
end, I've only tested this fully in Zig |
Beta Was this translation helpful? Give feedback.
-
I was migrating from AstroNvim v4 to v5 which, among other things, has replaced nvim-cmp with blink.nvim. With every other customization due to a replaced plugin that I had to reimplement, I'd never have imagined this would be the thing to do me in. Despite various suggestions in this discussion, the only thing that actually worked for me was ripping the logic out of nvim-cmp and using that. nvim-cmp can also handle non-treesitter cases, but for my purposes I was fine with requiring TS. -- Lifted from https://github.com/hrsh7th/nvim-cmp/blob/v0.0.2/lua/cmp/config/context.lua
function in_treesitter_capture(capture)
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
if vim.api.nvim_get_mode().mode == 'i' then
col = col - 1
end
local buf = vim.api.nvim_get_current_buf()
local get_captures_at_pos = require('vim.treesitter').get_captures_at_pos
local captures_at_cursor = vim.tbl_map(function(x)
return x.capture
end, get_captures_at_pos(buf, row - 1, col))
if vim.tbl_isempty(captures_at_cursor) then
return false
elseif type(capture) == 'string' and vim.tbl_contains(captures_at_cursor, capture) then
return true
elseif type(capture) == 'table' then
for _, v in ipairs(capture) do
if vim.tbl_contains(captures_at_cursor, v) then
return true
end
end
end
return false
end
return {
"Saghen/blink.cmp",
opts = {
completion = {
menu = {
auto_show = function()
return not in_treesitter_capture("comment") and not require("luasnip").expand_or_jumpable()
end
}
}
},
} |
Beta Was this translation helpful? Give feedback.
-
This is what I'm using in Neovim 0.11.2 to enable git commit & emoji cmp with blink in comments. This surely is a bit off-topic, but maybe it might provide some help. I basically took the code from @DeidaraMC and added the {buffer} property: function is_in_string_like_node()
if vim.bo.buftype == "prompt" then
return false
elseif vim.tbl_contains({ 'gitcommit', 'markdown' }, vim.bo.filetype) then
return true
end
local row, column = unpack(vim.api.nvim_win_get_cursor(0))
local success, node = pcall(vim.treesitter.get_node, {
bufnr = 0,
pos = { row - 1, math.max(0, column - 1) } -- seems to be necessary...
})
-- `string_fragment` is a node type reported in react files, so I've added it
local reject = { "comment", "line_comment", "block_comment", "string_start", "string_fragment", "string_content", "string_end" }
return (success and node and vim.tbl_contains(reject, node:type()))
end I'm using this function reference in the table path |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I used to do this in
nvim-cmp
with some function logic on theenable
option like this:I'm trying to recreate this for blink but I can't seem to detect a comment. I've got this so far:
The:
doesn't seem to work correctly. And
enabled
doesn't seem to fire for every treesitter context change.Is there a way to do this?
I'm using blink via LazyVim if that makes a difference.
Beta Was this translation helpful? Give feedback.
All reactions