Skip to content
This repository was archived by the owner on Apr 13, 2024. It is now read-only.

Commit 00340be

Browse files
committed
Add <Leader>rh command to show class hierarchy
Displays the class hierarchy in a new window where pressing return on a line opens that location in the other window.
1 parent b86ccb9 commit 00340be

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ It is possible to set its maximum size (number of entries), default is 100:
6767
| &lt;Leader&gt;rp | -U --symbol-info-include-parents | Jump to parent |
6868
| &lt;Leader&gt;rc | --class-hierarchy | Find subclasses |
6969
| &lt;Leader&gt;rC | --class-hierarchy | Find superclasses |
70+
| &lt;Leader&gt;rh | --class-hierarchy | List full class hierarchy |
7071
| &lt;Leader&gt;rf | -e -r | Find references |
7172
| &lt;Leader&gt;rF | -r --containing-function-location| Call tree (o - open node, Enter - jump) |
7273
| &lt;Leader&gt;rn | -ae -R | Find references by name |

plugin/rtags.vim

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ if g:rtagsUseDefaultMappings == 1
9393
noremap <Leader>rw :call rtags#RenameSymbolUnderCursor()<CR>
9494
noremap <Leader>rv :call rtags#FindVirtuals()<CR>
9595
noremap <Leader>rb :call rtags#JumpBack()<CR>
96+
noremap <Leader>rh :call rtags#ShowHierarchy()<CR>
9697
noremap <Leader>rC :call rtags#FindSuperClasses()<CR>
9798
noremap <Leader>rc :call rtags#FindSubClasses()<CR>
9899
noremap <Leader>rd :call rtags#Diagnostics()<CR>
@@ -419,6 +420,57 @@ function! rtags#AddReferences(results, i)
419420
exec (":" . ln)
420421
endfunction
421422

423+
" Creates a viewer for hierarachy results
424+
"
425+
" param[in] results - List of class hierarchy
426+
"
427+
" Hierarchy references have format: <type> <name> <file>:<line>:<col>: <text>
428+
"
429+
function! rtags#ViewHierarchy(results)
430+
let cmd = g:rtagsMaxSearchResultWindowHeight . "new Hierarchy"
431+
silent execute cmd
432+
setlocal noswapfile
433+
setlocal buftype=nowrite
434+
setlocal bufhidden=delete
435+
setlocal nowrap
436+
setlocal tw=0
437+
438+
iabc <buffer>
439+
440+
setlocal modifiable
441+
silent normal ggdG
442+
for record in a:results
443+
silent execute "normal! A\<cr>\<esc>i".record."\<esc>"
444+
endfor
445+
silent normal ggdd
446+
setlocal nomodifiable
447+
448+
let cpo_save = &cpo
449+
set cpo&vim
450+
nnoremap <buffer> <cr> :call <SID>OpenHierarchyLocation()<cr>
451+
let &cpo = cpo_save
452+
endfunction
453+
454+
"
455+
" Opens the location on the current line.
456+
"
457+
" Hierarchy references have format: <type> <name> <file>:<line>:<col>: <text>
458+
"
459+
function! s:OpenHierarchyLocation() " <<<
460+
let ln = line(".")
461+
let l = getline(ln)
462+
if l[0] == ' '
463+
let [type, name, location; rest] = split(l, '\s\+')
464+
let [jump_file, lnum, col; rest] = split(location, ':')
465+
wincmd j
466+
" Add location to the jumplist
467+
normal m'
468+
if rtags#jumpToLocation(jump_file, lnum, col)
469+
normal zz
470+
endif
471+
endif
472+
endfunction " >>>
473+
422474
function! rtags#getRcCmd()
423475
let cmd = g:rtagsRcCmd
424476
let cmd .= " --absolute-path "
@@ -747,6 +799,12 @@ function! rtags#FindRefs()
747799
call rtags#ExecuteThen(args, [function('rtags#DisplayResults')])
748800
endfunction
749801

802+
function! rtags#ShowHierarchy()
803+
let args = {'--class-hierarchy' : rtags#getCurrentLocation() }
804+
805+
call rtags#ExecuteThen(args, [function('rtags#ViewHierarchy')])
806+
endfunction
807+
750808
function! rtags#FindRefsCallTree()
751809
let args = {
752810
\ '--containing-function-location' : '',

0 commit comments

Comments
 (0)