supermaven-inc / supermaven-nvim

The official Neovim plugin for Supermaven
https://supermaven.com/
MIT License
304 stars 16 forks source link

Cannot accept suggestion in LazyVim #10

Open flupke opened 1 month ago

flupke commented 1 month ago

Configured like this:

# lua/plugins/supermaven.lua
return {
  "supermaven-inc/supermaven-nvim",
  config = function()
    require("supermaven-nvim").setup({
      keymaps = {
        accept_suggestion = "<Tab>",
        clear_suggestion = "<C-]>",
      },
    })
  end,
}
  1. I see suggestions inline in the editor, something like copilot-cmp would be nicer
  2. Hitting tab does not insert the suggestion
  3. The plugin does not load if I dont't include the config = key, which is not necessary for other plugins in general
dpetka2001 commented 1 month ago

I have it configured like following and it works nice for initial testing.

  {
    "supermaven-inc/supermaven-nvim",
    opts = {
      keymaps = {
        accept_suggestion = "<A-f>",
        clear_suggestion = "<A-c>",
      },
    },
  },

I also tried #7 locally and the problem with the cursor when accepting multiple lines is gone.

One thing I would like to ask is if it supports cycling through available suggestions. Or does it only make one suggestion at any time based on what it perceives the context is?

dpetka2001 commented 1 month ago

I did not use codeium.nvim. I used codeium.vim and after that also started testing neocodeium.nvim for a brief time. supermaven does indeed seems more performant and multi-line suggestions work without any glitch from the little testing that I did. For the foreseeable future I'll just keep both codeium.vim and supermaven testing in different configurations, until I find more points of what I like/dislike and also want to see if supermaven adds some kind of cycling through suggestions. It's still early to make a final decision.

Redoxahmii commented 1 month ago

Would be better with cmp support and cycling suggestions but hopefully that keeps the performance at the same level.

dpetka2001 commented 1 month ago

I believe this could be closed. It works as intended in LazyVim. I think it must be a keymap problem from the side of OP. LazyVim uses <Tab> by default for Luasnip moving to next/previous nodes, so either he has to disable that in his personal configuration or just assign a different keymap for supermaven.

It works correctly with the code snippet of my previous comment for my personal usage.

flupke commented 1 month ago

I don't have anything manually configured on <Tab> so I'm not sure the problem is on "my" side :)

Maybe the solution is to add cmp support, or to add a supermaven extra in LazyVim, or just a note for LazyVim users in the README, or something else :shrug:

Yet I would not close this as of now, because the plugin seemed broken to me until I read your comment.

Redoxahmii commented 1 month ago

I don't have anything manually configured on <Tab> so I'm not sure the problem is on "my" side :)

Maybe the solution is to add cmp support, or to add a supermaven extra in LazyVim, or just a note for LazyVim users in the README, or something else 🤷

Yet I would not close this as of now, because the plugin seemed broken to me until I read your comment.

It's not their duty to look for every configuration file and test that it works with every one of them. I am using LazyVim too and this is not really an obligation of the plugin to figure out someones whole configurations. That is indeed an issue on 'your' side. I do agree with the cmp support as that would make it far more better experience but this is a plugin in beta. And extras for LazyVim are done by their own maintainers so should ask them to resolve this.

dpetka2001 commented 1 month ago

Neither supermaven nor LazyVim is responsible for this.

I don't have anything manually configured on so I'm not sure the problem is on "my" side :)

I just told you in my previous comment that <Tab> is by default used for Luasnip in LazyVim. So, either you have to unmap that key in your personal configuration or use another keymap to accept suggestions, like I did in the code snippet that I provided (because I use Luasnip snippets and I like the default <Tab> for jumping between nodes).

Yet I would not close this as of now, because the plugin seemed broken to me until I read your comment.

If you copy/paste the code snippet from my first comment, it will not be broken.

On another note, I personally prefer the style with inline ghost text instead of it being a cmp source. That's the reason why I didn't use codeium.nvim but preferred codeium.vim instead, so I really hope the maintainers of this plugin keep it the way it is right now. The only suggestion I would make, is to provide a way to cycle through different suggestions, but I don't know if supermaven even provides such a feature or maybe it's only provided in the paid plan. It looks really a lot more performant compared to codeium.nvim, codeium.vim and neocodeium.nvim that I've tested so far. The only comparison I can't make is copilot itself because I've never used it.

Redoxahmii commented 1 month ago

@dpetka2001 Can you provide your configuration because for me i am not using LuaSnips tab key for accepting but instead have it what comes default with LazyVim using <CR> Enter to accept the suggestions. Currently deleting the keymap using :

vim.keymap.del("i", "<Tab>", { noremap = true, silent = true })

I deleted it still but when in insert mode i cannot use Tab to accept the suggestions from supermaven.

{
    "supermaven-inc/supermaven-nvim",
    opts = {
      keymaps = {
        accept_suggestion = "<Tab>",
        clear_suggestion = "<A-c>",
      },
    },
  }

This is how supermaven is setup.

Thanks for help.

EDIT: It is far more performant then Copilot i have used copilot for a long time.

dpetka2001 commented 1 month ago

<Tab> is used for Luasnip snippets. Probably you're confusing it with nvim-cmp <CR> which is for accepting suggestions from nvim-cmp. You can use <tab> with following configuration

  {
    "supermaven-inc/supermaven-nvim",
    opts = {
      keymaps = {
        accept_suggestion = "<tab>",
        clear_suggestion = "<A-c>",
        accept_word = "<A-w>",
      },
    },
  },
  {
    "L3MON4D3/LuaSnip",
    keys = {
      { "<tab>", false, mode = { "i", "s" } },
      { "<s-tab>", false, mode = { "i", "s" } },
    },
  },

PS: This way you won't be able to jump forth and back between Luasnip nodes. If that's something you won't be using in your workflow, that's fine. Otherwise I would suggest to at least remap these keys to something else if you want to keep the Luasnip functionality.

Redoxahmii commented 1 month ago

I have never used Tab for anything as the snippets appear as cmp source which now i understand that i am passing the cmp_luasnip to the table. This is a far better option to use tab for completions and the rest with cmp. Thanks for the info.

hmnd commented 1 month ago

I was using the Supertab recipe from LazyVim and have been able to integrate Supermaven into it as seen below. However, I can't figure out how to make on_accept_suggestion accept the suggestion instead of word-by-word. Any suggestions would be much appreciated!

return {
  {
    "L3MON4D3/LuaSnip",
    keys = function()
      return {}
    end,
  },
  {
    "hrsh7th/nvim-cmp",
    ---@param opts cmp.ConfigSchema
    opts = function(_, opts)
      local has_words_before = function()
        unpack = unpack or table.unpack
        local line, col = unpack(vim.api.nvim_win_get_cursor(0))
        return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
      end

      local luasnip = require("luasnip")
      local cmp = require("cmp")

      opts.mapping = vim.tbl_extend("force", opts.mapping, {
        ["<Tab>"] = cmp.mapping(function(fallback)
          local supermaven_preview = require("supermaven-nvim.completion_preview")

          if supermaven_preview.inlay_instance ~= nil then
            -- TOOD: figure out how to accept entire completion instead of only one word at a time
            supermaven_preview:on_accept_suggestion()
          elseif luasnip.expand_or_jumpable() then
            luasnip.expand_or_jump()
          elseif has_words_before() then
            cmp.complete()
          else
            fallback()
          end
        end, { "i", "s" }),
        ["<S-Tab>"] = cmp.mapping(function(fallback)
          if luasnip.jumpable(-1) then
            luasnip.jump(-1)
          else
            fallback()
          end
        end, { "i", "s" }),
      })
    end,
  },
}
kaiiserni commented 1 month ago

Since the last PR you can use it as a cmp source straight away (that’s how I use it now):


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

...

-- cmp.lua
cmp.setup {
  ...
  sources = {
    { name = "supermaven" },
  }
  ...
}

Or use it similar to @hmnd which would come down to something like this:

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() — (this should accept the complete suggestion btw)
  else
    fallback()
  end
end 
Redoxahmii commented 1 month ago

@kaiiserni I would actually prefer using it with only using tab for completion. It was previously working using the snippet provided above by @dpetka2001 but after the update to 0.10 it has stopped working again. Any help will be appreciated. And yes i am on LazyVim and i have luasnip extra enabled.

kaiiserni commented 1 month ago

@kaiiserni I would actually prefer using it with only using tab for completion. It was previously working using the snippet provided above by @dpetka2001 but after the update to 0.10 it has stopped working again. Any help will be appreciated. And yes i am on LazyVim and i have luasnip extra enabled.

I have upgraded to 0.10 as well and just tried the default Supermaven config to confirm, and everything (including tab) just works. At first glance, what @dpetka2001 suggested should still work in your case, but I’m not familiar with lazyvim and the like. It could be that other keymaps are conflicting, which you can quickly check with :imap.

Redoxahmii commented 1 month ago

Thank you for the suggestion @kaiiserni now the key was being inhibited by nvim-cmp so disabling it from their has made it work. And i am also baffled why do i not know :imap when using a prebuilt config.

thadkrugman commented 1 month ago

I am also having this issue. I am using Lazyvim and i have tried all of the suggested fixes with no luck. I can see the suggestions but i can not accept them with tab. I managed to disable inline hints and add Supermaven as a source to cmp but I don't like that setup and want to keep them separated.

thadkrugman commented 1 month ago

Thank you for the suggestion @kaiiserni now the key was being inhibited by nvim-cmp so disabling it from their has made it work. And i am also baffled why do i not know :imap when using a prebuilt config.

Can you show me what you did to get it working?

Redoxahmii commented 1 month ago

@thadkrugman have you updated to the latest versions of nvim as in 0.10 and also of LazyVim ? I am asking because the methods are different for both. And also if you are using either native-snippets or the Extra for LuaSnip.

thadkrugman commented 1 month ago

@thadkrugman have you updated to the latest versions of nvim as in 0.10 and also of LazyVim ? I am asking because the methods are different for both. And also if you are using either native-snippets or the Extra for LuaSnip.

I have the latest version of nvim. I don't know which version of LazyVim I have. I thought it kept itself updated when I run lazy update. I have whatever snippets that came with it and I currently have LuaSnip enabled to see if that fixed anything but it didn't work with or without it.

Redoxahmii commented 1 month ago

@thadkrugman If you are using lazy updates then you're already on the latest for LazyVim as well. I am currently using with LuaSnip Extra as the Native snippets were very slow for me .

return {
  {
    "L3MON4D3/LuaSnip",
    keys = {
      { "<tab>", false, mode = { "i", "s" } },
      { "<s-tab>", false, mode = { "i", "s" } },
    },
  },
  {
    "hrsh7th/nvim-cmp",
    keys = {
      { "<tab>", false, mode = { "i", "s" } },
      { "<s-tab>", false, mode = { "i", "s" } },
    },
  },
}
thadkrugman commented 1 month ago

@Redoxahmii That worked! Thank you very much!

jsonMartin commented 1 month ago

I also was struggling getting Tab to autocomplete also with LazyVim. I don't have LuaSnip enabled, so looks like nvim-cmp was the culprit as it's automatically enabled inside of LazyVim and was gobbling up the tab keystroke.

{
    "hrsh7th/nvim-cmp",
    keys = {
      { "<tab>", false, mode = { "i", "s" } },
      { "<s-tab>", false, mode = { "i", "s" } },
    },
  },

Did the trick for me. Thanks for the fix @Redoxahmii !

Redoxahmii commented 1 month ago

My pleasure

shovel-kun commented 4 days ago

Even with no keybindings set (at least, that's what :imap <Tab> tells me), I am still unable to accept suggestions from Supermaven. It instead indents, though perhaps this isn't necessarily a Supermaven issue. I have to map to other keybindings instead.

For reference, I'm on Lazyvim v12, and Neovim 0.10.

Redoxahmii commented 3 days ago

@thadkrugman If you are using lazy updates then you're already on the latest for LazyVim as well. I am currently using with LuaSnip Extra as the Native snippets were very slow for me .

  • For both nvim-cmp and LuaSnip you will have to disable <tab> and <s-tab> like this :
return {
  {
    "L3MON4D3/LuaSnip",
    keys = {
      { "<tab>", false, mode = { "i", "s" } },
      { "<s-tab>", false, mode = { "i", "s" } },
    },
  },
  {
    "hrsh7th/nvim-cmp",
    keys = {
      { "<tab>", false, mode = { "i", "s" } },
      { "<s-tab>", false, mode = { "i", "s" } },
    },
  },
}

@shovel-kun i am still using this same method and on the latest version of LazyVim for Supermaven this is the config i have currently for supermaven:

return {
  "supermaven-inc/supermaven-nvim",
  opts = {
    keymaps = {
      accept_suggestion = "<tab>",
      clear_suggestion = "<A-c>",
      accept_word = "<A-w>",
    },
    log_level = "off",
  },
}

If this is still not working for you then the issue might be some other plugin for you.