vim-lsp
vim-lsp copied to clipboard
Inlay hint
Current implementation provide only hints for snapshot buffer. This buffer can be modified but not follow appended keywords which will be matched as hints.
Should be provide name lsp#ui#vim#update_inlay_hints
and lsp#ui#vim#clear_inlay_hints
?
let g:lsp_inlayhints_mode = ''
let g:lsp_inlayhints_mode = 'always' " following changes (with timer)
let g:lsp_inlayhints_mode = 'curline' " following changes (with timer)
let g:lsp_inlayhints_mode = 'hold' " only cursor hold
What do you think?
Now I implemented inlay hints with callbag. Default is enabled.
I turn to make this disable in default since virtual text still have problem that cursor location is wrong.
Got the following error when running rust-analyzer. Seems to be the issue where label
can be string instead of array.
[
"s:on_stdout client request on_notification() error",
"Vim(let):E121: Undefined variable: value",
"function <SNR>120_out_cb[1]..<SNR>118_on_stdout[75]..<SNR>48_request_on_notification[3]..<SNR>49_createNext[1]..<SNR>49_materializeFSourceCallback[2]..<SNR>49_filterSourceCallback[6]..<SNR>49_mapFSourceCallback[1]..<SNR>49_switchMapCurrSourceCallback[2]..<SNR>49_subscribeSourceCallback[2]..<lambda>77[1]..<SNR>117_set_inlay_hints, line 16"
]
for the following response
[
"<---",
2,
"rust-analyzer",
{
"response": {
"id": 4,
"jsonrpc": "2.0",
"result": [
{
"label": ": i32",
"data": {
"position": {
"end": {
"character": 9,
"line": 12
},
"start": {
"character": 8,
"line": 12
}
},
"text_document": {
"uri": "file:///home/prabirshrestha/code/github/objstor/app/src/app.rs"
}
},
"paddingLeft": false,
"paddingRight": false,
"kind": 1,
"tooltip": "i32",
"position": {
"character": 9,
"line": 12
}
},
{
"label": ": i32",
"data": {
"position": {
"end": {
"character": 9,
"line": 13
},
"start": {
"character": 8,
"line": 13
}
},
"text_document": {
"uri": "file:///home/prabirshrestha/code/github/objstor/app/src/app.rs"
}
},
"paddingLeft": false,
"paddingRight": false,
"kind": 1,
"tooltip": "i32",
"position": {
"character": 9,
"line": 13
}
},
{
"label": "request_id:",
"data": {
"position": {
"character": 4,
"line": 43
},
"text_document": {
"uri": "file:///home/prabirshrestha/.cargo/registry/src/github.com-1ecc6299db9ec823/trillium-logger-0.4.0/src/formatters.rs"
}
},
"paddingLeft": false,
"paddingRight": true,
"kind": 2,
"tooltip": "request_id",
"position": {
"character": 12,
"line": 19
}
},
{
"label": "user_id:",
"data": {
"position": {
"character": 4,
"line": 44
},
"text_document": {
"uri": "file:///home/prabirshrestha/.cargo/registry/src/github.com-1ecc6299db9ec823/trillium-logger-0.4.0/src/formatters.rs"
}
},
"paddingLeft": false,
"paddingRight": true,
"kind": 2,
"tooltip": "user_id",
"position": {
"character": 12,
"line": 20
}
},
{
"label": "path:",
"data": {
"position": {
"character": 28,
"line": 353
},
"text_document": {
"uri": "file:///home/prabirshrestha/.cargo/registry/src/github.com-1ecc6299db9ec823/trillium-router-0.3.3/src/router.rs"
}
},
"paddingLeft": false,
"paddingRight": true,
"kind": 2,
"tooltip": "path",
"position": {
"character": 12,
"line": 23
}
},
{
"label": "handler:",
"data": {
"position": {
"character": 37,
"line": 353
},
"text_document": {
"uri": "file:///home/prabirshrestha/.cargo/registry/src/github.com-1ecc6299db9ec823/trillium-router-0.3.3/src/router.rs"
}
},
"paddingLeft": false,
"paddingRight": true,
"kind": 2,
"tooltip": "handler",
"position": {
"character": 12,
"line": 24
}
},
{
"label": "path:",
"data": {
"position": {
"character": 28,
"line": 353
},
"text_document": {
"uri": "file:///home/prabirshrestha/.cargo/registry/src/github.com-1ecc6299db9ec823/trillium-router-0.3.3/src/router.rs"
}
},
"paddingLeft": false,
"paddingRight": true,
"kind": 2,
"tooltip": "path",
"position": {
"character": 21,
"line": 26
}
},
{
"label": "handler:",
"data": {
"position": {
"character": 37,
"line": 353
},
"text_document": {
"uri": "file:///home/prabirshrestha/.cargo/registry/src/github.com-1ecc6299db9ec823/trillium-router-0.3.3/src/router.rs"
}
},
"paddingLeft": false,
"paddingRight": true,
"kind": 2,
"tooltip": "handler",
"position": {
"character": 26,
"line": 26
}
},
{
"label": "Router",
"data": {
"position": {
"end": {
"character": 51,
"line": 25
},
"start": {
"character": 12,
"line": 24
}
},
"text_document": {
"uri": "file:///home/prabirshrestha/code/github/objstor/app/src/app.rs"
}
},
"paddingLeft": true,
"paddingRight": false,
"kind": 1,
"tooltip": "Router",
"position": {
"character": 51,
"line": 25
}
},
{
"label": "path:",
"paddingLeft": false,
"paddingRight": true,
"kind": 2,
"tooltip": "path",
"position": {
"character": 22,
"line": 25
}
},
{
"label": "handler:",
"paddingLeft": false,
"paddingRight": true,
"kind": 2,
"tooltip": "handler",
"position": {
"character": 32,
"line": 25
}
},
{
"label": "Router",
"data": {
"position": {
"end": {
"character": 25,
"line": 24
},
"start": {
"character": 12,
"line": 24
}
},
"text_document": {
"uri": "file:///home/prabirshrestha/code/github/objstor/app/src/app.rs"
}
},
"paddingLeft": true,
"paddingRight": false,
"kind": 1,
"tooltip": "Router",
"position": {
"character": 25,
"line": 24
}
}
]
},
"request": {
"id": 4,
"jsonrpc": "2.0",
"method": "textDocument/inlayHint",
"params": {
"range": {
"end": {
"character": 1,
"line": 30
},
"start": {
"character": 0,
"line": 0
}
},
"textDocument": {
"uri": "file:///home/prabirshrestha/code/github/objstor/app/src/app.rs"
}
}
}
}
]
I do think we need some sort of mode for inlay hints.
I would like to always show inlay hints even when in insert mode but not for the current line. But expression this would be a bit difficult. Might be something like this which is easy to parse?
" when in insert mode always show the inlays expect for curline, when in normal mode always show
let g:lsp_inlayhints_mode = 'insert=always,!curline;normal=always'
" always show in insert and normal mode
let g:lsp_inlayhints_mode = 'insert=always;normal=always'
" only show in normal mode
let g:lsp_inlayhints_mode = 'normal=always')
Here are some other examples:
https://github.com/nvim-lua/lsp_extensions.nvim
require'lsp_extensions'.inlay_hints{
highlight = "Comment",
prefix = " > ",
aligned = false,
only_current_line = false,
enabled = { "ChainingHint" }
}
https://github.com/lvimuser/lsp-inlayhints.nvim#default-configuration
local default_config = {
inlay_hints = {
parameter_hints = {
show = true,
prefix = "<- ",
separator = ", ",
remove_colon_start = false,
remove_colon_end = true,
},
type_hints = {
-- type and other hints
show = true,
prefix = "",
separator = ", ",
remove_colon_start = false,
remove_colon_end = false,
},
-- separator between types and parameter hints. Note that type hints are
-- shown before parameter
labels_separator = " ",
-- whether to align to the length of the longest line in the file
max_len_align = false,
-- padding from the left if max_len_align is true
max_len_align_padding = 1,
-- highlight group
highlight = "LspInlayHint",
},
debug_mode = false,
}
Definitely should have a way to toggle on and off.
We should also document the highlight group.
So it should be better to be a dictionary?
let lsp_inlayhints_mode = {
\ 'insert': ['always', '!curline'],
\ 'normal': ['always'],
\}
Hmm, I guess implementation of always-mode should be difficult.
I added lsp_inlay_hints_mode that only include curline, !curline.
I'm trying this branch, but don't see any hints with gopls. Is any configuration required apart from let g:lsp_inlay_hints_enabled = 1
?
Do you use latest gopls ?
Also you need to add some configuration for vim-lsp.
https://github.com/mattn/vim-lsp-settings/blob/dd2858d4f7df7da2c3d30f2b3da39ea6488f3afa/settings/gopls.vim#L10-L18
Thanks, I updated gopls and put in the configuration and now it works.
One issue I noticed: if I pass a variable to a function and the name of the variable matches the function's parameter, the hint will not be drawn.
This inlay-hints implementation does not look-up the names (ex: which the functions or variables). So I guess it is the issue of gopls.
Interesting. I guess it's the expected behaviour, I could get used to it.