Skip to content

Commit

Permalink
fix(crash): fix terminate crash
Browse files Browse the repository at this point in the history
  • Loading branch information
linrongbin16 committed Jan 2, 2024
1 parent a15f6d1 commit bcaabd6
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions lua/gentags/dispatcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ local function get_tool()
local cfg = configs.get()
local tool = cfg.tool
local toolchain = TOOLS_MAP[string.lower(tool)] --[[@as gentags.Tool]]
assert(
logging.get("gentags"):ensure(
toolchain ~= nil,
string.format("%s is not supported!", vim.inspect(tool))
)
Expand Down Expand Up @@ -86,28 +86,53 @@ end

M.load = function()
vim.schedule(function()
get_tool().load(M.get_context())
local ok, ctx_or_err = pcall(M.get_context)
local logger = logging.get("gentags") --[[@as commons.logging.Logger]]
logger:ensure(ok, "failed to get context:%s", vim.inspect(ctx_or_err))
local tool = get_tool()
local ok2, err2 = pcall(tool.load, ctx_or_err)
logger:ensure(ok2, "failed to load:%s", vim.inspect(err2))

Check warning on line 94 in lua/gentags/dispatcher.lua

View check run for this annotation

Codecov / codecov/patch

lua/gentags/dispatcher.lua#L89-L94

Added lines #L89 - L94 were not covered by tests
end)
end

M.init = function()
vim.schedule(function()
get_tool().init(M.get_context())
local ok, ctx_or_err = pcall(M.get_context)
local logger = logging.get("gentags") --[[@as commons.logging.Logger]]
logger:ensure(ok, "failed to get context:%s", vim.inspect(ctx_or_err))
local tool = get_tool()
local ok2, err2 = pcall(tool.init, ctx_or_err)
logger:ensure(ok2, "failed to init:%s", vim.inspect(err2))

Check warning on line 105 in lua/gentags/dispatcher.lua

View check run for this annotation

Codecov / codecov/patch

lua/gentags/dispatcher.lua#L100-L105

Added lines #L100 - L105 were not covered by tests
end)
end

M.update = function()
vim.schedule(function()
get_tool().update(M.get_context())
local ok, ctx_or_err = pcall(M.get_context)
local logger = logging.get("gentags") --[[@as commons.logging.Logger]]
logger:ensure(ok, "failed to get context:%s", vim.inspect(ctx_or_err))
local tool = get_tool()
local ok2, err2 = pcall(tool.update, ctx_or_err)
logger:ensure(ok2, "failed to update:%s", vim.inspect(err2))

Check warning on line 116 in lua/gentags/dispatcher.lua

View check run for this annotation

Codecov / codecov/patch

lua/gentags/dispatcher.lua#L111-L116

Added lines #L111 - L116 were not covered by tests
end)
end

M.terminate = function()
get_tool().terminate(M.get_context())
local ok, ctx_or_err = pcall(M.get_context)
local logger = logging.get("gentags") --[[@as commons.logging.Logger]]
logger:ensure(ok, "failed to get context:%s", vim.inspect(ctx_or_err))
local tool = get_tool()
local ok2, err2 = pcall(tool.update, ctx_or_err)
logger:ensure(ok2, "failed to terminate:%s", vim.inspect(err2))
end

M.status = function()
get_tool().status(M.get_context())
local ok, ctx_or_err = pcall(M.get_context)
local logger = logging.get("gentags") --[[@as commons.logging.Logger]]
logger:ensure(ok, "failed to get context:%s", vim.inspect(ctx_or_err))
local tool = get_tool()
local ok2, err2 = pcall(tool.status, ctx_or_err)
logger:ensure(ok2, "failed to get status:%s", vim.inspect(err2))

Check warning on line 135 in lua/gentags/dispatcher.lua

View check run for this annotation

Codecov / codecov/patch

lua/gentags/dispatcher.lua#L130-L135

Added lines #L130 - L135 were not covered by tests
end

local gc_running = false
Expand Down

0 comments on commit bcaabd6

Please sign in to comment.