Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Commit 84c2d69

Browse files
authored
Fix cached project (#4403)
1 parent dc93c46 commit 84c2d69

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

lua/spacevim/plugin/projectmanager.lua

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
-- License: GPLv3
77
--=============================================================================
88

9-
local logger = require('spacevim.logger').derive('roter')
9+
local logger = require('spacevim.logger').derive('project')
1010
local sp = require('spacevim')
1111
local sp_file = require('spacevim.api.file')
1212
local sp_json = require('spacevim.api.data.json')
@@ -39,6 +39,7 @@ local function update_rooter_patterns()
3939
end
4040
end
4141
end
42+
4243
local function is_ignored_dir(dir)
4344
for _,v in pairs(project_rooter_ignores) do
4445
if string.match(dir, v) ~= nil then
@@ -76,14 +77,32 @@ local function filereadable(fpath)
7677
if f ~= nil then io.close(f) return true else return false end
7778
end
7879

80+
local function isdirectory(fpath)
81+
local f, err, code = io.open(fpath, "r")
82+
if f ~= nil then
83+
f:close()
84+
return false
85+
end
86+
return code == 13
87+
end
88+
89+
local function filter_invalid(projects)
90+
for key, value in pairs(projects) do
91+
if fn.isdirectory(value.path) == 0 then
92+
projects[key] = nil
93+
end
94+
end
95+
return projects
96+
end
97+
7998
local function load_cache()
8099
if filereadable(project_cache_path) then
81100
logger.info('Load projects cache from: ' .. project_cache_path)
82101
local cache_context = readfile(project_cache_path)
83-
if cache_context == nil then
102+
if cache_context ~= nil then
84103
local cache_object = sp_json.json_decode(cache_context)
85104
if type(cache_object) == 'table' then
86-
project_paths = fn.filter(cache_object, '!empty(v:key)')
105+
project_paths = filter_invalid(cache_object)
87106
end
88107
end
89108
else
@@ -246,14 +265,17 @@ end
246265

247266
function M.open(project)
248267
local path = project_paths[project]['path']
268+
local name = project_paths[project]['name']
249269
sp.cmd('tabnew')
270+
-- I am not sure we should set the project name here.
271+
-- sp.cmd('let t:_spacevim_tab_name = "[' .. name .. ']"')
250272
sp.cmd(cd .. ' ' .. path)
251273
if sp_opt.filemanager == 'vimfiler' then
252274
sp.cmd('Startify | VimFiler')
253275
elseif sp_opt.filemanager == 'nerdtree' then
254276
sp.cmd('Startify | NERDTree')
255277
elseif sp_opt.filemanager == 'defx' then
256-
sp.cmd('Startify | Defx')
278+
sp.cmd('Startify | Defx -new')
257279
end
258280
end
259281

@@ -264,7 +286,9 @@ end
264286

265287
function M.RootchandgeCallback()
266288
local path = sp_file.unify_path(fn.getcwd(), ':p')
267-
local name = fn.fnamemodify(path, ':t')
289+
local name = fn.fnamemodify(path, ':h:t')
290+
logger.debug('project name is:' .. name)
291+
logger.debug('project path is:' .. path)
268292
local project = {
269293
['path'] = path,
270294
['name'] = name,

0 commit comments

Comments
 (0)