Skip to content

Add blink_luasnip #378

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

Closed
wants to merge 3 commits into from
Closed

Add blink_luasnip #378

wants to merge 3 commits into from

Conversation

leiserfg
Copy link
Contributor

No description provided.

Co-authored-by: Austin Horstman <[email protected]>
Copy link
Owner

@Saghen Saghen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the wait, I'll give it a test on my system soon

opts = {
accept = {
expand_snippet = function(snippet) require('luasnip').lsp_expand(snippet) end,
},
sources = {
completion = {
-- WARN: add the rest of your providers here, unless you're using `opts_extend`
-- and defining this outside of your primary `blink.cmp` config
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be kept

@leiserfg
Copy link
Contributor Author

@Saghen it works fine in 0.6.2 but was somehow failing in master, let me know if I can help to debug.

@Saghen
Copy link
Owner

Saghen commented Dec 2, 2024

The accept logic was changed to first apply the item and then call source's execute function. where as before, it would hand off everything to the source @leiserfg. You might want to set insertText = "" and then expand the snippet. You could grab the text that was removed via context.line:sub(context.bounds.start_col, context.bounds.start_col + context.bounds.length - 1) (i.e. for TM_CURRENT_LINE)

@leiserfg
Copy link
Contributor Author

leiserfg commented Dec 2, 2024

Thanks @Saghen that was what I understood but was waiting for a stable release with the changes.

@leiserfg
Copy link
Contributor Author

leiserfg commented Dec 2, 2024

LuaSnip does more stuff with the current line and wants access to the range to clear it by itself. I was thinking to set insertText to the triggering word, so that LuaSnip will "see" the same. But that looks a bit dirty to me. I think it would be cleaner to have a way for asking blink.cmp not to edit the text.

Edit: My hack won't work event work as the items changing the text won't update the insertText.

Edit: Forget about it, it is indeed possible to feed luasnip with the line as you advised, thanks.

@Saghen
Copy link
Owner

Saghen commented Dec 2, 2024

It's messy but perhaps you could add back the text before calling luasnip? Using this snippet to get the text (not tested fyi, but should work):

context.line:sub(context.bounds.start_col, context.bounds.start_col + context.bounds.length - 1)

I'll revisit the execute function in the future so you don't have to hack around this

@leiserfg
Copy link
Contributor Author

leiserfg commented Dec 2, 2024

I managed to make it work following your previous suggestion, right now the only issue I see is that the snippet is expanded but it goes to "normal" mode instead of staying in "select" mode as it should.

@soifou
Copy link
Collaborator

soifou commented Dec 2, 2024

the only issue I see is that the snippet is expanded but it goes to "normal" mode instead of staying in "select" mode as it should.

I think you're missing the required insertTextFormat = vim.lsp.protocol.InsertTextFormat.Snippet, see here

@leiserfg
Copy link
Contributor Author

leiserfg commented Dec 2, 2024

If I pass insertTextFormat = vim.lsp.protocol.InsertTextFormat.Snippet then it crashes with

10.2/share/nvim/runtime/lua/vim/lsp/_snippet_grammar.lua:177: snippet parsing failed

@Saghen
Copy link
Owner

Saghen commented Dec 2, 2024

That's only if you want blink.cmp to expand the insertText as a snippet which you don't want

@leiserfg
Copy link
Contributor Author

leiserfg commented Dec 2, 2024

Yes but it's passing the inserText any way, I tried passing

inserText = " ",  -- an space
insertTextFormat = vim.lsp.protocol.InsertTextFormat.Snippet 

and that worked fine (kept the snippet in select mode), so I think I will use that as a workaround, but IMHO passing

inserText = "",  -- empty
insertTextFormat = vim.lsp.protocol.InsertTextFormat.Snippet 

should not break.

@Saghen
Copy link
Owner

Saghen commented Dec 2, 2024

You should be using vim.lsp.protocol.InsertTextFormat.PlainText with insertText = "". The source should switch the mode to select as part of the execute

@leiserfg
Copy link
Contributor Author

leiserfg commented Dec 2, 2024

In all the cases I'm using kind = vim.lsp.protocol.CompletionItemKind.Snippet, in case it matters

This keeps changing the mode to Normal

insertTextFormat = vim.lsp.protocol.InsertTextFormat.PlainText,
insertText = ""

This crashes because tries to parse the snippet

insertTextFormat = vim.lsp.protocol.InsertTextFormat.Snippet,
insertText = ""

This one works well but inserts the space:

insertTextFormat = vim.lsp.protocol.InsertTextFormat.Snippet,
insertText = " "

This one works well but to me is a HACK 😄 :

insertTextFormat = vim.lsp.protocol.InsertTextFormat.Snippet,
insertText = "$0"

@Saghen Saghen closed this in 08b59ed Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants