stevearc / overseer.nvim

A task runner and job management plugin for Neovim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bug: templates without condition field will always match, even if tags don't match

tobias-haenel opened this issue · comments

Neovim version (nvim -v)

0.9.4

Operating system/version

ArchLinux (Linux 6.6.8)

Describe the bug

Trying to run templates with a matching set of tags, will also display templates without condition fields, even if their tags don't overlap with the searched tags.

What is the severity of this bug?

tolerable (can work around it)

Steps To Reproduce

  1. register several task templates without a condition field and with different tags (e.g. tags = {"a"} / {"b"}) with
require("overseer").register_template
  1. Run
require("overseer").run_template{tags={"a"}, first=false)
  1. Check the returned templates

Expected Behavior

A template should only be displayed for selection when its tags overlap with the searched tags.

Minimal example file

No response

Minimal init.lua

No response

Additional context

Proposed fix: remove line 62 to 64 in condition_matches and default initialise condition with an empty table or default initialise all template condition fields with an empty table

local function condition_matches(condition, tags, search, match_tags)
if not condition then
return true
end
if condition.filetype then
local search_fts = vim.split(search.filetype, ".", { plain = true })
local any_ft_match = false
for _, ft in util.iter_as_list(condition.filetype) do
if vim.tbl_contains(search_fts, ft) then
any_ft_match = true
break
end
end
if not any_ft_match then
return false, string.format("Does not match filetype %s", vim.inspect(condition.filetype))
end
end
local dir = condition.dir
if dir then
if type(dir) == "string" then
if not files.is_subpath(dir, search.dir) then
return false, string.format("Not in dir %s", condition.dir)
end
elseif
not util.list_any(dir, function(d)
return files.is_subpath(d, search.dir)
end)
then
return false, string.format("Not in dirs %s", table.concat(dir, ", "))
end
end
if match_tags and search.tags and not vim.tbl_isempty(search.tags) then
if not tags then
return false, string.format("Doesn't have tags %s", vim.inspect(search.tags))
end
local tag_map = util.list_to_map(tags)
for _, v in ipairs(search.tags) do
if not tag_map[v] then
return false, string.format("Doesn't have tags %s", vim.inspect(search.tags))
end
end
end
if condition.callback then
local passed, message = condition.callback(search)
if not passed then
return false, message
end
end
return true
end

Should be fixed!