Skip to content

Commit 8eb5eeb

Browse files
author
Gaspar Chilingarov
committed
Configure Tabbar to show arity and also separate OTP functions
1 parent 2373361 commit 8eb5eeb

1 file changed

Lines changed: 76 additions & 5 deletions

File tree

plugin/vim-ide-elixir.vim

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"
1+
"
22
" vim: et ts=2 sts=2 sw=2
33
"
44

@@ -21,22 +21,93 @@ let s:bundle_path = s:path."/bundle"
2121
" "runtime(s:bundle_path)
2222
"endif
2323

24+
25+
function! Tag_transform(tags)
26+
" remove OTP callbacks from ordinary function list
27+
call filter(a:tags, ' !(v:val.fields.kind == "f" && v:val.name =~ "\\v(handle_call|handle_info|handle_cast|init|terminate)") ')
28+
29+
function! Arity_extract(idx, tag)
30+
if a:tag.fields.kind == 'f' || a:tag.fields.kind == 'g'
31+
let args_string = substitute(a:tag.pattern, "^.*".a:tag.name."[ \t]*", "", "")
32+
let args_string = substitute(args_string, "do[ \t]*\\\\[$]$", "", "")
33+
let args_string = substitute(args_string, "[ \t]*", "", "g")
34+
35+
let args_len = len(args_string)
36+
37+
if args_len == 0
38+
let a:tag.name = a:tag.name."/0"
39+
else
40+
let old_args_len = -10000
41+
while args_len != old_args_len
42+
let args_string = substitute(args_string, "{[^}]*}", "", "g")
43+
let args_string = substitute(args_string, "\\[[^]]*\\]", "", "g")
44+
let old_args_len = args_len
45+
let args_len = len(args_string)
46+
echo(args_string)
47+
endwhile
48+
49+
let comma_count = len(substitute(args_string, "[^,]", "", "g"))
50+
let a:tag.name = a:tag.name . "/" . (comma_count + 1)
51+
endif
52+
53+
return a:tag
54+
else
55+
return a:tag
56+
endif
57+
endfunction
58+
59+
" replaces function names with function_name/arity notation
60+
call map(a:tags, function('Arity_extract'))
61+
62+
let seen_list = map(copy(a:tags), '[v:val.fields.kind, v:val.name, v:val.fields.line]')
63+
64+
let seen_fnames = {}
65+
for [kind, fname, line] in seen_list
66+
if ! has_key(seen_fnames, kind.fname)
67+
let seen_fnames[kind.fname] = line
68+
endif
69+
endfor
70+
71+
" leaves only first definition of function with same arity
72+
function! Filter_fun(seen_hash, idx, tag)
73+
let key = a:tag.fields.kind . a:tag.name
74+
let line = a:tag.fields.line
75+
76+
return a:seen_hash[key] == line
77+
endfunction
78+
79+
call filter(a:tags, function('Filter_fun', [seen_fnames]))
80+
81+
return a:tags
82+
endfunction
83+
84+
2485
let g:tagbar_type_elixir = {
2586
\ 'ctagstype' : 'elixir',
2687
\ 'deffile' : s:path . '/extras/elixir-ctags/.ctags',
88+
\ 'transform': function("Tag_transform"),
2789
\ 'kinds' : [
28-
\ 'f:functions',
29-
\ 'functions:functions',
90+
\ 'm:modules',
91+
\ 'O:OTP callbacks',
92+
\ 't:tests',
93+
\ 'f:functions (public)',
94+
\ 'g:functions (private)',
3095
\ 'c:callbacks',
3196
\ 'd:delegates',
3297
\ 'e:exceptions',
3398
\ 'i:implementations',
3499
\ 'a:macros',
35100
\ 'o:operators',
36-
\ 'm:modules',
101+
\ 's:structs',
37102
\ 'p:protocols',
38-
\ 'r:records'
103+
\ 'r:records',
104+
\ 'T:types',
105+
\ 'z:foo'
39106
\ ]
40107
\ }
41108

42109
set updatetime=500
110+
111+
" keyboard shortcuts
112+
nmap <F4> :TagbarToggle<CR>
113+

0 commit comments

Comments
 (0)