Skip to content

Commit

Permalink
Add ctags tool layer
Browse files Browse the repository at this point in the history
  • Loading branch information
rene-descartes2021 committed Sep 29, 2022
1 parent 02d4c74 commit 9080ed6
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 9 deletions.
6 changes: 0 additions & 6 deletions core/autoload/spacevim/autocmd/gutentags.vim
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,11 @@ if !isdirectory(s:vim_tags)
silent! call mkdir(s:vim_tags, 'p')
endif

let g:spacevim#vim#ctags#cache_dir = s:vim_tags

function! spacevim#autocmd#gutentags#Init()
let g:gutentags_ctags_tagfile = '.tags'
" set default tags file name `tags` to `.tags`
set tags=./.tags;,.tags

let g:gutentags_ctags_extra_args = ['--fields=+niazS', '--extra=+q']
let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
let g:gutentags_ctags_extra_args += ['--c-kinds=+px']

let g:gutentags_modules = s:modules

" Specifies a directory in which to create all the tags files
Expand Down
16 changes: 16 additions & 0 deletions layers/+tools/ctags/config.vim
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
execute 'source '.fnamemodify(expand('<sfile>'), ':h').'/native-dependency.vim'

if spacevim#vim#plug#LocateDependency('ctags')[0] ==# 'none'
call spacevim#util#warn('ctags layer failure, try ":call dein#get('.
\ '"libyaml").hook_post_update()" to build ctags+libyaml as plugin,'.
\ ' or set $PATH to existing build, or install system-wide with '.
\ 'version >= '.join(g:spacevim#vim#plug#native_dependency[
\ 'ctags'].v_req, '.').'.')
endif

" vim-gutentags {
let g:gutentags_ctags_extra_args = get(g:, 'gutentags_ctags_extra_args', [])
let g:gutentags_ctags_extra_args += ['--fields=+niazS', '--extras=+q',
\ '--excmd=number', '--tag-relative=yes']
let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
let g:gutentags_ctags_extra_args += ['--c-kinds=+px']
" }
126 changes: 126 additions & 0 deletions layers/+tools/ctags/native-dependency.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
" Need to add libyaml/install/lib to LD_LIBRARY_PATH for ctags runtime
" but dein doesn't manage plugpath once built, so look at state
" For spacevim#vim#plug#LocateDependency in packages.vim and cache.vim
let f = g:spacevim.state_base.'libyaml_state'
if filereadable(f)
let p = readfile(f)
if len(p) > 0
if match($LD_LIBRARY_PATH, '\V'.p[0]) == -1
let $LD_LIBRARY_PATH .= (empty($LD_LIBRARY_PATH) ? '' :
\ spacevim#util#PathEnvSep()).p[0]
endif
endif
endif

function! BuildCtags(native) abort
if executable('rst2man') != 1
call spacevim#util#info('Unable to build ctags man pages unless '.
\ 'rst2man in python3-docutils is installed.')
endif

if a:native.posix_compiler
execute 'tcd' a:native.plugpath
let autoconf_log = a:native.temppath.'/ctags_autoconf.log'
call system('./autogen.sh > '.autoconf_log)
call rename(autoconf_log, a:native.plugpath.'/autoconf.log')

execute 'tcd build'
let configure_log = a:native.temppath.'/ctags_configure.log'
call system(a:native.plugpath.'/configure --enable-yaml --prefix='.
\ a:native.plugpath.'/install > '.configure_log)
call rename(configure_log, a:native.plugpath.'/configure.log')
call execute('AsyncRun -cwd='.a:native.plugpath.'/build '.
\ '-mode=term -pos=tab -program=make -post='.
\ 'call\ spacevim\#vim\#plug\#PostBuild(code,\ ''ctags'') @ '.
\ 'install'.a:native.jobs_flag)
endif
endfunction

function! PostBuildCtags(native) abort
call delete('autom4te.cache', 'rf')
call delete('gnulib', 'rf')
call delete('man', 'rf')
call delete('aclocal.m4')
call delete('config.guess')
call delete('config.h.in')
call delete('config.h.in~')
call delete('config.sub')
call delete('configure')
call delete('depcomp')
call delete('install-sh')
call delete('last-aclocal.m4')
call delete('Makefile.in')
call delete('missing')
endfunction

function! BuildYaml(native) abort
if executable('autoconf') != 1
call spacevim#util#info('Unable to build libyaml, requires'.
\ ' autoconf. After rectifying try `:call '.
\ 'dein#get(''libyaml'').hook_post_update()`')
else
if a:native.posix_compiler
execute 'tcd' a:native.plugpath
let autoconf_log = a:native.temppath.'/libyaml_autoconf.log'
call system('./bootstrap > '.autoconf_log)
call rename(autoconf_log, a:native.plugpath.'/autoconf.log')

execute 'tcd build'
let configure_log = a:native.temppath.'/libyaml_configure.log'
call system(a:native.plugpath.'/configure --prefix='.
\ a:native.plugpath.'/install > '.configure_log)
call rename(configure_log, a:native.plugpath.'/configure.log')
call execute('AsyncRun -cwd='.a:native.plugpath.'/build '.
\ '-mode=term -pos=tab -program=make -post='.
\ 'call\ spacevim\#vim\#plug\#PostBuild(code,\ ''libyaml'') @ '.
\ 'install'.a:native.jobs_flag)
endif
endif
endfunction

function! PostBuildYaml(native) abort
if a:native.posix_compiler
" And PKG_CONFIG_PATH so that ctags configure can find libyaml
" And LD_LIBRARY_PATH so that library can be found at runtime
let ps = spacevim#util#PathSep()
let eps = spacevim#util#PathEnvSep()
let l = a:native.plugpath.ps.'install'.ps.'lib'
let $PKG_CONFIG_PATH .= (empty($PKG_CONFIG_PATH) ? '' : eps).l.'/pkgconfig'
let $LD_LIBRARY_PATH .= (empty($LD_LIBRARY_PATH) ? '' : eps).l
" Put into a statefile so that it can be loaded before version check
let f = g:spacevim.state_base.'libyaml_state'
call writefile([l], f, 'S')
endif
call delete('autom4te.cache', 'rf')
call delete('config', 'rf')
call delete('include', 'rf')
call delete('src', 'rf')
call delete('tests', 'rf')
call delete('aclocal.m4')
call delete('configure')
call delete('Makefile.in')
" Can't rely on dein to wait for libyaml to build to then build ctags
execute 'tcd' a:native.cwd
call spacevim#vim#plug#Build('ctags')
endfunction

let g:spacevim#vim#plug#native_dependency = get(g:,
\ 'spacevim#vim#plug#native_dependency', {})
" Unfortunately plugin built ctags doesn't include YYYYMMDD versioning
"\ vregex: '\V\%(p\)\@<=\(\[0-9]\+\).\(\[0-9]\+\).\(\[0-9]\{4}\)'.
" \ '\(\[0-9]\{2}\)\(\[0-9]\{2}\)',
"\ v_req: [5, 9, 2022, 8, 7],
let g:spacevim#vim#plug#native_dependency['ctags'] = {
\ 'bin': 'ctags',
\ 'repo': 'universal-ctags/ctags',
\ 'vregex': '\V\^Universal Ctags \(\[0-9]\+\).\(\[0-9]\+\).\(\[0-9]\+\)(',
\ 'v_req': [5, 9, 0],
\ 'feature_req': ['--list-features', '\V\nyaml'],
\ 'Build': function('BuildCtags'),
\ 'PostBuild': function('PostBuildCtags'),
\ }
let g:spacevim#vim#plug#native_dependency['libyaml'] = {
\ 'repo': 'yaml/libyaml',
\ 'Build': function('BuildYaml'),
\ 'PostBuild': function('PostBuildYaml'),
\ }
12 changes: 11 additions & 1 deletion layers/+tools/ctags/packages.vim
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
MP 'ludovicchabant/vim-gutentags', { 'on_ft': ['c', 'cpp'],
MP 'ludovicchabant/vim-gutentags', { 'on_ft': ['c', 'cpp', 'cs'],
\ 'hook_source': function('spacevim#autocmd#gutentags#Init') }

execute 'source '.fnamemodify(expand('<sfile>'), ':h').'/native-dependency.vim'

if spacevim#vim#plug#LocateDependency('ctags')[0] ==# 'none'
" Note: 'depends' loading order not guaranteed for non-lazy plugins
MP 'universal-ctags/ctags', { 'merged': v:false, 'rtp': '',
\ 'depends': 'yaml/libyaml', 'lazy': v:true }
MP 'yaml/libyaml', { 'merged': v:false, 'rtp': '',
\ 'hook_post_update': function('spacevim#vim#plug#Build', ['libyaml']) }
endif
4 changes: 2 additions & 2 deletions layers/LAYERS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Layer Manifest
==============

Last updated: 2022-09-29 12:39:45
Last updated: 2022-09-29 16:50:50

Default layers: `fzf`, `better-defaults` and `which-key`.

Expand Down Expand Up @@ -47,7 +47,7 @@ Topic | Layer | Plugins
+themes | [airline](https://github.com/liuchengxu/space-vim/tree/master/layers/+themes/airline) | <ul><li>[vim-airline/vim-airline](https://github.com/vim-airline/vim-airline)</li><li>[vim-airline/vim-airline-themes](https://github.com/vim-airline/vim-airline-themes)</li></ul>
+themes | [lightline](https://github.com/liuchengxu/space-vim/tree/master/layers/+themes/lightline) | <ul><li>[itchyny/lightline.vim](https://github.com/itchyny/lightline.vim)</li></ul>
+tools | [cscope](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/cscope) | <ul><li>[romainl/vim-qf](https://github.com/romainl/vim-qf)</li></ul>
+tools | [ctags](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/ctags) | <ul><li>[ludovicchabant/vim-gutentags](https://github.com/ludovicchabant/vim-gutentags)</li></ul>
+tools | [ctags](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/ctags) | <ul><li>[ludovicchabant/vim-gutentags](https://github.com/ludovicchabant/vim-gutentags)</li><li>[universal-ctags/ctags](https://github.com/universal-ctags/ctags)</li><li>[yaml/libyaml](https://github.com/yaml/libyaml)</li></ul>
+tools | [docker](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/docker) | <ul><li>[ekalinin/Dockerfile.vim](https://github.com/ekalinin/Dockerfile.vim)</li></ul>
+tools | [file-manager](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/file-manager) | <ul><li>[Xuyuanp/nerdtree-git-plugin](https://github.com/Xuyuanp/nerdtree-git-plugin)</li><li>[danro/rename.vim](https://github.com/danro/rename.vim)</li><li>[liuchengxu/nerdtree-dash](https://github.com/liuchengxu/nerdtree-dash)</li><li>[ryanoasis/vim-devicons](https://github.com/ryanoasis/vim-devicons)</li><li>[scrooloose/nerdtree](https://github.com/scrooloose/nerdtree)</li><li>[tiagofumo/vim-nerdtree-syntax-highlight](https://github.com/tiagofumo/vim-nerdtree-syntax-highlight)</li></ul>
+tools | [fzf](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/fzf) | <ul><li>[Yggdroot/LeaderF](https://github.com/Yggdroot/LeaderF)</li><li>[junegunn/fzf](https://github.com/junegunn/fzf)</li><li>[junegunn/fzf.vim](https://github.com/junegunn/fzf.vim)</li><li>[liuchengxu/vim-clap](https://github.com/liuchengxu/vim-clap)</li><li>[vn-ki/coc-clap](https://github.com/vn-ki/coc-clap)</li></ul>
Expand Down

0 comments on commit 9080ed6

Please sign in to comment.