prabirshrestha / vim-lsp

async language server protocol plugin for vim and neovim
MIT License
3.13k stars 305 forks source link

Do not join inlay hints list with ', ' #1430

Closed ArtAndreev closed 1 year ago

ArtAndreev commented 1 year ago

Currently I write some rust code with rust-analyzer. It has type inlay hints enabled by default. I set up rust-analyzer with vim-lsp:

if executable('rust-analyzer')
  augroup lsp_register_rust_analyzer
    autocmd!
    autocmd User lsp_setup call lsp#register_server({
          \   'name': 'Rust Language Server',
          \   'cmd': {server_info->['rust-analyzer']},
          \   'allowlist': ['rust'],
          \ })
    autocmd BufWritePre *.rs call execute('LspDocumentFormatSync')
  augroup END
endif

After writing code inlay hints rendered strangely:

image

I thought there are some items that are joined with ', '. I searched for it in this plugin codebase and found this line https://github.com/prabirshrestha/vim-lsp/blob/master/autoload/lsp/internal/inlay_hints.vim#L25.

I turned on log file with let g:lsp_log_file = expand('~/vim-lsp.log') and found inlay hints responses. For example, this:

Sat Jan 28 21:18:05 2023:["<---",1,"Rust Language Server",{"response":{"id":6,"jsonrpc":"2.0","result":[{"label":[{"value":": "},{"location":{"uri":"file:///.../.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/collections/hash/map.rs","range":{"end":{"character":18,"line":213},"start":{"character":11,"line":213}}},"value":"HashMap"},{"value":"<&str, i32>"}],"paddingLeft":false,"paddingRight":false,"kind":1,"position":{"character":14,"line":3}},{"label":[{"location":{"uri":"file:///.../.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/collections/hash/map.rs","range":{"end":{"character":30,"line":1102},"start":{"character":29,"line":1102}}},"value":"k"},{"value":":"}],"paddingLeft":false,"paddingRight":true,"kind":2,"position":{"character":14,"line":4}},{"label":[{"location":{"uri":"file:///.../.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/collections/hash/map.rs","range":{"end":{"character":36,"line":1102},"start":{"character":35,"line":1102}}},"value":"v"},{"value":":"}],"paddingLeft":false,"paddingRight":true,"kind":2,"position":{"character":18,"line":4}},{"label":": i32","paddingLeft":false,"paddingRight":false,"kind":1,"position":{"character":11,"line":5}}]},"request":{"id":6,"jsonrpc":"2.0","method":"textDocument/inlayHint","params":{"range":{"end":{"character":0,"line":8},"start":{"character":0,"line":0}},"textDocument":{"uri":"file:///.../project/src/main.rs"}}}}]

The type of hints is list, like in the line above, so they are joined with ', '.

Can be the joining removed?

P.S. VS Code renders okay:

image
CoelacanthusHex commented 1 year ago

I think just replace let l:label = join(map(copy(l:hint.label), {_,v -> v.value}), ', ') with let l:label = join(map(copy(l:hint.label), {_,v -> v.value}), '') can fix it?

prabirshrestha commented 1 year ago

PR has been merged. Please try again.

ArtAndreev commented 1 year ago

Looks OK, thank you!