Programmatically accept suggestion #15

Closed
opened 2024-05-13 12:09:01 -04:00 by sQVe · 4 comments
sQVe commented 2024-05-13 12:09:01 -04:00 (Migrated from github.com)

Hey,

I would love to be able to interact with this plugin via Lua code. This is super useful when configuring AI suggestions together with LSP completion.

This is how I set up accepting both Luasnip snippets and GitHub Copilot under the save key via nvim-cmp:

M.expand = function(fallback)
  local luasnip = require('luasnip')
  local suggestion = require('copilot.suggestion')

  if luasnip.expandable() then
    luasnip.expand()
  elseif suggestion.is_visible() then
    suggestion.accept()
  else
    fallback()
  end
end

Cheers!

Hey, I would love to be able to interact with this plugin via Lua code. This is super useful when configuring AI suggestions together with LSP completion. This is how I set up accepting both Luasnip snippets and [GitHub Copilot ](https://github.com/zbirenbaum/copilot.lua) under the save key via [`nvim-cmp`](https://github.com/hrsh7th/nvim-cmp): ```lua M.expand = function(fallback) local luasnip = require('luasnip') local suggestion = require('copilot.suggestion') if luasnip.expandable() then luasnip.expand() elseif suggestion.is_visible() then suggestion.accept() else fallback() end end ``` Cheers!
hboon commented 2024-05-13 21:22:39 -04:00 (Migrated from github.com)

Second this. Just mapping to a function like this, but falling back to <Tab> worked for me yesterday, but it no longer works.

Second this. Just mapping <Tab> to a function like this, but falling back to `<Tab>` worked for me yesterday, but it no longer works.
kaiiserni commented 2024-05-19 19:13:32 -04:00 (Migrated from github.com)

As of the last PR, something like this should work btw:

require("supermaven-nvim").setup({
  disable_keymaps = true
})

...

M.expand = function(fallback)
  local luasnip = require('luasnip')
  local suggestion = require('supermaven-nvim.completion_preview')

  if luasnip.expandable() then
    luasnip.expand()
  elseif suggestion.has_suggestion() then
    suggestion.on_accept_suggestion()
  else
    fallback()
  end
end 
As of the last PR, something like this should work btw: ```lua require("supermaven-nvim").setup({ disable_keymaps = true }) ... M.expand = function(fallback) local luasnip = require('luasnip') local suggestion = require('supermaven-nvim.completion_preview') if luasnip.expandable() then luasnip.expand() elseif suggestion.has_suggestion() then suggestion.on_accept_suggestion() else fallback() end end ```
hboon commented 2024-05-19 22:02:36 -04:00 (Migrated from github.com)

Just in case this saves someone's time in the future, there is also expand_or_jumpable() and expand_or_jump().

Just in case this saves someone's time in the future, there is also `expand_or_jumpable()` and `expand_or_jump()`.
sQVe commented 2024-05-20 02:42:33 -04:00 (Migrated from github.com)
Closing issue since https://github.com/supermaven-inc/supermaven-nvim/issues/15#issuecomment-2119390970 provides a solution.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
supermaven-inc/supermaven-nvim#15
No description provided.