Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions todotreeview-xl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ config.plugins.todotreeview = common.merge({
-- Tells if the plugin should start with the nodes expanded
todo_expanded = true,

-- Ignore all files which are not part of the git repository
todo_only_files_from_git_repository = true,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se default value to false


-- 'tag' mode can be used to group the todos by tags
-- 'file' mode can be used to group the todos by files
-- 'file_tag' mode can be used to group the todos by files and then by tags inside the files
Expand Down Expand Up @@ -63,6 +66,13 @@ config.plugins.todotreeview = common.merge({
type = "list_strings",
default = {"TODO", "BUG", "FIX", "FIXME", "IMPROVEMENT"},
},
{
label = "Only files from git repository",
description = "Ignore all files which are not commited to the current git repository.",
path = "todo_only_files_from_git_repository",
type = "toggle",
default = true,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very specific behaviour for your use case, set the default to false.

},
{
label = "Paths to ignore",
description = "Paths to be ignored when parsing the tags.",
Expand Down Expand Up @@ -171,6 +181,33 @@ function TodoTreeView:is_file_in_scope(filename)
end
end

-- run command and return stdout
-- taken from plugins/gitopen.lua
local function exec(cmd)
local proc = process.start(cmd)
while proc:running() do
coroutine.yield(0.1)
end
if proc:returncode() > 0 then
core.error("ERROR - command: " .. table.concat(cmd, " "))
end
return proc:read_stdout() or ""
end

-- get list of all files in git repo
function TodoTreeView.get_all_files_in_git_repo()
-- local git_root = exec({"git", "rev-parse", "--show-toplevel"}):match( "^%s*(.-)%s*$" )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clear commented code

local file_list_str = exec({"git", "ls-tree", "--name-only", "--full-tree", "-r", "HEAD"})

local git_files = {}
for relative_path_from_project_root in string.gmatch(file_list_str, "([^\n]+)") do
-- git_files[git_root .. PATHSEP .. relative_path_from_project_root] = true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clear commented code

git_files[relative_path_from_project_root] = true
end

return git_files
end

function TodoTreeView.get_all_files()
local all_files = {}
for _, file in ipairs(core.project_files) do
Expand All @@ -197,8 +234,28 @@ function TodoTreeView:refresh_cache()
self.updating_cache = true

core.add_thread(function()
-- if user decides to ignore all files not commited to git repository,
-- then prepare a list of files checked in to git repository
local files_in_git_repository = {}
if config.plugins.todotreeview.todo_only_files_from_git_repository then
files_in_git_repository = self.get_all_files_in_git_repo()
end

-- iterate over all files in project folder
for _, item in pairs(self.get_all_files()) do
-- check against list of explicitly ignored files
local ignored = is_file_ignored(item.filename)

-- when requested, check if file has been commited to git repository
if not ignored
and config.plugins.todotreeview.todo_only_files_from_git_repository
then
-- ignore file if it is not commited to git
if not files_in_git_repository[item.filename] then
ignored = true
end
end

if not ignored and item.type == "file" then
local cached = self:get_cached(item)

Expand Down