supermaven-inc / supermaven-nvim

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

[Suggestion] ignoring files (not filetypes) dynamically #57

Open ahmedelgabri opened 3 weeks ago

ahmedelgabri commented 3 weeks ago

ignore_filetypes currently is limited to filetypes, but in some cases, I want to disable the plugin from running on some specific files. For example, some shellscript files that contains some secrets, token, etc…

If I add bash = true in ignore_filetypes then this will disable it for all bash files. I don't want this. I want to be able to do something like this instead


function()
   return string.match(vim.fn.expand('%:t'), 'foo.sh') != nil
end
AlejandroSuero commented 3 weeks ago

I usually use _private or .private, so for me it would be useful as well, currently I am doing it in my nvim-config to not load selected plugins.

I think a good way to resolve this cases would be with something like none-ls.nvim in the utils file, this is useful with none-ls for example to not use luacheck if selene.toml is in the root. In supermaven's case checking for root wouldn't be necessary.

Creating a condition entry on the plugin's config like this (rough concept):

local files = {
  { ft = { "bash", "javascript", ... }, ignore = { "foo", "_private", ".private", ... },
  ...
}

require("supermaven-nvim").setup({
  -- condition would need to return a boolean
  condition = function(util)
    return util.file_matches(files)
  end,
})

---@class FilesToMatch
---@field ft string? | string[]?
---@field ignore string | string[]

---@param files FilesToMatch[]
---@return boolean
util.file_matches = function(files)
  -- check if `files.ft` is specified, if not just check filename with `files.match`
    -- check current filetype within or some of `files.ft`
      -- check current filename contains or some of `files.ignore`
end

[!NOTE] This could be more user friendly with more thought into it and some feedback.

ahmedelgabri commented 3 weeks ago

Looks good. But I'd personally start with just adding an option that takes a function that returns a Boolean without the utils. And leave the logic for the consumer. if later there is a demand for such utils you can add it.

AlejandroSuero commented 3 weeks ago

That is a great idea, a nice place to start. Thanks for the feedback.

AlejandroSuero commented 3 weeks ago

@ahmedelgabri I made this quick demo and added this to my config:

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

I am thinking if its better to default condition to false, and check if condition is true to stop. Right now its defaulting to true.

https://github.com/supermaven-inc/supermaven-nvim/assets/71392160/90931945-4fe4-4f10-ad50-802db97c7310

ahmedelgabri commented 3 weeks ago

I am thinking if its better to default condition to false, and check if condition is true to stop. Right now its defaulting to true.

Agree, the default should be false, true should mean disable the plugin.

AlejandroSuero commented 3 weeks ago

@ahmedelgabri I made the changes in the PR above if you want to try them out.