mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-02 23:40:06 +08:00
Add alt file plugin (#2416)
This commit is contained in:
parent
be1ce0cbb3
commit
1b7c6b56e6
@ -24,3 +24,5 @@ function! s:language_specified_mappings() abort
|
|||||||
\ 'execute current file', 1)
|
\ 'execute current file', 1)
|
||||||
endfunction
|
endfunction
|
||||||
call SpaceVim#mapping#space#regesit_lang_mappings('vader', function('s:language_specified_mappings'))
|
call SpaceVim#mapping#space#regesit_lang_mappings('vader', function('s:language_specified_mappings'))
|
||||||
|
call SpaceVim#plugins#a#set_config_name('.projections.json')
|
||||||
|
|
||||||
|
@ -219,8 +219,17 @@ function! s:updatefiles(files) abort
|
|||||||
return failed
|
return failed
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
let s:file['updateFiles'] = function('s:updatefiles')
|
let s:file['updateFiles'] = function('s:updatefiles')
|
||||||
|
|
||||||
|
function! s:unify_path(path, ...) abort
|
||||||
|
let mod = a:0 > 0 ? a:1 : ':p'
|
||||||
|
return resolve(fnamemodify(a:path, mod . ':gs?[\\/]?/?'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
let s:file['unify_path'] = function('s:unify_path')
|
||||||
|
|
||||||
|
|
||||||
function! SpaceVim#api#file#get() abort
|
function! SpaceVim#api#file#get() abort
|
||||||
return deepcopy(s:file)
|
return deepcopy(s:file)
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -34,8 +34,6 @@ function! SpaceVim#layers#core#plugins() abort
|
|||||||
\'on_map' : '<Plug>(openbrowser-',
|
\'on_map' : '<Plug>(openbrowser-',
|
||||||
\ 'loadconf' : 1,
|
\ 'loadconf' : 1,
|
||||||
\}])
|
\}])
|
||||||
call add(plugins, ['tpope/vim-projectionist', { 'on_cmd' : ['A', 'AS', 'AV',
|
|
||||||
\ 'AT', 'AD', 'Cd', 'Lcd', 'ProjectDo']}])
|
|
||||||
call add(plugins, ['mhinz/vim-grepper' , { 'on_cmd' : 'Grepper',
|
call add(plugins, ['mhinz/vim-grepper' , { 'on_cmd' : 'Grepper',
|
||||||
\ 'loadconf' : 1} ])
|
\ 'loadconf' : 1} ])
|
||||||
return plugins
|
return plugins
|
||||||
|
74
autoload/SpaceVim/plugins/a.vim
Normal file
74
autoload/SpaceVim/plugins/a.vim
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
let s:CMP = SpaceVim#api#import('vim#compatible')
|
||||||
|
let s:JSON = SpaceVim#api#import('data#json')
|
||||||
|
let s:FILE = SpaceVim#api#import('file')
|
||||||
|
let s:conf = '.project_alt.json'
|
||||||
|
|
||||||
|
let s:project_config = {}
|
||||||
|
|
||||||
|
function! SpaceVim#plugins#a#set_config_name(name)
|
||||||
|
|
||||||
|
let s:conf = a:name
|
||||||
|
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! SpaceVim#plugins#a#alt()
|
||||||
|
let conf_file = s:FILE.unify_path(s:conf, ':p')
|
||||||
|
let file = s:FILE.unify_path(bufname('%'), ':.')
|
||||||
|
let alt = SpaceVim#plugins#a#get_alt(file, conf_file)
|
||||||
|
if !empty(alt)
|
||||||
|
exe 'e ' . alt
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:paser(conf, root) abort
|
||||||
|
for key in keys(a:conf)
|
||||||
|
for file in s:CMP.globpath('.', substitute(key, '*', '**/*', 'g'))
|
||||||
|
let file = s:FILE.unify_path(file, ':.')
|
||||||
|
if has_key(a:conf, file)
|
||||||
|
if has_key(a:conf[file], 'alternate')
|
||||||
|
let s:project_config[a:root][file] = {'alternate' : a:conf[file]['alternate']}
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
let conf = a:conf[key]
|
||||||
|
if has_key(conf, 'alternate')
|
||||||
|
let begin_end = split(key, '*')
|
||||||
|
if len(begin_end) == 2
|
||||||
|
let s:project_config[a:root][file] = {'alternate' : s:add_alternate_file(begin_end, file, a:conf[key]['alternate'])}
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:add_alternate_file(a, f, b) abort
|
||||||
|
let begin_len = strlen(a:a[0])
|
||||||
|
let end_len = strlen(a:a[1])
|
||||||
|
"docs/*.md": {"alternate": "docs/cn/{}.md"},
|
||||||
|
"begin_end = 5
|
||||||
|
"end_len = 3
|
||||||
|
"docs/index.md
|
||||||
|
return substitute(a:b, '{}', a:f[begin_len : (end_len+1) * -1], 'g')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! Log() abort
|
||||||
|
return s:project_config
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! SpaceVim#plugins#a#get_alt(file, root)
|
||||||
|
if !has_key(s:project_config, a:root)
|
||||||
|
let altconfa = s:JSON.json_decode(join(readfile(a:root), "\n"))
|
||||||
|
let s:project_config[a:root] = {}
|
||||||
|
call s:paser(altconfa, a:root)
|
||||||
|
endif
|
||||||
|
try
|
||||||
|
return s:project_config[a:root][a:file]['alternate']
|
||||||
|
catch
|
||||||
|
return ''
|
||||||
|
endtry
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
function! SpaceVim#plugins#a#get_root()
|
||||||
|
return s:FILE.unify_path(s:conf, ':p')
|
||||||
|
endfunction
|
10
codecov.yml
10
codecov.yml
@ -10,7 +10,13 @@ coverage:
|
|||||||
project:
|
project:
|
||||||
default: false # disable the default status that measures entire project
|
default: false # disable the default status that measures entire project
|
||||||
api: # declare a new status context "api"
|
api: # declare a new status context "api"
|
||||||
target: 70% # we always want 100% coverage here
|
target: 35% # we always want 100% coverage here
|
||||||
paths: "autoload/SpaceVim/api/" # only include coverage in "tests/" folder
|
paths: "autoload/SpaceVim/api/" # only include coverage in "tests/" folder
|
||||||
app: # declare a new status context "app"
|
leyer: # declare a new status context "api"
|
||||||
|
target: 35% # we always want 100% coverage here
|
||||||
|
paths: "autoload/SpaceVim/layers/" # only include coverage in "tests/" folder
|
||||||
|
plugins: # declare a new status context "api"
|
||||||
|
target: 35% # we always want 100% coverage here
|
||||||
|
paths: "autoload/SpaceVim/plugins/" # only include coverage in "tests/" folder
|
||||||
|
all: # declare a new status context "app"
|
||||||
paths: "!tests/" # remove all files in "tests/"
|
paths: "!tests/" # remove all files in "tests/"
|
||||||
|
@ -8,3 +8,5 @@ command! -nargs=* -complete=custom,zvim#util#complete_plugs Plugin :call zvim#ut
|
|||||||
command! -nargs=+ -complete=custom,zvim#util#complete_project OpenProject :call zvim#util#OpenProject(<f-args>)
|
command! -nargs=+ -complete=custom,zvim#util#complete_project OpenProject :call zvim#util#OpenProject(<f-args>)
|
||||||
|
|
||||||
command! -nargs=* -complete=custom,SpaceVim#plugins#pmd#complete PMD :call SpaceVim#plugins#pmd#run(<f-args>)
|
command! -nargs=* -complete=custom,SpaceVim#plugins#pmd#complete PMD :call SpaceVim#plugins#pmd#run(<f-args>)
|
||||||
|
|
||||||
|
command! -nargs=0 A :call SpaceVim#plugins#a#alt()
|
||||||
|
@ -62,7 +62,7 @@ pip install --user isort
|
|||||||
|
|
||||||
### 工程文件跳转
|
### 工程文件跳转
|
||||||
|
|
||||||
工程文件跳转,主要依赖 vim-projectionist, 需要在项目根目录加入 .projections.json 文件,标记源文件和测试文件之间的关系。
|
SpaceVim 自带工程管理插件,可以识别项目根目录,自动跳转alternate文件。
|
||||||
|
|
||||||
### 快速运行
|
### 快速运行
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ lang: cn
|
|||||||
## 功能特性
|
## 功能特性
|
||||||
|
|
||||||
- 语法高亮
|
- 语法高亮
|
||||||
- lsp 支持(需要 [lsp](/cn/layers/language-server-protocol/) 模块)
|
- lsp 支持(需要 [lsp](../../language-server-protocol/) 模块)
|
||||||
|
|
||||||
## 启用模块
|
## 启用模块
|
||||||
|
|
||||||
|
@ -1792,7 +1792,7 @@ Custom sign symbol:
|
|||||||
|
|
||||||
### Managing projects
|
### Managing projects
|
||||||
|
|
||||||
Projects in SpaceVim are managed by vim-projectionist and vim-rooter, vim-rooter will find the root of the project when a `.git` directory or a `.projections.json` file is encountered in the file tree.
|
SpaceVim will find the root of the project when a `.git` directory or a `.project_alt.json` file is encountered in the file tree.
|
||||||
|
|
||||||
project manager commands start with `p`:
|
project manager commands start with `p`:
|
||||||
|
|
||||||
|
12
test/plugin/a.vader
Normal file
12
test/plugin/a.vader
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
Execute ( SpaceVim plugin: a.vim ):
|
||||||
|
call SpaceVim#plugins#a#set_config_name('.projections.json')
|
||||||
|
let root = SpaceVim#plugins#a#get_root()
|
||||||
|
AssertEqual SpaceVim#plugins#a#get_alt('docs/index.md', root), 'docs/cn/index.md'
|
||||||
|
AssertEqual SpaceVim#plugins#a#get_alt('docs/cn/index.md', root), 'docs/index.md'
|
||||||
|
AssertEqual SpaceVim#plugins#a#get_alt('docs/api/job.md', root), 'docs/cn/api/job.md'
|
||||||
|
AssertEqual SpaceVim#plugins#a#get_alt('docs/cn/api/job.md', root), 'docs/api/job.md'
|
||||||
|
AssertEqual SpaceVim#plugins#a#get_alt('wiki/en/Project-layout.md', root), 'wiki/cn/Project-layout.md'
|
||||||
|
AssertEqual SpaceVim#plugins#a#get_alt('wiki/cn/Project-layout.md', root), 'wiki/en/Project-layout.md'
|
||||||
|
AssertEqual SpaceVim#plugins#a#get_alt('docs/_posts/2018-09-28-use-vim-as-ide.md', root), 'docs/_posts/2018-09-27-use-vim-as-ide.md'
|
||||||
|
unlet root
|
||||||
|
|
Loading…
Reference in New Issue
Block a user