supermaven-inc / supermaven-nvim

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

feat(#57): disable `supermaven-nvim` on condition #58

Open AlejandroSuero opened 3 weeks ago

AlejandroSuero commented 3 weeks ago

With these changes the user can stop supermaven conditionally for example, if the user wants files like bash_private.sh to not be running but want any other .sh files to have supermaven running it can do it with the following configuration.

require("supermaven-nvim").setup({
  condition = function()
    return string.match(vim.fn.expand(":t"), "_private.sh")
  end,
})

For this demo I used:

require("supermaven-nvim").setup({
  condition = function()
    return vim.fn.expand(":t:r") == "api"
  end,
})

https://github.com/supermaven-inc/supermaven-nvim/assets/71392160/a1efb698-8e5b-49a2-af39-d2b5887fc492

[!NOTE] It runs on lua files except in api.lua because the filename is api.

Closes #57.

ahmedelgabri commented 2 weeks ago

@AlejandroSuero sorry I was a bit busy. Just tried the changes here, for some reason it doesn't work for me.

Here is my how I'm testing it

{
    'https://github.com/AlejandroSuero/supermaven-nvim',
    branch = 'feature/conditional-running',
    config = function()
        require('supermaven-nvim').setup {
            keymaps = {
                accept_suggestion = '<C-g>',
                condition = function()
                    local match = vim.bo.filetype == 'starter'
                        or vim.fn.expand ':t:r' == 'init'
                    return match
                end,
            },
            disable_inline_completion = false, -- disables inline completion for use with cmp
            disable_keymaps = false, -- disables built in keymaps for more manual control
        }
    end,
},

You can here for example that although I have a check for the starter filetype it still ran (check the supermaven message at the bottom), same happens when opening any init.lua, the condition should prevent it from running but it's still running

https://github.com/supermaven-inc/supermaven-nvim/assets/63876/7a5de70e-4348-45b6-8b74-77e8226dd0c1

AlejandroSuero commented 2 weeks ago

@ahmedelgabri condition should be outside the keymaps entry, like:

require("supermaven-nvim").setup({
  keymaps = {
    - - ...
   },
  condition = function()
     return - - your condition
  end,
})

Try it out this way and if something fails, I'll check it out tomorrow, today I don't have the pc around.

ahmedelgabri commented 2 weeks ago

What a stupid mistake 🤦‍♂️ I will try again in the evening. Thanks @AlejandroSuero

AlejandroSuero commented 2 weeks ago

@ahmedelgabri no worries, I should have put an example with the other options in the PR description so it doesn't lead to confusion.

ahmedelgabri commented 2 weeks ago

@AlejandroSuero works great! 👍🏼