From 7fe165cbc6da15c3702594000aa0a200235b2508 Mon Sep 17 00:00:00 2001 From: Anthony Naddeo Date: Sun, 6 Nov 2016 12:44:47 -0800 Subject: [PATCH] First pass at ctags integration This adds a bunch of ctag kinds that I find useful for myself. Configuration options: g:elm_ctags_config - Location of the .cnf file that ctags uses. By default, it is defaulting to the one that I've added to this repo. I added this option because people may have their own ~/.ctags file with elm configuration (and other languages) already, which causes tagbar to show duplicate entires. g:elm_ctags_target_dirs - The directories that should be indexed by ctags. By default, I made it ./elm-stuff and ./src so that people can jump around their own source as well as the core library stuff. g:elm_ctags_exe - Name of the ctags executable, just so people can point it to /usr/local/bin or something. Outstanding issues: * No scope features * No idea how to support signatures in ctags. I really just wanted signatures to show up in tagbar. I was able to get it working by changing the .cnf to create tag names like `MyFunc (A -> B)`, but then those are then interpreted as actual tags, so you can't jump around using in Vim. I'm considering having two .cnf files: one for generating the `tags` file and one for use with tagbar to get around it. The ctags documentation mentions the --fields+S options, but it also says that it only works for C family languages and there doesn't seem to be a way of adding it via the `--regex-` flags. Hack to make sure that imports don't define tags Currently, `import Html` will make vim jump to the import statement instead of the Html module. This hack will make sure that the tag generated in the import statement doesn't get jumped to. --- ftplugin/elm/ctags/elm.cnf | 11 +++++++++++ ftplugin/elm/tagbar.vim | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 ftplugin/elm/ctags/elm.cnf diff --git a/ftplugin/elm/ctags/elm.cnf b/ftplugin/elm/ctags/elm.cnf new file mode 100644 index 0000000..09b3d4a --- /dev/null +++ b/ftplugin/elm/ctags/elm.cnf @@ -0,0 +1,11 @@ +--langdef=Elm +--langmap=Elm:.elm +--regex-Elm=/^ *([a-z][a-zA-Z0-9_-]+)[ \t ]*:[^:].*->(.*)/\1/f,function,functions type declarations,S:String s/ +--regex-Elm=/^ *([a-z][a-zA-Z0-9_-]+)[ \t ]*:([^:][^-]+)$/\1/c,constant,constants/ +--regex-Elm=/^port *([a-z][a-zA-Z0-9_-]+)[ \t ]*:[^:]/\1/p,port,ports/ +--regex-Elm=/^type *([A-Z][a-zA-Z0-9_-]*)/\1/t,type/ +--regex-Elm=/^type alias *([A-Z][a-zA-Z0-9_-]*)/\1/t,type,Declared types/ +--regex-Elm=/[ \r\n\t][\|=][ \r\n\t]*([A-Z][a-zA-Z0-9_-]*)(.*)/\1/C,constructor,constructors created by types/ +--regex-Elm=/^module *([A-Z][.a-zA-Z0-9_-]*)/\1/m,module,module definitions/ +--regex-Elm=/^import *([A-Z][.a-zA-Z0-9_-]*)(.*as *([A-Z][.a-zA-Z0-9_-]*))?.*(\(.*\))*/\1 (\2)/i,import,imported modules/ + diff --git a/ftplugin/elm/tagbar.vim b/ftplugin/elm/tagbar.vim index fa69fd1..1efed43 100644 --- a/ftplugin/elm/tagbar.vim +++ b/ftplugin/elm/tagbar.vim @@ -4,11 +4,34 @@ elseif globpath(&rtp, 'plugin/tagbar.vim') == "" finish endif +if !exists("g:elm_ctags_config") + let g:elm_ctags_config = expand(':p:h:h') . '/elm/ctags/elm.cnf' +endif + +if !exists("g:elm_ctags_target_dirs") + let g:elm_ctags_target_dirs = './elm-stuff ./src' +endif + +if !exists("g:elm_ctags_exe") + let g:elm_ctags_exe = 'ctags-exuberant' +endif + +function! GenerateElmTags() + exec system(g:elm_ctags_exe . ' -R --fields=+l --options=' . g:elm_ctags_config . ' ' . g:elm_ctags_target_dirs) +endfunction +command! ElmGenerateTags call GenerateElmTags() + +let g:Plugin_install_dir = expand(':p:h:h') function! s:SetTagbar() if !exists("g:tagbar_type_elm") let g:tagbar_type_elm = { \ 'ctagstype' : 'elm', + \ 'deffile' : g:elm_ctags_config, \ 'kinds' : [ + \ 'm:module', + \ 'i:imports', + \ 't:types', + \ 'C:constructors', \ 'c:constants', \ 'f:functions', \ 'p:ports'