@@ -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 )
420421endfunction
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+
422474function ! 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' )])
748800endfunction
749801
802+ function ! rtags#ShowHierarchy ()
803+ let args = {' --class-hierarchy' : rtags#getCurrentLocation () }
804+
805+ call rtags#ExecuteThen (args , [function (' rtags#ViewHierarchy' )])
806+ endfunction
807+
750808function ! rtags#FindRefsCallTree ()
751809 let args = {
752810 \ ' --containing-function-location' : ' ' ,
0 commit comments