mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 17:50:04 +08:00
Add projects caches (#3875)
This commit is contained in:
parent
3c4ea75baa
commit
1ac1fd789a
@ -1057,6 +1057,22 @@ let g:spacevim_search_tools = ['rg', 'ag', 'pt', 'ack', 'grep', 'find
|
||||
" <
|
||||
let g:spacevim_project_rooter_patterns = ['.git/', '_darcs/', '.hg/', '.bzr/', '.svn/']
|
||||
""
|
||||
" @section enable_projects_cache, options-enable_projects_cache
|
||||
" @parentsection options
|
||||
" Enable/Disable cross session projects cache. Enabled by default.
|
||||
|
||||
""
|
||||
" Enable/Disable cross session projects cache. Enabled by default.
|
||||
let g:spacevim_enable_projects_cache = 1
|
||||
""
|
||||
" @section projects_cache_num, options-projects_cache_num
|
||||
" @parentsection options
|
||||
" Setting the numbers of cached projects, by default it is 20.
|
||||
|
||||
""
|
||||
" Setting the numbers of cached projects, by default it is 20.
|
||||
let g:spacevim_projects_cache_num = 20
|
||||
""
|
||||
" @section project_rooter_automatically, options-project_rooter_automatically
|
||||
" @parentsection options
|
||||
" Enable/Disable project root detection. By default, SpaceVim will change the
|
||||
|
@ -19,6 +19,9 @@ let s:FILE = SpaceVim#api#import('file')
|
||||
" the name projectmanager is too long
|
||||
" use rooter instead
|
||||
let s:LOGGER =SpaceVim#logger#derive('rooter')
|
||||
let s:TIME = SpaceVim#api#import('time')
|
||||
let s:JSON = SpaceVim#api#import('data#json')
|
||||
let s:LIST = SpaceVim#api#import('data#list')
|
||||
|
||||
function! s:update_rooter_patterns() abort
|
||||
let s:project_rooter_patterns = filter(copy(g:spacevim_project_rooter_patterns), 'v:val !~# "^!"')
|
||||
@ -35,16 +38,28 @@ let s:spacevim_project_rooter_patterns = copy(g:spacevim_project_rooter_patterns
|
||||
call s:update_rooter_patterns()
|
||||
|
||||
let s:project_paths = {}
|
||||
let s:project_cache_path = s:FILE.unify_path(g:spacevim_data_dir, ':p') . 'SpaceVim/projects.json'
|
||||
|
||||
function! s:cache_project(prj) abort
|
||||
if !has_key(s:project_paths, a:prj.path)
|
||||
let s:project_paths[a:prj.path] = a:prj
|
||||
let desc = '[' . a:prj.name . '] ' . a:prj.path
|
||||
let cmd = "call SpaceVim#plugins#projectmanager#open('" . a:prj.path . "')"
|
||||
call add(g:unite_source_menu_menus.Projects.command_candidates, [desc,cmd])
|
||||
function! s:cache() abort
|
||||
call writefile([s:JSON.json_encode(s:project_paths)], s:FILE.unify_path(s:project_cache_path, ':p'))
|
||||
endfunction
|
||||
|
||||
function! s:load_cache() abort
|
||||
if filereadable(s:project_cache_path)
|
||||
call s:LOGGER.info('Load projects cache from: ' . s:project_cache_path)
|
||||
let cache_context = join(readfile(s:project_cache_path, ''), '')
|
||||
if !empty(cache_context)
|
||||
let s:project_paths = s:JSON.json_decode(cache_context)
|
||||
endif
|
||||
else
|
||||
call s:LOGGER.info('projects cache file does not exists!')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
if g:spacevim_enable_projects_cache
|
||||
call s:load_cache()
|
||||
endif
|
||||
|
||||
let g:unite_source_menu_menus =
|
||||
\ get(g:,'unite_source_menu_menus',{})
|
||||
let g:unite_source_menu_menus.Projects = {'description':
|
||||
@ -52,6 +67,38 @@ let g:unite_source_menu_menus.Projects = {'description':
|
||||
let g:unite_source_menu_menus.Projects.command_candidates =
|
||||
\ get(g:unite_source_menu_menus.Projects,'command_candidates', [])
|
||||
|
||||
function! s:cache_project(prj) abort
|
||||
let s:project_paths[a:prj.path] = a:prj
|
||||
let g:unite_source_menu_menus.Projects.command_candidates = []
|
||||
for key in s:sort_by_opened_time()
|
||||
let desc = '[' . s:project_paths[key].name . '] ' . s:project_paths[key].path . ' <' . strftime('%Y-%m-%d %T', s:project_paths[key].opened_time) . '>'
|
||||
let cmd = "call SpaceVim#plugins#projectmanager#open('" . s:project_paths[key].path . "')"
|
||||
call add(g:unite_source_menu_menus.Projects.command_candidates, [desc,cmd])
|
||||
endfor
|
||||
if g:spacevim_enable_projects_cache
|
||||
call s:cache()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" sort projects based on opened_time, and remove extra projects based on
|
||||
" projects_cache_num
|
||||
function! s:sort_by_opened_time() abort
|
||||
let paths = keys(s:project_paths)
|
||||
let paths = sort(paths, function('s:compare_time'))
|
||||
if g:spacevim_projects_cache_num > 0 && s:LIST.has_index(paths, g:spacevim_projects_cache_num)
|
||||
for path in paths[g:spacevim_projects_cache_num :]
|
||||
call remove(s:project_paths, path)
|
||||
endfor
|
||||
let paths = paths[:g:spacevim_projects_cache_num - 1]
|
||||
endif
|
||||
return paths
|
||||
endfunction
|
||||
|
||||
function! s:compare_time(d1, d2) abort
|
||||
return s:project_paths[a:d2].opened_time - s:project_paths[a:d1].opened_time
|
||||
endfunction
|
||||
|
||||
|
||||
" this function will use fuzzy find layer, now only denite and unite are
|
||||
" supported.
|
||||
|
||||
@ -62,6 +109,8 @@ function! SpaceVim#plugins#projectmanager#list() abort
|
||||
Denite menu:Projects
|
||||
elseif SpaceVim#layers#isLoaded('fzf')
|
||||
FzfMenu Projects
|
||||
elseif SpaceVim#layers#isLoaded('leaderf')
|
||||
Leaderf menu --name Projects
|
||||
else
|
||||
call SpaceVim#logger#warn('fuzzy find layer is needed to find project!')
|
||||
endif
|
||||
@ -75,6 +124,8 @@ function! SpaceVim#plugins#projectmanager#open(project) abort
|
||||
Startify | VimFiler
|
||||
elseif g:spacevim_filemanager ==# 'nerdtree'
|
||||
Startify | NERDTree
|
||||
elseif g:spacevim_filemanager ==# 'defx'
|
||||
Startify | Defx
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@ -82,12 +133,15 @@ function! SpaceVim#plugins#projectmanager#current_name() abort
|
||||
return get(b:, '_spacevim_project_name', '')
|
||||
endfunction
|
||||
|
||||
" this func is called when vim-rooter change the dir, That means the project
|
||||
" is changed, so will call call the registered function.
|
||||
" This function is called when projectmanager change the directory.
|
||||
"
|
||||
" What should be cached?
|
||||
" only the directory and project name.
|
||||
function! SpaceVim#plugins#projectmanager#RootchandgeCallback() abort
|
||||
let project = {
|
||||
\ 'path' : getcwd(),
|
||||
\ 'name' : fnamemodify(getcwd(), ':t')
|
||||
\ 'name' : fnamemodify(getcwd(), ':t'),
|
||||
\ 'opened_time' : localtime()
|
||||
\ }
|
||||
call s:cache_project(project)
|
||||
let g:_spacevim_project_name = project.name
|
||||
@ -176,7 +230,7 @@ endif
|
||||
function! s:find_root_directory() abort
|
||||
" @question confused about expand and fnamemodify
|
||||
" ref: https://github.com/vim/vim/issues/6793
|
||||
|
||||
|
||||
" get the current path of buffer
|
||||
" If it is a empty buffer, do nothing?
|
||||
let fd = expand('%:p')
|
||||
|
@ -36,47 +36,49 @@ CONTENTS *SpaceVim-contents*
|
||||
16. enable_insert_leader.........|SpaceVim-options-enable_insert_leader|
|
||||
17. enable_key_frequency.........|SpaceVim-options-enable_key_frequency|
|
||||
18. enable_neomake.....................|SpaceVim-options-enable_neomake|
|
||||
19. enable_statusline_bfpath.|SpaceVim-options-enable_statusline_bfpath|
|
||||
20. enable_statusline_mode.....|SpaceVim-options-enable_statusline_mode|
|
||||
21. enable_statusline_tag.......|SpaceVim-options-enable_statusline_tag|
|
||||
22. enable_tabline_ft_icon.....|SpaceVim-options-enable_tabline_ft_icon|
|
||||
23. enable_vimfiler_welcome...|SpaceVim-options-enable_vimfiler_welcome|
|
||||
24. enable_ycm.............................|SpaceVim-options-enable_ycm|
|
||||
25. error_symbol.........................|SpaceVim-options-error_symbol|
|
||||
26. escape_key_binding.............|SpaceVim-options-escape_key_binding|
|
||||
27. filemanager...........................|SpaceVim-options-filemanager|
|
||||
28. filetree_direction.............|SpaceVim-options-filetree_direction|
|
||||
29. guifont...................................|SpaceVim-options-guifont|
|
||||
30. home_files_number...............|SpaceVim-options-home_files_number|
|
||||
31. info_symbol...........................|SpaceVim-options-info_symbol|
|
||||
32. keep_server_alive...............|SpaceVim-options-keep_server_alive|
|
||||
33. language.................................|SpaceVim-options-language|
|
||||
34. lint_on_the_fly...................|SpaceVim-options-lint_on_the_fly|
|
||||
35. max_column.............................|SpaceVim-options-max_column|
|
||||
36. plugin_bundle_dir...............|SpaceVim-options-plugin_bundle_dir|
|
||||
37. plugin_manager_processes.|SpaceVim-options-plugin_manager_processes|
|
||||
38. project_rooter_automatically
|
||||
19. enable_projects_cache.......|SpaceVim-options-enable_projects_cache|
|
||||
20. enable_statusline_bfpath.|SpaceVim-options-enable_statusline_bfpath|
|
||||
21. enable_statusline_mode.....|SpaceVim-options-enable_statusline_mode|
|
||||
22. enable_statusline_tag.......|SpaceVim-options-enable_statusline_tag|
|
||||
23. enable_tabline_ft_icon.....|SpaceVim-options-enable_tabline_ft_icon|
|
||||
24. enable_vimfiler_welcome...|SpaceVim-options-enable_vimfiler_welcome|
|
||||
25. enable_ycm.............................|SpaceVim-options-enable_ycm|
|
||||
26. error_symbol.........................|SpaceVim-options-error_symbol|
|
||||
27. escape_key_binding.............|SpaceVim-options-escape_key_binding|
|
||||
28. filemanager...........................|SpaceVim-options-filemanager|
|
||||
29. filetree_direction.............|SpaceVim-options-filetree_direction|
|
||||
30. guifont...................................|SpaceVim-options-guifont|
|
||||
31. home_files_number...............|SpaceVim-options-home_files_number|
|
||||
32. info_symbol...........................|SpaceVim-options-info_symbol|
|
||||
33. keep_server_alive...............|SpaceVim-options-keep_server_alive|
|
||||
34. language.................................|SpaceVim-options-language|
|
||||
35. lint_on_the_fly...................|SpaceVim-options-lint_on_the_fly|
|
||||
36. max_column.............................|SpaceVim-options-max_column|
|
||||
37. plugin_bundle_dir...............|SpaceVim-options-plugin_bundle_dir|
|
||||
38. plugin_manager_processes.|SpaceVim-options-plugin_manager_processes|
|
||||
39. project_rooter_automatically
|
||||
...............................|SpaceVim-options-project_rooter_automatically|
|
||||
39. project_rooter_outermost.|SpaceVim-options-project_rooter_outermost|
|
||||
40. project_rooter_patterns...|SpaceVim-options-project_rooter_patterns|
|
||||
41. realtime_leader_guide.......|SpaceVim-options-realtime_leader_guide|
|
||||
42. relativenumber.....................|SpaceVim-options-relativenumber|
|
||||
43. retry_cnt...............................|SpaceVim-options-retry_cnt|
|
||||
44. search_tools.........................|SpaceVim-options-search_tools|
|
||||
45. sidebar_width.......................|SpaceVim-options-sidebar_width|
|
||||
46. snippet_engine.....................|SpaceVim-options-snippet_engine|
|
||||
47. statusline_iseparator.......|SpaceVim-options-statusline_iseparator|
|
||||
48. statusline_left_sections.|SpaceVim-options-statusline_left_sections|
|
||||
49. statusline_separator.........|SpaceVim-options-statusline_separator|
|
||||
50. statusline_unicode_symbols
|
||||
40. project_rooter_outermost.|SpaceVim-options-project_rooter_outermost|
|
||||
41. project_rooter_patterns...|SpaceVim-options-project_rooter_patterns|
|
||||
42. projects_cache_num.............|SpaceVim-options-projects_cache_num|
|
||||
43. realtime_leader_guide.......|SpaceVim-options-realtime_leader_guide|
|
||||
44. relativenumber.....................|SpaceVim-options-relativenumber|
|
||||
45. retry_cnt...............................|SpaceVim-options-retry_cnt|
|
||||
46. search_tools.........................|SpaceVim-options-search_tools|
|
||||
47. sidebar_width.......................|SpaceVim-options-sidebar_width|
|
||||
48. snippet_engine.....................|SpaceVim-options-snippet_engine|
|
||||
49. statusline_iseparator.......|SpaceVim-options-statusline_iseparator|
|
||||
50. statusline_left_sections.|SpaceVim-options-statusline_left_sections|
|
||||
51. statusline_separator.........|SpaceVim-options-statusline_separator|
|
||||
52. statusline_unicode_symbols
|
||||
.................................|SpaceVim-options-statusline_unicode_symbols|
|
||||
51. terminal_cursor_shape.......|SpaceVim-options-terminal_cursor_shape|
|
||||
52. vim_help_language...............|SpaceVim-options-vim_help_language|
|
||||
53. vimcompatible.......................|SpaceVim-options-vimcompatible|
|
||||
54. warning_symbol.....................|SpaceVim-options-warning_symbol|
|
||||
55. windows_index_type.............|SpaceVim-options-windows_index_type|
|
||||
56. windows_leader.....................|SpaceVim-options-windows_leader|
|
||||
57. windows_smartclose.............|SpaceVim-options-windows_smartclose|
|
||||
53. terminal_cursor_shape.......|SpaceVim-options-terminal_cursor_shape|
|
||||
54. vim_help_language...............|SpaceVim-options-vim_help_language|
|
||||
55. vimcompatible.......................|SpaceVim-options-vimcompatible|
|
||||
56. warning_symbol.....................|SpaceVim-options-warning_symbol|
|
||||
57. windows_index_type.............|SpaceVim-options-windows_index_type|
|
||||
58. windows_leader.....................|SpaceVim-options-windows_leader|
|
||||
59. windows_smartclose.............|SpaceVim-options-windows_smartclose|
|
||||
3. Configuration...........................................|SpaceVim-config|
|
||||
4. Commands..............................................|SpaceVim-commands|
|
||||
5. Functions............................................|SpaceVim-functions|
|
||||
@ -372,6 +374,11 @@ SpaceVim default checker is neomake. If you want to use syntastic, use:
|
||||
enable_neomake = false
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
ENABLE_PROJECTS_CACHE *SpaceVim-options-enable_projects_cache*
|
||||
|
||||
Enable/Disable cross session projects cache. Enabled by default.
|
||||
|
||||
==============================================================================
|
||||
ENABLE_STATUSLINE_BFPATH *SpaceVim-options-enable_statusline_bfpath*
|
||||
|
||||
@ -554,6 +561,11 @@ project based on this option. By default it is:
|
||||
['.git/', '_darcs/', '.hg/', '.bzr/', '.svn/']
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
PROJECTS_CACHE_NUM *SpaceVim-options-projects_cache_num*
|
||||
|
||||
Setting the numbers of cached projects, by default it is 20.
|
||||
|
||||
==============================================================================
|
||||
REALTIME_LEADER_GUIDE *SpaceVim-options-realtime_leader_guide*
|
||||
|
||||
@ -1206,6 +1218,12 @@ project based on this option. By default it is:
|
||||
['.git/', '_darcs/', '.hg/', '.bzr/', '.svn/']
|
||||
<
|
||||
|
||||
*g:spacevim_enable_projects_cache*
|
||||
Enable/Disable cross session projects cache. Enabled by default.
|
||||
|
||||
*g:spacevim_projects_cache_num*
|
||||
Setting the numbers of cached projects, by default it is 20.
|
||||
|
||||
*g:spacevim_project_rooter_automatically*
|
||||
Enable/Disable changing directory automatically. Enabled by default.
|
||||
|
||||
|
@ -1818,6 +1818,18 @@ Denite/Unite 是一个强大的信息筛选浏览器,这类似于 Emacs 中的
|
||||
| `SPC p k` | 关闭当前工程的所有缓冲区 |
|
||||
| `SPC p p` | 显示所有工程 |
|
||||
|
||||
`SPC p p` 将会列出最近使用的项目清单,默认会显示最多20个,
|
||||
这一数量可以使用 `projects_cache_num` 来修改。
|
||||
|
||||
为了可以夸 Vim 进程读取历史打开的项目信息,这一功能使用了缓存机制。
|
||||
如果需要禁用这一缓存功能,可以将 `enable_projects_cache` 设为 `false`。
|
||||
|
||||
```toml
|
||||
[options]
|
||||
enable_projects_cache = true
|
||||
projects_cache_num = 20
|
||||
```
|
||||
|
||||
#### 自定义跳转文件
|
||||
|
||||
若要实现自定义文件跳转功能,需要在项目根目录新建一个 `.project_alt.json` 文件,
|
||||
|
@ -1561,7 +1561,8 @@ The structure of searching tool profile is:
|
||||
| `SPC s r p` | rg |
|
||||
| `SPC s r P` | rg with default text |
|
||||
|
||||
**Hint**: It is also possible to search in a project without needing to open a file beforehand. To do so use `SPC p p` and then `C-s` on a given project to directly search into it like with `SPC s p`. (TODO)
|
||||
**Hint**: It is also possible to search in a project without needing to open a file beforehand.
|
||||
To do so use `SPC p p` and then `C-s` on a given project to directly search into it like with `SPC s p`. (TODO)
|
||||
|
||||
#### Background searching in a project
|
||||
|
||||
@ -1859,6 +1860,18 @@ Project manager commands start with `p`:
|
||||
| `SPC p k` | kill all buffers of current project |
|
||||
| `SPC p p` | list all projects |
|
||||
|
||||
`SPC p p` will list all the projects history cross vim sessions. By default
|
||||
only 20 projects will be listed. To increase it, you can change the value
|
||||
of `projects_cache_num`.
|
||||
|
||||
To disable the cross session cacche, change `enable_projects_cache` to `false`.
|
||||
|
||||
```toml
|
||||
[options]
|
||||
enable_projects_cache = true
|
||||
projects_cache_num = 20
|
||||
```
|
||||
|
||||
#### Custom alternate file
|
||||
|
||||
To manager the alternate file of the project, you need to create a `.project_alt.json` file
|
||||
|
Loading…
Reference in New Issue
Block a user