decls.vim 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. let s:save_cpo = &cpoptions
  2. set cpoptions&vim
  3. let s:source = {
  4. \ 'name': 'decls',
  5. \ 'description': 'GoDecls implementation for unite',
  6. \ 'syntax': 'uniteSource__Decls',
  7. \ 'action_table': {},
  8. \ 'hooks': {},
  9. \ }
  10. function! unite#sources#decls#define()
  11. return s:source
  12. endfunction
  13. function! s:source.gather_candidates(args, context) abort
  14. let l:bin_path = go#path#CheckBinPath('motion')
  15. if empty(l:bin_path)
  16. return []
  17. endif
  18. let l:path = expand(get(a:args, 0, '%:p:h'))
  19. if isdirectory(l:path)
  20. let l:mode = 'dir'
  21. elseif filereadable(l:path)
  22. let l:mode = 'file'
  23. else
  24. return []
  25. endif
  26. let l:include = get(g:, 'go_decls_includes', 'func,type')
  27. let l:command = printf('%s -format vim -mode decls -include %s -%s %s', l:bin_path, l:include, l:mode, shellescape(l:path))
  28. let l:candidates = []
  29. try
  30. let l:result = eval(unite#util#system(l:command))
  31. let l:candidates = get(l:result, 'decls', [])
  32. catch
  33. call unite#print_source_error(['command returned invalid response.', v:exception], s:source.name)
  34. endtry
  35. return map(l:candidates, "{
  36. \ 'word': printf('%s :%d :%s', fnamemodify(v:val.filename, ':~:.'), v:val.line, v:val.full),
  37. \ 'kind': 'jump_list',
  38. \ 'action__path': v:val.filename,
  39. \ 'action__line': v:val.line,
  40. \ 'action__col': v:val.col,
  41. \ }")
  42. endfunction
  43. function! s:source.hooks.on_syntax(args, context) abort
  44. syntax match uniteSource__Decls_Filepath /[^:]*\ze:/ contained containedin=uniteSource__Decls
  45. syntax match uniteSource__Decls_Line /\d\+\ze :/ contained containedin=uniteSource__Decls
  46. syntax match uniteSource__Decls_WholeFunction /\vfunc %(\([^)]+\) )?[^(]+/ contained containedin=uniteSource__Decls
  47. syntax match uniteSource__Decls_Function /\S\+\ze(/ contained containedin=uniteSource__Decls_WholeFunction
  48. syntax match uniteSource__Decls_WholeType /type \S\+/ contained containedin=uniteSource__Decls
  49. syntax match uniteSource__Decls_Type /\v( )@<=\S+/ contained containedin=uniteSource__Decls_WholeType
  50. highlight default link uniteSource__Decls_Filepath Comment
  51. highlight default link uniteSource__Decls_Line LineNr
  52. highlight default link uniteSource__Decls_Function Function
  53. highlight default link uniteSource__Decls_Type Type
  54. syntax match uniteSource__Decls_Separator /:/ contained containedin=uniteSource__Decls conceal
  55. syntax match uniteSource__Decls_SeparatorFunction /func / contained containedin=uniteSource__Decls_WholeFunction conceal
  56. syntax match uniteSource__Decls_SeparatorType /type / contained containedin=uniteSource__Decls_WholeType conceal
  57. endfunction
  58. let &cpoptions = s:save_cpo
  59. unlet s:save_cpo
  60. " vim: sw=2 ts=2 et