mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 17:50:04 +08:00
fix(projectmanager): remove debug info
This commit is contained in:
parent
7347ec4bff
commit
d3a2916dc8
@ -20,7 +20,6 @@ local project_rooter_patterns = {}
|
||||
local project_rooter_ignores = {}
|
||||
local project_callback = {}
|
||||
|
||||
|
||||
local cd = 'cd'
|
||||
if fn.exists(':tcd') then
|
||||
cd = 'tcd'
|
||||
@ -63,9 +62,9 @@ local function cache()
|
||||
end
|
||||
|
||||
local function readfile(path)
|
||||
local file = io.open(path, "r")
|
||||
local file = io.open(path, 'r')
|
||||
if file then
|
||||
local content = file:read("*a")
|
||||
local content = file:read('*a')
|
||||
io.close(file)
|
||||
return content
|
||||
end
|
||||
@ -74,11 +73,16 @@ end
|
||||
|
||||
local function filereadable(fpath)
|
||||
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
|
||||
|
||||
local function isdirectory(fpath)
|
||||
local f, err, code = io.open(fpath, "r")
|
||||
local f, err, code = io.open(fpath, 'r')
|
||||
if f ~= nil then
|
||||
f:close()
|
||||
return false
|
||||
@ -112,7 +116,9 @@ end
|
||||
|
||||
local function sort_by_opened_time()
|
||||
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)
|
||||
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
|
||||
@ -153,8 +159,8 @@ local function sort_dirs(dirs)
|
||||
end
|
||||
|
||||
local function compare(d1, d2)
|
||||
local _, al = string.gsub(d1, "/", "")
|
||||
local _, bl = string.gsub(d2, "/", "")
|
||||
local _, al = string.gsub(d1, '/', '')
|
||||
local _, bl = string.gsub(d2, '/', '')
|
||||
if sp_opt.project_rooter_outermost == 0 then
|
||||
return bl - al
|
||||
else
|
||||
@ -186,18 +192,14 @@ local function find_root_directory()
|
||||
find_path = sp_file.findfile(pattern, fd)
|
||||
end
|
||||
end
|
||||
logger.debug('find_path is:' .. 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')
|
||||
if path_type == 'dir' then
|
||||
find_path = sp_file.unify_path(find_path, ':h:h')
|
||||
else
|
||||
find_path = sp_file.unify_path(find_path, ':h')
|
||||
end
|
||||
logger.debug('find_path is:' .. find_path)
|
||||
if find_path ~= sp_file.unify_path(fn.expand('$HOME')) then
|
||||
logger.info(' (' .. pattern .. '):' .. find_path)
|
||||
table.insert(dirs, find_path)
|
||||
@ -212,13 +214,21 @@ local function cache_project(prj)
|
||||
project_paths[prj.path] = prj
|
||||
sp.cmd('let g:unite_source_menu_menus.Projects.command_candidates = []')
|
||||
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 .. "')"
|
||||
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
|
||||
.. '", "'
|
||||
.. cmd
|
||||
.. '"])')
|
||||
.. '"])'
|
||||
)
|
||||
end
|
||||
if sp_opt.enable_projects_cache then
|
||||
cache()
|
||||
@ -241,11 +251,13 @@ sp.cmd([[
|
||||
]])
|
||||
|
||||
if sp_opt.project_auto_root == 1 then
|
||||
sp.cmd("augroup spacevim_project_rooter")
|
||||
sp.cmd("autocmd!")
|
||||
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("augroup END")
|
||||
sp.cmd('augroup spacevim_project_rooter')
|
||||
sp.cmd('autocmd!')
|
||||
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('augroup END')
|
||||
end
|
||||
local M = {}
|
||||
|
||||
@ -283,7 +295,6 @@ function M.current_name()
|
||||
return sp.eval('b:_spacevim_project_name')
|
||||
end
|
||||
|
||||
|
||||
function M.RootchandgeCallback()
|
||||
local path = sp_file.unify_path(fn.getcwd(), ':p')
|
||||
local name = fn.fnamemodify(path, ':h:t')
|
||||
@ -292,7 +303,7 @@ function M.RootchandgeCallback()
|
||||
local project = {
|
||||
['path'] = path,
|
||||
['name'] = name,
|
||||
['opened_time'] = os.time()
|
||||
['opened_time'] = os.time(),
|
||||
}
|
||||
if project.path == '' then
|
||||
return
|
||||
@ -323,52 +334,48 @@ end
|
||||
function M.kill_project()
|
||||
local name = sp.eval('b:_spacevim_project_name')
|
||||
if name ~= '' then
|
||||
sp_buffer.filter_do(
|
||||
{
|
||||
sp_buffer.filter_do({
|
||||
['expr'] = {
|
||||
'buflisted(v:val)',
|
||||
'getbufvar(v:val, "_spacevim_project_name") == "' .. name .. '"',
|
||||
},
|
||||
['do'] = 'bd %d'
|
||||
}
|
||||
)
|
||||
['do'] = 'bd %d',
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
function M.complete_project(arglead, cmdline, cursorpos)
|
||||
local dir = '~'
|
||||
local result = fn.split(fn.globpath(dir, '*'), "\n")
|
||||
local result = fn.split(fn.globpath(dir, '*'), '\n')
|
||||
local ps = {}
|
||||
for p in result do
|
||||
if fn.isdirectory(p) == 1 and fn.isdirectory(p .. sp_file.separator .. '.git') == 1 then
|
||||
table.insert(ps, fn.fnamemodify(p, ':t'))
|
||||
end
|
||||
end
|
||||
return fn.join(ps, "\n")
|
||||
return fn.join(ps, '\n')
|
||||
end
|
||||
|
||||
|
||||
function M.OpenProject(p)
|
||||
sp.cmd('CtrlP ' .. dir)
|
||||
end
|
||||
|
||||
|
||||
function M.current_root()
|
||||
local bufname = fn.bufname('%')
|
||||
if bufname == '[denite]'
|
||||
or bufname == 'denite-filter'
|
||||
or bufname == '[defx]' then
|
||||
if bufname:match('%[denite%]') or bufname:match('denite-filter') or bufname:match('%[defx%]') then
|
||||
return
|
||||
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')
|
||||
fn.setbufvar('%', 'rootDir', '')
|
||||
spacevim_project_rooter_patterns = sp_opt.project_rooter_patterns
|
||||
update_rooter_patterns()
|
||||
end
|
||||
local rootdir = fn.getbufvar('%', 'rootDir', '')
|
||||
-- @bug fn.getbufvar('%', 'rootDir', '') return nil
|
||||
if rootdir == nil or rootdir == '' then
|
||||
if rootdir == '' then
|
||||
rootdir = find_root_directory()
|
||||
if rootdir == nil or rootdir == '' then
|
||||
rootdir = sp_file.unify_path(fn.getcwd())
|
||||
|
Loading…
Reference in New Issue
Block a user