1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 08:00:04 +08:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Eric Wong
b9eb91a793 feat(git): improve git branch detection 2024-12-13 00:32:24 +08:00
Eric Wong
4e5a459ee4 fix(cmp): fix return nil behavior
close https://github.com/SpaceVim/SpaceVim/issues/4943
2024-12-13 00:10:43 +08:00
2 changed files with 8 additions and 1 deletions

View File

@ -6,7 +6,6 @@ local log = require('git.log')
local str = require('spacevim.api.data.string')
local branch_ui = require('git.ui.branch')
local branch = ''
local branch_info = {}
local job_pwds = {}
@ -21,6 +20,7 @@ local function on_stdout_show_branch(id, data)
end
local function on_exit_show_branch(id, code, single)
log.debug('git-branch exit code:' .. code .. ' single:' .. single)
local pwd = job_pwds['jobid' .. id] or ''
if branch_info[pwd] == nil and #pwd > 0 then
branch_info[pwd] = {}
@ -41,11 +41,13 @@ local function update_branch_name(pwd, ...)
or vim.fn.get(vim.fn.get(branch_info, pwd, {}), 'last_update_done', 0)
<= vim.fn.localtime() - 1
then
log.debug('git branch cmd:' .. vim.inspect(cmd))
local jobid = job.start(cmd, {
on_stdout = on_stdout_show_branch,
on_exit = on_exit_show_branch,
cwd = pwd,
})
log.debug('git branch jobid:' .. jobid)
if jobid > 0 then
job_pwds['jobid' .. jobid] = pwd
end

View File

@ -57,6 +57,11 @@ local function enter(f) -- {{{
else
pcall(f)
end
elseif copt.auto_completion_return_key_behavior == 'nil' then
if cmp.visible() then
cmp.close()
end
pcall(f)
end
end
-- }}}