Skip to content

Commit

Permalink
fix(singlefile): fix single file mode ctags parameters (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
linrongbin16 committed Dec 28, 2023
1 parent 9578df3 commit d4d77a9
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lua/gentags/configs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local Defaults = {
tool = "ctags",

-- ctags options
ctags = { "--tag-relative=never" },
ctags = { "--tag-relative=never", "--exclude=*.log" },

-- workspace detection
workspace = { ".git", ".svn" },
Expand Down
20 changes: 10 additions & 10 deletions lua/gentags/ctags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ end
--- @param ctx gentags.Context
M.init = function(ctx)
local logger = logging.get("gentags") --[[@as commons.logging.Logger]]
logger:debug("|run| ctx:%s", vim.inspect(ctx))
logger:debug("|init| ctx:%s", vim.inspect(ctx))

-- no tags name
if strings.empty(ctx.tags_file) then
Expand All @@ -63,11 +63,11 @@ M.init = function(ctx)
local system_obj = nil

local function _on_stdout(line)
logger:debug("|run._on_stdout| line:%s", vim.inspect(line))
logger:debug("|init._on_stdout| line:%s", vim.inspect(line))
end

local function _on_stderr(line)
logger:debug("|run._on_stderr| line:%s", vim.inspect(line))
logger:debug("|init._on_stderr| line:%s", vim.inspect(line))
end

local function _close_file(fp)
Expand All @@ -78,7 +78,7 @@ M.init = function(ctx)

local function _on_exit(completed)
-- logger:debug(
-- "|run._on_exit| completed:%s, sysobj:%s, JOBS_MAP:%s",
-- "|init._on_exit| completed:%s, sysobj:%s, JOBS_MAP:%s",
-- vim.inspect(completed),
-- vim.inspect(sysobj),
-- vim.inspect(JOBS_MAP)
Expand Down Expand Up @@ -150,19 +150,19 @@ M.init = function(ctx)
assert(strings.not_empty(ctx.workspace))
cwd = ctx.workspace
table.insert(opts, "-R")
else
assert(ctx.mode == "file")
assert(strings.not_empty(ctx.filename))
table.insert(opts, "-L")
table.insert(opts, ctx.filename)
end

-- output tags file
table.insert(opts, "-f")
table.insert(opts, tmpfile)

if ctx.mode == "singlefile" then
assert(strings.not_empty(ctx.filename))
table.insert(opts, ctx.filename)
end

local cmds = { "ctags", unpack(opts) }
logger:debug("|run| cmds:%s", vim.inspect(cmds))
logger:debug("|init| ctx:%s, cmds:%s", vim.inspect(ctx), vim.inspect(cmds))

system_obj = spawn.run(cmds, {
cwd = cwd,
Expand Down
16 changes: 8 additions & 8 deletions lua/gentags/dispatcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local M = {}

-- A tool module has these APIs: load/init/update/terminate
--
--- @alias gentags.Context {workspace:string?,filename:string?,filetype:string?,tags_file:string?,tags_handle:string?,tags_pattern:string?,mode:"workspace"|"file"}
--- @alias gentags.Context {workspace:string?,filename:string?,filetype:string?,tags_file:string?,tags_handle:string?,tags_pattern:string?,mode:"workspace"|"singlefile"}
--- @alias gentags.LoadMethod fun(ctx:gentags.Context):nil
--- @alias gentags.InitMethod fun(ctx:gentags.Context):nil
--- @alias gentags.UpdateMethod fun(ctx:gentags.Context):nil
Expand All @@ -36,7 +36,7 @@ local function get_tool()
end

--- @return gentags.Context
local function get_context()
M.get_context = function()
local cfg = configs.get()
local logger = logging.get("gentags") --[[@as commons.logging.Logger]]

Expand All @@ -62,7 +62,7 @@ local function get_context()
tags_pattern = utils.get_tags_pattern(tags_handle --[[@as string]])
end

local mode = strings.not_empty(workspace) and "workspace" or "file"
local mode = strings.not_empty(workspace) and "workspace" or "singlefile"

return {
workspace = workspace,
Expand All @@ -77,28 +77,28 @@ end

M.load = function()
vim.schedule(function()
get_tool().load(get_context())
get_tool().load(M.get_context())
end)
end

M.init = function()
vim.schedule(function()
get_tool().init(get_context())
get_tool().init(M.get_context())
end)
end

M.update = function()
vim.schedule(function()
get_tool().update(get_context())
get_tool().update(M.get_context())
end)
end

M.terminate = function()
get_tool().terminate(get_context())
get_tool().terminate(M.get_context())
end

M.status = function()
get_tool().status(get_context())
get_tool().status(M.get_context())
end

local gc_running = false
Expand Down
22 changes: 20 additions & 2 deletions test/gentags/ctags_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,26 @@ describe("gentags.ctags", function()
local github_actions = os.getenv("GITHUB_ACTIONS") == "true"

local ctags = require("gentags.ctags")
local dispatcher = require("gentags.dispatcher")
require("gentags").setup()
describe("[run]", function()
it("test", function() end)
describe("[load]", function()
it("test", function()
local ok, err = pcall(ctags.load, dispatcher.get_context())
end)
end)
describe("[init]", function()
it("test", function()
local ok, err = pcall(ctags.init, dispatcher.get_context())
end)
end)
describe("[update]", function()
it("test", function()
local ok, err = pcall(ctags.update, dispatcher.get_context())
end)
end)
describe("[terminate]", function()
it("test", function()
local ok, err = pcall(ctags.terminate, dispatcher.get_context())
end)
end)
end)
37 changes: 37 additions & 0 deletions test/gentags/dispatcher_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
local cwd = vim.fn.getcwd()

describe("gentags.dispatcher", function()
local assert_eq = assert.is_equal
local assert_true = assert.is_true
local assert_false = assert.is_false

before_each(function()
vim.api.nvim_command("cd " .. cwd)
end)

local github_actions = os.getenv("GITHUB_ACTIONS") == "true"

local dispatcher = require("gentags.dispatcher")
require("gentags").setup()

describe("[load]", function()
it("test", function()
local ok, err = pcall(dispatcher.load)
end)
end)
describe("[init]", function()
it("test", function()
local ok, err = pcall(dispatcher.init)
end)
end)
describe("[update]", function()
it("test", function()
local ok, err = pcall(dispatcher.update)
end)
end)
describe("[terminate]", function()
it("test", function()
local ok, err = pcall(dispatcher.terminate)
end)
end)
end)

0 comments on commit d4d77a9

Please sign in to comment.