|
6 | 6 | -- License: GPLv3 |
7 | 7 | --============================================================================= |
8 | 8 |
|
9 | | -local logger = require('spacevim.logger').derive('roter') |
| 9 | +local logger = require('spacevim.logger').derive('project') |
10 | 10 | local sp = require('spacevim') |
11 | 11 | local sp_file = require('spacevim.api.file') |
12 | 12 | local sp_json = require('spacevim.api.data.json') |
@@ -39,6 +39,7 @@ local function update_rooter_patterns() |
39 | 39 | end |
40 | 40 | end |
41 | 41 | end |
| 42 | + |
42 | 43 | local function is_ignored_dir(dir) |
43 | 44 | for _,v in pairs(project_rooter_ignores) do |
44 | 45 | if string.match(dir, v) ~= nil then |
@@ -76,14 +77,32 @@ local function filereadable(fpath) |
76 | 77 | if f ~= nil then io.close(f) return true else return false end |
77 | 78 | end |
78 | 79 |
|
| 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 | + |
79 | 98 | local function load_cache() |
80 | 99 | if filereadable(project_cache_path) then |
81 | 100 | logger.info('Load projects cache from: ' .. project_cache_path) |
82 | 101 | local cache_context = readfile(project_cache_path) |
83 | | - if cache_context == nil then |
| 102 | + if cache_context ~= nil then |
84 | 103 | local cache_object = sp_json.json_decode(cache_context) |
85 | 104 | if type(cache_object) == 'table' then |
86 | | - project_paths = fn.filter(cache_object, '!empty(v:key)') |
| 105 | + project_paths = filter_invalid(cache_object) |
87 | 106 | end |
88 | 107 | end |
89 | 108 | else |
@@ -246,14 +265,17 @@ end |
246 | 265 |
|
247 | 266 | function M.open(project) |
248 | 267 | local path = project_paths[project]['path'] |
| 268 | + local name = project_paths[project]['name'] |
249 | 269 | sp.cmd('tabnew') |
| 270 | + -- I am not sure we should set the project name here. |
| 271 | + -- sp.cmd('let t:_spacevim_tab_name = "[' .. name .. ']"') |
250 | 272 | sp.cmd(cd .. ' ' .. path) |
251 | 273 | if sp_opt.filemanager == 'vimfiler' then |
252 | 274 | sp.cmd('Startify | VimFiler') |
253 | 275 | elseif sp_opt.filemanager == 'nerdtree' then |
254 | 276 | sp.cmd('Startify | NERDTree') |
255 | 277 | elseif sp_opt.filemanager == 'defx' then |
256 | | - sp.cmd('Startify | Defx') |
| 278 | + sp.cmd('Startify | Defx -new') |
257 | 279 | end |
258 | 280 | end |
259 | 281 |
|
|
264 | 286 |
|
265 | 287 | function M.RootchandgeCallback() |
266 | 288 | 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) |
268 | 292 | local project = { |
269 | 293 | ['path'] = path, |
270 | 294 | ['name'] = name, |
|
0 commit comments