Skip to content

Commit

Permalink
Merge pull request #4221 from bstaletic/hierarchies
Browse files Browse the repository at this point in the history
[READY] Implement type/call hierarchy handling
  • Loading branch information
mergify[bot] authored Jun 20, 2024
2 parents 4556062 + 25ec3c9 commit 3a5ee90
Show file tree
Hide file tree
Showing 16 changed files with 918 additions and 84 deletions.
76 changes: 69 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Contents
- [Diagnostic Display](#diagnostic-display)
- [Diagnostic Highlighting Groups](#diagnostic-highlighting-groups)
- [Symbol Search](#symbol-search)
- [Type/Call Hierarchy](#typecall-hierarchy)
- [Commands](#commands)
- [YcmCompleter subcommands](#ycmcompleter-subcommands)
- [GoTo Commands](#goto-commands)
Expand Down Expand Up @@ -677,6 +678,8 @@ Quick Feature Summary
* Code formatting (`Format`)
* Semantic highlighting
* Inlay hints
* Type hierarchy
* Call hierarchy

### C♯

Expand Down Expand Up @@ -720,6 +723,8 @@ Quick Feature Summary
* Type information for identifiers (`GetType`)
* Code formatting (`Format`)
* Management of `gopls` server instance
* Inlay hints
* Call hierarchy

### JavaScript and TypeScript

Expand All @@ -741,6 +746,7 @@ Quick Feature Summary
* Organize imports (`OrganizeImports`)
* Management of `TSServer` server instance
* Inlay hints
* Call hierarchy

### Rust

Expand All @@ -759,6 +765,7 @@ Quick Feature Summary
* Management of `rust-analyzer` server instance
* Semantic highlighting
* Inlay hints
* Call hierarchy

### Java

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

User Guide
----------
Expand Down Expand Up @@ -913,10 +923,6 @@ Ctrl-l is not a suggestion, just an example.

### Semantic highlighting

**NOTE**: This feature is highly experimental and offered in the hope that it is
useful. It shall not be considered stable; if you find issues with it, feel free
to report them, however.

Semantic highlighting is the process where the buffer text is coloured according
to the underlying semantic type of the word, rather than classic syntax
highlighting based on regular expressions. This can be powerful additional data
Expand Down Expand Up @@ -1883,6 +1889,61 @@ so you can use window commands `<C-w>...` for example.
for that, or use a window command (e.g. `<Ctrl-w>j`) or the mouse to leave the
prompt buffer window.

### Type/Call Hierarchy

***This feature requires Vim and is not supported in Neovim***

**NOTE**: This feature is highly experimental and offered in the hope that it is
useful. Please help us by reporting issues and offering feedback.

YCM provides a way to view and navigate hierarchies. The following hierarchies
are supported:

* Type hierachy `<Plug>(YCMTypeHierarchy)`: Display subtypes and supertypes
of the symbol under cursor. Expand down to subtypes and up to supertypes.
* Call hierarchy `<Plug>(YCMCallHierarchy)`: Display callees and callers of
the symbol under cursor. Expand down to callers and up to callees.

Take a look at this [![asciicast](https://asciinema.org/a/659925.svg)](https://asciinema.org/a/659925)
for brief demo.

Hierarchy UI can be initiated by mapping something to the indicated plug
mappings, for example:

```viml
nmap <leader>yth <Plug>(YCMTypeHierarchy)
nmap <leader>ych <Plug>(YCMCallHierarchy)
```

This opens a "modal" popup showing the current element in the hierarchy tree.
The current tree root is aligned to the left and child and parent nodes are
expanded to the right. Expand the tree "down" with `<Tab> and "up" with
`<S-Tab>`.

The "root" of the tree can be re-focused to the selected item with
`<S-Tab>` and further `<S-Tab>` will show the parents of the selected item. This
can take a little getting used to, but it's particularly important with multiple
inheritance where a "child" of the current root may actually have other,
invisible, parent links. `<S-Tab>` on that row will show these by setting the
display root to the selected item.

When the hierarchy is displayed, the following keys are intercepted:

* `<Tab>`: Drill into the hierarchy at the selected item: expand and show
children of the selected item.
* `<S-Tab>`: Show parents of the selected item. When applied to sub-types, this
will re-root the tree at that type, so that all parent types (are displayed).
Similar for callers.
* `<CR>`: Jump to the symbol currently selected.
* `<Down>`, `<C-n>`, `<C-j>`, `j`: Select the next item
* `<Up>`, `<C-p>`, `<C-k>`, `k`; Select the previous item
* Any other key: closes the popup without jumping to any location

**Note:** you might think the call hierarchy tree is inverted, but we think
this way round is more intuitive because this is the typical way that call
stacks are displayed (with the current function at the top, and its callers
below).

Commands
--------

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

#### The `GoToCallers` and `GoToCallees` subcommands

Note: A much more powerful call and type hierarchy can be viewd interactively.
See [interactive type and call hierarchy](#interactive-type-and-call-hierarchy).

Populate the quickfix list with the callers, or callees respectively, of the
function associated with the current cursor position. The semantics of this
differ depending on the filetype and language server.
Expand Down Expand Up @@ -3738,9 +3802,7 @@ let g:ycm_language_server = []
### The `g:ycm_disable_signature_help` option
This option allows you to disable all signature help for all completion engines.
There is no way to disable it per-completer. This option is _reserved_, meaning
that while signature help support remains experimental, its values and meaning
may change and it may be removed in a future version.
There is no way to disable it per-completer.
Default: `0`
Expand Down
5 changes: 5 additions & 0 deletions autoload/youcompleteme.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,11 @@ endfunction
silent! nnoremap <silent> <plug>(YCMToggleInlayHints)
\ <cmd>call <SID>ToggleInlayHints()<CR>
silent! nnoremap <silent> <plug>(YCMTypeHierarchy)
\ <cmd>call youcompleteme#hierarchy#StartRequest( 'type' )<cr>
silent! nnoremap <silent> <plug>(YCMCallHierarchy)
\ <cmd>call youcompleteme#hierarchy#StartRequest( 'call' )<cr>
" This is basic vim plugin boilerplate
let &cpo = s:save_cpo
unlet s:save_cpo
48 changes: 2 additions & 46 deletions autoload/youcompleteme/finder.vim
Original file line number Diff line number Diff line change
Expand Up @@ -113,35 +113,6 @@ scriptencoding utf-8
" The other functions are utility for the most part and handle things like
" TextChangedI event, starting/stopping drawing the spinner and such.

let s:highlight_group_for_symbol_kind = {
\ 'Array': 'Identifier',
\ 'Boolean': 'Boolean',
\ 'Class': 'Structure',
\ 'Constant': 'Constant',
\ 'Constructor': 'Function',
\ 'Enum': 'Structure',
\ 'EnumMember': 'Identifier',
\ 'Event': 'Identifier',
\ 'Field': 'Identifier',
\ 'Function': 'Function',
\ 'Interface': 'Structure',
\ 'Key': 'Identifier',
\ 'Method': 'Function',
\ 'Module': 'Include',
\ 'Namespace': 'Type',
\ 'Null': 'Keyword',
\ 'Number': 'Number',
\ 'Object': 'Structure',
\ 'Operator': 'Operator',
\ 'Package': 'Include',
\ 'Property': 'Identifier',
\ 'String': 'String',
\ 'Struct': 'Structure',
\ 'TypeParameter': 'Typedef',
\ 'Variable': 'Identifier',
\ }
let s:initialized_text_properties = v:false

let s:icon_spinner = [ '/', '-', '\', '|', '/', '-', '\', '|' ]
let s:icon_done = 'X'
let s:spinner_delay = 100
Expand All @@ -156,18 +127,7 @@ function! youcompleteme#finder#FindSymbol( scope ) abort
return
endif

if !s:initialized_text_properties
call prop_type_add( 'YCM-symbol-Normal', { 'highlight': 'Normal' } )
for k in keys( s:highlight_group_for_symbol_kind )
call prop_type_add(
\ 'YCM-symbol-' . k,
\ { 'highlight': s:highlight_group_for_symbol_kind[ k ] } )
endfor
call prop_type_add( 'YCM-symbol-file', { 'highlight': 'Comment' } )
call prop_type_add( 'YCM-symbol-filetype', { 'highlight': 'Special' } )
call prop_type_add( 'YCM-symbol-line-num', { 'highlight': 'Number' } )
let s:initialized_text_properties = v:true
endif
call youcompleteme#symbol#InitSymbolProperties()

let s:find_symbol_status = {
\ 'selected': -1,
Expand Down Expand Up @@ -470,11 +430,7 @@ function! s:RedrawFinderPopup() abort
let kind = result[ 'extra_data' ][ 'kind' ]
let name = result[ 'extra_data' ][ 'name' ]
let desc = kind .. ': ' .. name
if s:highlight_group_for_symbol_kind->has_key( kind )
let prop = 'YCM-symbol-' . kind
else
let prop = 'YCM-symbol-Normal'
endif
let prop = youcompleteme#symbol#GetPropForSymbolKind( kind )
let props = [
\ { 'col': 1,
\ 'length': len( kind ) + 2,
Expand Down
Loading

0 comments on commit 3a5ee90

Please sign in to comment.