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

feat(git): update remote manager context when switch project

This commit is contained in:
Eric Wong 2024-02-24 15:38:20 +08:00
parent 1c9a09223f
commit 031a6a2497
4 changed files with 40 additions and 9 deletions

View File

@ -13,7 +13,7 @@ local log = require('git.log')
-- script local valuables
local show_help_infoo = false
local show_help_info = false
local update_branch_list_jobid = -1
local update_branch_list_name = ''
local update_branch_list_branches = {}
@ -31,8 +31,14 @@ local help_info = {
'" <CR>: view git log',
'" f: fetch remote under cursor',
'" o: toggle display of branchs',
'" q: close windows"'
}
-- project_manager support
local project_manager_registered = false
local bufnr = -1
local bufname = ''
@ -74,7 +80,7 @@ local function update_buf_context()
return
end
local context = {}
if show_help_infoo then
if show_help_info then
for _, v in ipairs(help_info) do
table.insert(context, v)
end
@ -231,10 +237,10 @@ local function toggle_remote_branch()
end
local function toggle_help()
if show_help_infoo then
show_help_infoo = false
if show_help_info then
show_help_info = false
else
show_help_infoo = true
show_help_info = true
end
update_buf_context()
end
@ -269,6 +275,10 @@ local function fetch_remote()
end
function M.open()
if not project_manager_registered then
require('spacevim.plugin.projectmanager').reg_callback(M.on_cwd_changed)
project_manager_registered = true
end
if bufnr ~= -1 and vim.api.nvim_buf_is_valid(bufnr) then
vim.api.nvim_buf_delete(bufnr, {
force = true,
@ -304,6 +314,18 @@ function M.open()
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'f', '', {
callback = fetch_remote,
})
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'q', '', {
callback = function ()
vim.cmd('quit')
show_help_info = false
end,
})
end
function M.on_cwd_changed()
if vim.api.nvim_buf_is_valid(bufnr) then
update()
end
end
return M

View File

@ -38,6 +38,7 @@ lang: zh
- [x] 使得 `:A` 命令支持 toml 配置文件
- [x] 增加 git 远程仓库管理插件
- [x] 使用 `<cr>` 快捷键展示 git log
- [x] 切换项目时,更新 remote 窗口信息
- [ ] 缓存远程仓库以及分支名称等信息
- [ ] 基于项目路径存储信息
- [x] 使用 lua 实现 `ctags#update` 函数

View File

@ -37,6 +37,7 @@ The roadmap defines the project direction and priorities.
- [x] make `:A` command support toml configuration file
- [x] add git remote manager
- [x] make `<cr>` show git log
- [x] update remote context when switch project
- [ ] cache remote and branch info
- [ ] cache info based on project root
- [x] implement `ctags#update` in lua

View File

@ -158,8 +158,7 @@ local function compare(d1, d2)
-- logger.debug('al is ' .. al)
-- logger.debug('bl is ' .. bl)
-- the project_rooter_outermost is 0/false or 1 true
if sp_opt.project_rooter_outermost == 0
or sp_opt.project_rooter_outermost == false then
if sp_opt.project_rooter_outermost == 0 or sp_opt.project_rooter_outermost == false then
if bl >= al then
return false
else
@ -344,8 +343,13 @@ function M.RootchandgeCallback()
-- let b:_spacevim_project_name = g:_spacevim_project_name
fn.setbufvar('%', '_spacevim_project_name', project.name)
for _, Callback in pairs(project_callback) do
logger.debug(' run callback:' .. Callback)
fn.call(Callback, {})
if type(Callback) == 'string' then
logger.debug(' run callback:' .. Callback)
fn.call(Callback, {})
elseif type(Callback) == 'function' then
logger.debug(' run callback:' .. tostring(Callback))
pcall(Callback)
end
end
end
@ -356,6 +360,9 @@ function M.reg_callback(func)
else
table.insert(project_callback, func)
end
elseif type(func) == 'function' then
-- support lua function
table.insert(project_callback, func)
else
logger.warn('type of func is:' .. type(func))
logger.warn('can not register the project callback: ' .. fn.string(func))