diff --git a/lua/gentags/configs.lua b/lua/gentags/configs.lua index 63144f8..ef1313a 100644 --- a/lua/gentags/configs.lua +++ b/lua/gentags/configs.lua @@ -1,3 +1,6 @@ +local tbl = require("gentags.commons.tbl") +local str = require("gentags.commons.str") + local M = {} --- @alias gentags.Options table @@ -8,65 +11,65 @@ local Defaults = { -- ctags options ctags = { - ["--tag-relative=never"] = true, + "--tag-relative=never", -- Recommended Options: -- -- exclude logs - -- ["--exclude=*.log"] = true, + -- "--exclude=*.log", -- -- -- exclude vcs - -- ["--exclude=*.git"] = true, - -- ["--exclude=*.svg"] = true, - -- ["--exclude=*.hg"] = true, + -- "--exclude=*.git", + -- "--exclude=*.svg", + -- "--exclude=*.hg", -- -- -- exclude nodejs - -- ["--exclude=node_modules"] = true, + -- "--exclude=node_modules", -- -- -- exclude tags/cscope - -- ["--exclude=*tags*"] = true, - -- ["--exclude=*cscope.*"] = true, + -- "--exclude=*tags*", + -- "--exclude=*cscope.*", -- -- -- exclude python - -- ["--exclude=*.pyc"] = true, + -- "--exclude=*.pyc", -- -- -- exclude jvm class - -- ["--exclude=*.class"] = true, + -- "--exclude=*.class", -- -- -- exclude VS project generated - -- ["--exclude=*.pdb"] = true, - -- ["--exclude=*.sln"] = true, - -- ["--exclude=*.csproj"] = true, - -- ["--exclude=*.csproj.user"] = true, + -- "--exclude=*.pdb", + -- "--exclude=*.sln", + -- "--exclude=*.csproj", + -- "--exclude=*.csproj.user", -- -- -- exclude blobs - -- ["--exclude=*.exe"] = true, - -- ["--exclude=*.dll"] = true, - -- ["--exclude=*.mp3"] = true, - -- ["--exclude=*.ogg"] = true, - -- ["--exclude=*.flac"] = true, - -- ["--exclude=*.swp"] = true, - -- ["--exclude=*.swo"] = true, - -- ["--exclude=*.bmp"] = true, - -- ["--exclude=*.gif"] = true, - -- ["--exclude=*.ico"] = true, - -- ["--exclude=*.jpg"] = true, - -- ["--exclude=*.png"] = true, - -- ["--exclude=*.rar"] = true, - -- ["--exclude=*.zip"] = true, - -- ["--exclude=*.tar"] = true, - -- ["--exclude=*.tar.gz"] = true, - -- ["--exclude=*.tar.xz"] = true, - -- ["--exclude=*.tar.bz2"] = true, - -- ["--exclude=*.pdf"] = true, - -- ["--exclude=*.doc"] = true, - -- ["--exclude=*.docx"] = true, - -- ["--exclude=*.ppt"] = true, - -- ["--exclude=*.pptx"] = true, + -- "--exclude=*.exe", + -- "--exclude=*.dll", + -- "--exclude=*.mp3", + -- "--exclude=*.ogg", + -- "--exclude=*.flac", + -- "--exclude=*.swp", + -- "--exclude=*.swo", + -- "--exclude=*.bmp", + -- "--exclude=*.gif", + -- "--exclude=*.ico", + -- "--exclude=*.jpg", + -- "--exclude=*.png", + -- "--exclude=*.rar", + -- "--exclude=*.zip", + -- "--exclude=*.tar", + -- "--exclude=*.tar.gz", + -- "--exclude=*.tar.xz", + -- "--exclude=*.tar.bz2", + -- "--exclude=*.pdf", + -- "--exclude=*.doc", + -- "--exclude=*.docx", + -- "--exclude=*.ppt", + -- "--exclude=*.pptx", }, -- workspace detection - workspace = { [".git"] = true, [".svn"] = true, [".hg"] = true }, + workspace = { ".git", ".svn", ".hg" }, -- excluded workspace disabled_workspaces = {}, @@ -76,8 +79,8 @@ local Defaults = { -- Recommended Options: - -- ["neo-tree"] = true, - -- ["NvimTree"] = true, + -- "neo-tree", + -- "NvimTree", }, -- excluded filenames @@ -135,7 +138,26 @@ end --- @param opts gentags.Options? --- @return gentags.Options M.setup = function(opts) + local user_ctags = tbl.tbl_get(opts, "ctags") or {} + local ctags_opts = vim.deepcopy(Defaults.ctags) + for _, o in ipairs(user_ctags) do + if str.not_empty(o) then + table.insert(ctags_opts, o) + end + end + + local user_workspace = tbl.tbl_get(opts, "workspace") or {} + local workspace_opts = vim.deepcopy(Defaults.workspace) + for _, o in ipairs(user_workspace) do + if str.not_empty(o) then + table.insert(workspace_opts, o) + end + end + Configs = vim.tbl_deep_extend("force", vim.deepcopy(Defaults), opts or {}) + Configs.ctags = ctags_opts + Configs.workspace = workspace_opts + return Configs end diff --git a/lua/gentags/ctags.lua b/lua/gentags/ctags.lua index c8a28eb..54ca143 100644 --- a/lua/gentags/ctags.lua +++ b/lua/gentags/ctags.lua @@ -123,13 +123,7 @@ M._write = function(ctx, on_exit) end local cfg = configs.get() - local opts_table = vim.deepcopy(tbl.tbl_get(cfg, "ctags") or {}) - local opts = {} - for o, v in ipairs(opts_table) do - if str.not_empty(o) and v then - table.insert(opts, o) - end - end + local opts = vim.deepcopy(tbl.tbl_get(cfg, "ctags") or {}) local cwd = nil if ctx.mode == "workspace" then @@ -231,13 +225,7 @@ M._append = function(ctx, on_exit) end local cfg = configs.get() - local opts_table = vim.deepcopy(tbl.tbl_get(cfg, "ctags") or {}) - local opts = {} - for o, v in pairs(opts_table) do - if str.not_empty(o) and v then - table.insert(opts, o) - end - end + local opts = vim.deepcopy(tbl.tbl_get(cfg, "ctags") or {}) -- append mode table.insert(opts, "--append=yes") diff --git a/lua/gentags/dispatcher.lua b/lua/gentags/dispatcher.lua index fa7b6ed..e8998e2 100644 --- a/lua/gentags/dispatcher.lua +++ b/lua/gentags/dispatcher.lua @@ -87,10 +87,10 @@ M.enabled = function() local filename = utils.get_filename() local filetype = utils.get_filetype() - if cfg.disabled_filetypes[filetype] then + if tbl.list_contains(cfg.disabled_filetypes, filetype) then return false end - if cfg.disabled_filenames[filename] then + if tbl.list_contains(cfg.disabled_filenames, filename) then return false end @@ -99,7 +99,7 @@ M.enabled = function() filedir = path.parent(filename) end local workspace = utils.get_workspace(filedir) - if cfg.disabled_workspaces[workspace] then + if tbl.list_contains(cfg.disabled_workspaces, workspace) then return false end diff --git a/lua/gentags/utils.lua b/lua/gentags/utils.lua index 5340922..98a84e0 100644 --- a/lua/gentags/utils.lua +++ b/lua/gentags/utils.lua @@ -15,27 +15,25 @@ M.get_workspace = function(cwd) cwd = cwd or vim.fn.getcwd() while true do -- logger:debug("|get_workspace| 0-cwd:%s", vim.inspect(cwd)) - for pattern, value in pairs(configs.get().workspace) do - if value then - local target = path.join(cwd, pattern) - -- logger:debug( - -- "|get_workspace| 1-cwd:%s, target:%s", - -- vim.inspect(cwd), - -- vim.inspect(target) - -- ) - target = - path.normalize(target, { double_backslash = true, expand = true }) - local stat_result, stat_err = uv.fs_stat(target) - -- logger:debug( - -- "|get_workspace| 2-cwd:%s, target:%s, stat result:%s, stat err:%s", - -- vim.inspect(cwd), - -- vim.inspect(target), - -- vim.inspect(stat_result), - -- vim.inspect(stat_err) - -- ) - if stat_result then - return cwd - end + for _, pattern in ipairs(configs.get().workspace) do + local target = path.join(cwd, pattern) + -- logger:debug( + -- "|get_workspace| 1-cwd:%s, target:%s", + -- vim.inspect(cwd), + -- vim.inspect(target) + -- ) + target = + path.normalize(target, { double_backslash = true, expand = true }) + local stat_result, stat_err = uv.fs_stat(target) + -- logger:debug( + -- "|get_workspace| 2-cwd:%s, target:%s, stat result:%s, stat err:%s", + -- vim.inspect(cwd), + -- vim.inspect(target), + -- vim.inspect(stat_result), + -- vim.inspect(stat_err) + -- ) + if stat_result then + return cwd end end local parent = path.parent(cwd)