1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-25 19:32:20 +08:00

fix(projectmanager): remove debug info

This commit is contained in:
wsdjeg 2022-10-26 17:17:56 +08:00
parent 7347ec4bff
commit d3a2916dc8

View File

@ -20,7 +20,6 @@ local project_rooter_patterns = {}
local project_rooter_ignores = {} local project_rooter_ignores = {}
local project_callback = {} local project_callback = {}
local cd = 'cd' local cd = 'cd'
if fn.exists(':tcd') then if fn.exists(':tcd') then
cd = 'tcd' cd = 'tcd'
@ -31,7 +30,7 @@ end
local function update_rooter_patterns() local function update_rooter_patterns()
project_rooter_patterns = {} project_rooter_patterns = {}
project_rooter_ignores = {} project_rooter_ignores = {}
for _,v in pairs(sp_opt.project_rooter_patterns) do for _, v in pairs(sp_opt.project_rooter_patterns) do
if string.match(v, '^!') == nil then if string.match(v, '^!') == nil then
table.insert(project_rooter_patterns, v) table.insert(project_rooter_patterns, v)
else else
@ -41,7 +40,7 @@ local function update_rooter_patterns()
end end
local function is_ignored_dir(dir) local function is_ignored_dir(dir)
for _,v in pairs(project_rooter_ignores) do for _, v in pairs(project_rooter_ignores) do
if string.match(dir, v) ~= nil then if string.match(dir, v) ~= nil then
logger.debug('this is an ignored dir:' .. dir) logger.debug('this is an ignored dir:' .. dir)
return true return true
@ -63,9 +62,9 @@ local function cache()
end end
local function readfile(path) local function readfile(path)
local file = io.open(path, "r") local file = io.open(path, 'r')
if file then if file then
local content = file:read("*a") local content = file:read('*a')
io.close(file) io.close(file)
return content return content
end end
@ -74,11 +73,16 @@ end
local function filereadable(fpath) local function filereadable(fpath)
local f = io.open(fpath, 'r') local f = io.open(fpath, 'r')
if f ~= nil then io.close(f) return true else return false end if f ~= nil then
io.close(f)
return true
else
return false
end
end end
local function isdirectory(fpath) local function isdirectory(fpath)
local f, err, code = io.open(fpath, "r") local f, err, code = io.open(fpath, 'r')
if f ~= nil then if f ~= nil then
f:close() f:close()
return false return false
@ -112,7 +116,9 @@ end
local function sort_by_opened_time() local function sort_by_opened_time()
local paths = {} local paths = {}
for k,v in pairs(project_paths) do table.insert(paths, k) end for k, v in pairs(project_paths) do
table.insert(paths, k)
end
table.sort(paths, compare_time) table.sort(paths, compare_time)
if sp_opt.projects_cache_num > 0 and #paths >= sp_opt.projects_cache_num then if sp_opt.projects_cache_num > 0 and #paths >= sp_opt.projects_cache_num then
for i = sp_opt.projects_cache_num, #paths, 1 do for i = sp_opt.projects_cache_num, #paths, 1 do
@ -153,8 +159,8 @@ local function sort_dirs(dirs)
end end
local function compare(d1, d2) local function compare(d1, d2)
local _, al = string.gsub(d1, "/", "") local _, al = string.gsub(d1, '/', '')
local _, bl = string.gsub(d2, "/", "") local _, bl = string.gsub(d2, '/', '')
if sp_opt.project_rooter_outermost == 0 then if sp_opt.project_rooter_outermost == 0 then
return bl - al return bl - al
else else
@ -170,7 +176,7 @@ local function find_root_directory()
end end
logger.debug('start to find root for: ' .. fd) logger.debug('start to find root for: ' .. fd)
local dirs = {} local dirs = {}
for _,pattern in pairs(project_rooter_patterns) do for _, pattern in pairs(project_rooter_patterns) do
logger.debug('searching rooter_patterns:' .. pattern) logger.debug('searching rooter_patterns:' .. pattern)
local find_path = '' local find_path = ''
if string.sub(pattern, -1) == '/' then if string.sub(pattern, -1) == '/' then
@ -186,18 +192,14 @@ local function find_root_directory()
find_path = sp_file.findfile(pattern, fd) find_path = sp_file.findfile(pattern, fd)
end end
end end
logger.debug('find_path is:' .. find_path)
local path_type = fn.getftype(find_path) local path_type = fn.getftype(find_path)
logger.debug('path_type is:' .. path_type) if (path_type == 'dir' or path_type == 'file') and not (is_ignored_dir(find_path)) then
if ( path_type == 'dir' or path_type == 'file' )
and not(is_ignored_dir(find_path)) then
find_path = sp_file.unify_path(find_path, ':p') find_path = sp_file.unify_path(find_path, ':p')
if path_type == 'dir' then if path_type == 'dir' then
find_path = sp_file.unify_path(find_path, ':h:h') find_path = sp_file.unify_path(find_path, ':h:h')
else else
find_path = sp_file.unify_path(find_path, ':h') find_path = sp_file.unify_path(find_path, ':h')
end end
logger.debug('find_path is:' .. find_path)
if find_path ~= sp_file.unify_path(fn.expand('$HOME')) then if find_path ~= sp_file.unify_path(fn.expand('$HOME')) then
logger.info(' (' .. pattern .. '):' .. find_path) logger.info(' (' .. pattern .. '):' .. find_path)
table.insert(dirs, find_path) table.insert(dirs, find_path)
@ -212,13 +214,21 @@ local function cache_project(prj)
project_paths[prj.path] = prj project_paths[prj.path] = prj
sp.cmd('let g:unite_source_menu_menus.Projects.command_candidates = []') sp.cmd('let g:unite_source_menu_menus.Projects.command_candidates = []')
for _, key in pairs(sort_by_opened_time()) do for _, key in pairs(sort_by_opened_time()) do
local desc = '[' .. project_paths[key].name .. '] ' .. project_paths[key].path .. ' <' .. fn.strftime('%Y-%m-%d %T', project_paths[key].opened_time) .. '>' local desc = '['
.. project_paths[key].name
.. '] '
.. project_paths[key].path
.. ' <'
.. fn.strftime('%Y-%m-%d %T', project_paths[key].opened_time)
.. '>'
local cmd = "call SpaceVim#plugins#projectmanager#open('" .. project_paths[key].path .. "')" local cmd = "call SpaceVim#plugins#projectmanager#open('" .. project_paths[key].path .. "')"
sp.cmd('call add(g:unite_source_menu_menus.Projects.command_candidates, ["' sp.cmd(
'call add(g:unite_source_menu_menus.Projects.command_candidates, ["'
.. desc .. desc
.. '", "' .. '", "'
.. cmd .. cmd
.. '"])') .. '"])'
)
end end
if sp_opt.enable_projects_cache then if sp_opt.enable_projects_cache then
cache() cache()
@ -241,11 +251,13 @@ sp.cmd([[
]]) ]])
if sp_opt.project_auto_root == 1 then if sp_opt.project_auto_root == 1 then
sp.cmd("augroup spacevim_project_rooter") sp.cmd('augroup spacevim_project_rooter')
sp.cmd("autocmd!") sp.cmd('autocmd!')
sp.cmd("autocmd VimEnter,BufEnter * call SpaceVim#plugins#projectmanager#current_root()") sp.cmd('autocmd VimEnter,BufEnter * call SpaceVim#plugins#projectmanager#current_root()')
sp.cmd("autocmd BufWritePost * :call setbufvar('%', 'rootDir', '') | call SpaceVim#plugins#projectmanager#current_root()") sp.cmd(
sp.cmd("augroup END") "autocmd BufWritePost * :call setbufvar('%', 'rootDir', '') | call SpaceVim#plugins#projectmanager#current_root()"
)
sp.cmd('augroup END')
end end
local M = {} local M = {}
@ -283,7 +295,6 @@ function M.current_name()
return sp.eval('b:_spacevim_project_name') return sp.eval('b:_spacevim_project_name')
end end
function M.RootchandgeCallback() function M.RootchandgeCallback()
local path = sp_file.unify_path(fn.getcwd(), ':p') local path = sp_file.unify_path(fn.getcwd(), ':p')
local name = fn.fnamemodify(path, ':h:t') local name = fn.fnamemodify(path, ':h:t')
@ -292,7 +303,7 @@ function M.RootchandgeCallback()
local project = { local project = {
['path'] = path, ['path'] = path,
['name'] = name, ['name'] = name,
['opened_time'] = os.time() ['opened_time'] = os.time(),
} }
if project.path == '' then if project.path == '' then
return return
@ -323,52 +334,48 @@ end
function M.kill_project() function M.kill_project()
local name = sp.eval('b:_spacevim_project_name') local name = sp.eval('b:_spacevim_project_name')
if name ~= '' then if name ~= '' then
sp_buffer.filter_do( sp_buffer.filter_do({
{
['expr'] = { ['expr'] = {
'buflisted(v:val)', 'buflisted(v:val)',
'getbufvar(v:val, "_spacevim_project_name") == "' .. name .. '"', 'getbufvar(v:val, "_spacevim_project_name") == "' .. name .. '"',
}, },
['do'] = 'bd %d' ['do'] = 'bd %d',
} })
)
end end
end end
function M.complete_project(arglead, cmdline, cursorpos) function M.complete_project(arglead, cmdline, cursorpos)
local dir = '~' local dir = '~'
local result = fn.split(fn.globpath(dir, '*'), "\n") local result = fn.split(fn.globpath(dir, '*'), '\n')
local ps = {} local ps = {}
for p in result do for p in result do
if fn.isdirectory(p) == 1 and fn.isdirectory(p .. sp_file.separator .. '.git') == 1 then if fn.isdirectory(p) == 1 and fn.isdirectory(p .. sp_file.separator .. '.git') == 1 then
table.insert(ps, fn.fnamemodify(p, ':t')) table.insert(ps, fn.fnamemodify(p, ':t'))
end end
end end
return fn.join(ps, "\n") return fn.join(ps, '\n')
end end
function M.OpenProject(p) function M.OpenProject(p)
sp.cmd('CtrlP '.. dir) sp.cmd('CtrlP ' .. dir)
end end
function M.current_root() function M.current_root()
local bufname = fn.bufname('%') local bufname = fn.bufname('%')
if bufname == '[denite]' if bufname:match('%[denite%]') or bufname:match('denite-filter') or bufname:match('%[defx%]') then
or bufname == 'denite-filter'
or bufname == '[defx]' then
return return
end end
if table.concat(sp_opt.project_rooter_patterns, ':') ~= table.concat(spacevim_project_rooter_patterns, ':') then if
table.concat(sp_opt.project_rooter_patterns, ':')
~= table.concat(spacevim_project_rooter_patterns, ':')
then
logger.info('project_rooter_patterns option has been change, clear b:rootDir') logger.info('project_rooter_patterns option has been change, clear b:rootDir')
fn.setbufvar('%', 'rootDir', '') fn.setbufvar('%', 'rootDir', '')
spacevim_project_rooter_patterns = sp_opt.project_rooter_patterns spacevim_project_rooter_patterns = sp_opt.project_rooter_patterns
update_rooter_patterns() update_rooter_patterns()
end end
local rootdir = fn.getbufvar('%', 'rootDir', '') local rootdir = fn.getbufvar('%', 'rootDir', '')
-- @bug fn.getbufvar('%', 'rootDir', '') return nil if rootdir == '' then
if rootdir == nil or rootdir == '' then
rootdir = find_root_directory() rootdir = find_root_directory()
if rootdir == nil or rootdir == '' then if rootdir == nil or rootdir == '' then
rootdir = sp_file.unify_path(fn.getcwd()) rootdir = sp_file.unify_path(fn.getcwd())