Skip to content

Commit 3a5ee90

Browse files
authored
Merge pull request #4221 from bstaletic/hierarchies
[READY] Implement type/call hierarchy handling
2 parents 4556062 + 25ec3c9 commit 3a5ee90

16 files changed

+918
-84
lines changed

README.md

+69-7
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Contents
6767
- [Diagnostic Display](#diagnostic-display)
6868
- [Diagnostic Highlighting Groups](#diagnostic-highlighting-groups)
6969
- [Symbol Search](#symbol-search)
70+
- [Type/Call Hierarchy](#typecall-hierarchy)
7071
- [Commands](#commands)
7172
- [YcmCompleter subcommands](#ycmcompleter-subcommands)
7273
- [GoTo Commands](#goto-commands)
@@ -677,6 +678,8 @@ Quick Feature Summary
677678
* Code formatting (`Format`)
678679
* Semantic highlighting
679680
* Inlay hints
681+
* Type hierarchy
682+
* Call hierarchy
680683

681684
### C♯
682685

@@ -720,6 +723,8 @@ Quick Feature Summary
720723
* Type information for identifiers (`GetType`)
721724
* Code formatting (`Format`)
722725
* Management of `gopls` server instance
726+
* Inlay hints
727+
* Call hierarchy
723728

724729
### JavaScript and TypeScript
725730

@@ -741,6 +746,7 @@ Quick Feature Summary
741746
* Organize imports (`OrganizeImports`)
742747
* Management of `TSServer` server instance
743748
* Inlay hints
749+
* Call hierarchy
744750

745751
### Rust
746752

@@ -759,6 +765,7 @@ Quick Feature Summary
759765
* Management of `rust-analyzer` server instance
760766
* Semantic highlighting
761767
* Inlay hints
768+
* Call hierarchy
762769

763770
### Java
764771

@@ -782,6 +789,9 @@ Quick Feature Summary
782789
* Execute custom server command (`ExecuteCommand <args>`)
783790
* Management of `jdt.ls` server instance
784791
* Semantic highlighting
792+
* Inlay hints
793+
* Type hierarchy
794+
* Call hierarchy
785795

786796
User Guide
787797
----------
@@ -913,10 +923,6 @@ Ctrl-l is not a suggestion, just an example.
913923

914924
### Semantic highlighting
915925

916-
**NOTE**: This feature is highly experimental and offered in the hope that it is
917-
useful. It shall not be considered stable; if you find issues with it, feel free
918-
to report them, however.
919-
920926
Semantic highlighting is the process where the buffer text is coloured according
921927
to the underlying semantic type of the word, rather than classic syntax
922928
highlighting based on regular expressions. This can be powerful additional data
@@ -1883,6 +1889,61 @@ so you can use window commands `<C-w>...` for example.
18831889
for that, or use a window command (e.g. `<Ctrl-w>j`) or the mouse to leave the
18841890
prompt buffer window.
18851891

1892+
### Type/Call Hierarchy
1893+
1894+
***This feature requires Vim and is not supported in Neovim***
1895+
1896+
**NOTE**: This feature is highly experimental and offered in the hope that it is
1897+
useful. Please help us by reporting issues and offering feedback.
1898+
1899+
YCM provides a way to view and navigate hierarchies. The following hierarchies
1900+
are supported:
1901+
1902+
* Type hierachy `<Plug>(YCMTypeHierarchy)`: Display subtypes and supertypes
1903+
of the symbol under cursor. Expand down to subtypes and up to supertypes.
1904+
* Call hierarchy `<Plug>(YCMCallHierarchy)`: Display callees and callers of
1905+
the symbol under cursor. Expand down to callers and up to callees.
1906+
1907+
Take a look at this [![asciicast](https://asciinema.org/a/659925.svg)](https://asciinema.org/a/659925)
1908+
for brief demo.
1909+
1910+
Hierarchy UI can be initiated by mapping something to the indicated plug
1911+
mappings, for example:
1912+
1913+
```viml
1914+
nmap <leader>yth <Plug>(YCMTypeHierarchy)
1915+
nmap <leader>ych <Plug>(YCMCallHierarchy)
1916+
```
1917+
1918+
This opens a "modal" popup showing the current element in the hierarchy tree.
1919+
The current tree root is aligned to the left and child and parent nodes are
1920+
expanded to the right. Expand the tree "down" with `<Tab> and "up" with
1921+
`<S-Tab>`.
1922+
1923+
The "root" of the tree can be re-focused to the selected item with
1924+
`<S-Tab>` and further `<S-Tab>` will show the parents of the selected item. This
1925+
can take a little getting used to, but it's particularly important with multiple
1926+
inheritance where a "child" of the current root may actually have other,
1927+
invisible, parent links. `<S-Tab>` on that row will show these by setting the
1928+
display root to the selected item.
1929+
1930+
When the hierarchy is displayed, the following keys are intercepted:
1931+
1932+
* `<Tab>`: Drill into the hierarchy at the selected item: expand and show
1933+
children of the selected item.
1934+
* `<S-Tab>`: Show parents of the selected item. When applied to sub-types, this
1935+
will re-root the tree at that type, so that all parent types (are displayed).
1936+
Similar for callers.
1937+
* `<CR>`: Jump to the symbol currently selected.
1938+
* `<Down>`, `<C-n>`, `<C-j>`, `j`: Select the next item
1939+
* `<Up>`, `<C-p>`, `<C-k>`, `k`; Select the previous item
1940+
* Any other key: closes the popup without jumping to any location
1941+
1942+
**Note:** you might think the call hierarchy tree is inverted, but we think
1943+
this way round is more intuitive because this is the typical way that call
1944+
stacks are displayed (with the current function at the top, and its callers
1945+
below).
1946+
18861947
Commands
18871948
--------
18881949

@@ -2102,6 +2163,9 @@ Supported in filetypes: `c, cpp, objc, objcpp, cuda, go, java, rust`
21022163

21032164
#### The `GoToCallers` and `GoToCallees` subcommands
21042165

2166+
Note: A much more powerful call and type hierarchy can be viewd interactively.
2167+
See [interactive type and call hierarchy](#interactive-type-and-call-hierarchy).
2168+
21052169
Populate the quickfix list with the callers, or callees respectively, of the
21062170
function associated with the current cursor position. The semantics of this
21072171
differ depending on the filetype and language server.
@@ -3738,9 +3802,7 @@ let g:ycm_language_server = []
37383802
### The `g:ycm_disable_signature_help` option
37393803
37403804
This option allows you to disable all signature help for all completion engines.
3741-
There is no way to disable it per-completer. This option is _reserved_, meaning
3742-
that while signature help support remains experimental, its values and meaning
3743-
may change and it may be removed in a future version.
3805+
There is no way to disable it per-completer.
37443806
37453807
Default: `0`
37463808

autoload/youcompleteme.vim

+5
Original file line numberDiff line numberDiff line change
@@ -1763,6 +1763,11 @@ endfunction
17631763
silent! nnoremap <silent> <plug>(YCMToggleInlayHints)
17641764
\ <cmd>call <SID>ToggleInlayHints()<CR>
17651765
1766+
silent! nnoremap <silent> <plug>(YCMTypeHierarchy)
1767+
\ <cmd>call youcompleteme#hierarchy#StartRequest( 'type' )<cr>
1768+
silent! nnoremap <silent> <plug>(YCMCallHierarchy)
1769+
\ <cmd>call youcompleteme#hierarchy#StartRequest( 'call' )<cr>
1770+
17661771
" This is basic vim plugin boilerplate
17671772
let &cpo = s:save_cpo
17681773
unlet s:save_cpo

autoload/youcompleteme/finder.vim

+2-46
Original file line numberDiff line numberDiff line change
@@ -113,35 +113,6 @@ scriptencoding utf-8
113113
" The other functions are utility for the most part and handle things like
114114
" TextChangedI event, starting/stopping drawing the spinner and such.
115115

116-
let s:highlight_group_for_symbol_kind = {
117-
\ 'Array': 'Identifier',
118-
\ 'Boolean': 'Boolean',
119-
\ 'Class': 'Structure',
120-
\ 'Constant': 'Constant',
121-
\ 'Constructor': 'Function',
122-
\ 'Enum': 'Structure',
123-
\ 'EnumMember': 'Identifier',
124-
\ 'Event': 'Identifier',
125-
\ 'Field': 'Identifier',
126-
\ 'Function': 'Function',
127-
\ 'Interface': 'Structure',
128-
\ 'Key': 'Identifier',
129-
\ 'Method': 'Function',
130-
\ 'Module': 'Include',
131-
\ 'Namespace': 'Type',
132-
\ 'Null': 'Keyword',
133-
\ 'Number': 'Number',
134-
\ 'Object': 'Structure',
135-
\ 'Operator': 'Operator',
136-
\ 'Package': 'Include',
137-
\ 'Property': 'Identifier',
138-
\ 'String': 'String',
139-
\ 'Struct': 'Structure',
140-
\ 'TypeParameter': 'Typedef',
141-
\ 'Variable': 'Identifier',
142-
\ }
143-
let s:initialized_text_properties = v:false
144-
145116
let s:icon_spinner = [ '/', '-', '\', '|', '/', '-', '\', '|' ]
146117
let s:icon_done = 'X'
147118
let s:spinner_delay = 100
@@ -156,18 +127,7 @@ function! youcompleteme#finder#FindSymbol( scope ) abort
156127
return
157128
endif
158129

159-
if !s:initialized_text_properties
160-
call prop_type_add( 'YCM-symbol-Normal', { 'highlight': 'Normal' } )
161-
for k in keys( s:highlight_group_for_symbol_kind )
162-
call prop_type_add(
163-
\ 'YCM-symbol-' . k,
164-
\ { 'highlight': s:highlight_group_for_symbol_kind[ k ] } )
165-
endfor
166-
call prop_type_add( 'YCM-symbol-file', { 'highlight': 'Comment' } )
167-
call prop_type_add( 'YCM-symbol-filetype', { 'highlight': 'Special' } )
168-
call prop_type_add( 'YCM-symbol-line-num', { 'highlight': 'Number' } )
169-
let s:initialized_text_properties = v:true
170-
endif
130+
call youcompleteme#symbol#InitSymbolProperties()
171131

172132
let s:find_symbol_status = {
173133
\ 'selected': -1,
@@ -470,11 +430,7 @@ function! s:RedrawFinderPopup() abort
470430
let kind = result[ 'extra_data' ][ 'kind' ]
471431
let name = result[ 'extra_data' ][ 'name' ]
472432
let desc = kind .. ': ' .. name
473-
if s:highlight_group_for_symbol_kind->has_key( kind )
474-
let prop = 'YCM-symbol-' . kind
475-
else
476-
let prop = 'YCM-symbol-Normal'
477-
endif
433+
let prop = youcompleteme#symbol#GetPropForSymbolKind( kind )
478434
let props = [
479435
\ { 'col': 1,
480436
\ 'length': len( kind ) + 2,

0 commit comments

Comments
 (0)