Skip to content

Commit

Permalink
fix: ignore snippets that only contain text
Browse files Browse the repository at this point in the history
Closes #624
  • Loading branch information
Saghen committed Dec 18, 2024
1 parent ea12c51 commit 284dd37
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lua/blink/cmp/completion/accept/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,24 @@ local function accept(ctx, item, callback)
if
ctx.mode == 'default'
and item.insertTextFormat ~= vim.lsp.protocol.InsertTextFormat.Snippet
and item.kind ~= require('blink.cmp.types').CompletionItemKind.Snippet

This comment has been minimized.

Copy link
@soifou

soifou Dec 18, 2024

Contributor

Why the removal of this line? This break luasnip expanding in select mode

This comment has been minimized.

Copy link
@Saghen

Saghen Dec 18, 2024

Author Owner

I'm not able to reproduce this on luasnip v2.* or main

This comment has been minimized.

Copy link
@soifou

soifou Dec 18, 2024

Contributor

Same ver, it seems this goes to normal only when the snippet use a text placeholder in the first tabstop. For instance, try with the following lua snippet:

s("fmt", fmta('("<>"):format(<>)<>', { i(1, "text"), i(2), i(0) })),

This comment has been minimized.

Copy link
@Saghen

Saghen Dec 18, 2024

Author Owner

Thanks! added it back

and require('blink.cmp.config').completion.accept.create_undo_point
then
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<C-g>u', true, true, true), 'n', true)
end

-- Ignore snippets that only contain text
if item.insertTextFormat == vim.lsp.protocol.InsertTextFormat.Snippet then
local parsed_snippet = require('blink.cmp.sources.snippets.utils').safe_parse(item.textEdit.newText)
if
parsed_snippet ~= nil
and #parsed_snippet.data.children == 1
and parsed_snippet.data.children[1].type == vim.lsp._snippet_grammar.NodeType.Text
then
vim.notify('Snippet only contains text, ignoring', vim.log.levels.WARN)
item.insertTextFormat = vim.lsp.protocol.InsertTextFormat.PlainText
end
end

-- Add brackets to the text edit if needed
local brackets_status, text_edit_with_brackets, offset = brackets_lib.add_brackets(ctx, vim.bo.filetype, item)
item.textEdit = text_edit_with_brackets
Expand Down

0 comments on commit 284dd37

Please sign in to comment.