Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[READY] Implement type/call hierarchy handling #4221

Merged
merged 34 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
dbcca3d
Preliminary type/call hierarchy support
bstaletic Feb 10, 2024
93833dc
Clean up API
bstaletic Feb 11, 2024
705803a
Allow both directions at the same time - me is happy
bstaletic Feb 11, 2024
729806c
Support changing the current hierarchy root node
bstaletic Feb 11, 2024
fcf89f0
Add bindings for hierarchies
bstaletic Feb 11, 2024
65456b2
flake8
bstaletic Feb 11, 2024
08353bc
Fix error using mappings: <Cmd> mappings must end with <CR>
puremourning May 11, 2024
0ce21e2
Avoid vim backtrace when no target description
bstaletic May 11, 2024
f1937cf
Close the popup when non-handled key pressed
puremourning May 11, 2024
c217e66
Basic popup aesthetics
puremourning May 11, 2024
72026b3
Tidy handles: wrap in some little functions
puremourning May 11, 2024
6ca4659
Style the hierarchy popup like the finder popup
puremourning May 13, 2024
ea6cb61
Trim leading/trailing whitespace from description
puremourning May 13, 2024
fa73852
Explain offsets
puremourning May 13, 2024
3376c05
Use correct bottom-right border character as we don't actually allow …
puremourning May 13, 2024
2a68752
Log server exceptoins
puremourning May 13, 2024
9d8d267
flake8
bstaletic May 14, 2024
6c3832d
Avoid nasty crashes in othervim
puremourning May 17, 2024
3702f46
Update README for type hierarchy; graduate some features
puremourning May 17, 2024
489dcb1
Avoid skip_post_command_action hack when making Hierarchy request
bstaletic Jun 9, 2024
8888bbe
Fix re-rooting of call/type hierarchies
bstaletic Jun 9, 2024
546b050
Simplify getting a raw response from a completer command
bstaletic Jun 10, 2024
31f6517
Fix re-rooting from incoming calls to outgoing calls
bstaletic Jun 11, 2024
67c02b8
Fix sending requests for a location in an unloaded buffer
bstaletic Jun 11, 2024
e354a54
Properly calculate selection offset when expanding hierarchy upwards
bstaletic Jun 11, 2024
5e03ee0
Fix python tests... again
bstaletic Jun 11, 2024
bbd0f03
Handle vim erros when invoking `:badd` and `bufload()`
bstaletic Jun 12, 2024
866128c
Flake8 fixes
bstaletic Jun 12, 2024
53f4a42
Add vim tests for hierarchies
bstaletic Jun 12, 2024
f05f89e
Update ycmd submodule
bstaletic Jun 18, 2024
87939d6
Fix vim tests for hierarchies
puremourning Jun 19, 2024
2eff94b
Remove use of indexof()
puremourning Jun 19, 2024
ac002d5
Clean up hierarchies.test.vim
bstaletic Jun 19, 2024
25ec3c9
Clean up BuildRequestDataForLocation
bstaletic Jun 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 66 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,7 @@ Quick Feature Summary
* Type information for identifiers (`GetType`)
* Code formatting (`Format`)
* Management of `gopls` server instance
* Call hierarchy

### JavaScript and TypeScript

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

### Java

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

User Guide
----------
Expand Down Expand Up @@ -913,10 +920,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 +1886,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 +2160,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 +3799,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
Loading