fannheyward / coc-rust-analyzer

rust-analyzer extension for coc.nvim
MIT License
1.12k stars 39 forks source link

The last two lines of doc comments are always missing in popup window. #1221

Closed your-diary closed 5 months ago

your-diary commented 6 months ago

I have this Rust code:

/// 1
/// 2
/// 3
/// 4
/// 5
struct S;

fn main() {
    S {};
}

The doc comments of the struct S consist of five lines.

However, when I try to show the documentation of S via :call CocAction('doHover'), the last two lines of the doc comments are missing:

Screenshot 2024-01-21 at 19 54 50

This is extremely annoying especially when doc comments consist of one or two comments:

Screenshot 2024-01-21 at 20 08 03

Though I can scroll with a mouse wheel, I think the entire doc comments should be shown (if they are short enough as in the example above).

By the way, rust-analyzer extension of VSCode shows the doc comments correctly.

Screenshot 2024-01-21 at 19 55 10

And Golang has no problem:

Screenshot 2024-01-21 at 20 14 21

What's the output of :CocInfo

## versions

vim version: VIM - Vi IMproved 9.1 9010000
node version: v21.6.0
coc.nvim version: 0.0.82-d1568d56 2023-09-29 19:43:34 +0800
coc.nvim directory: /Users/user/.vim/plugged/coc.nvim
term: iTerm.app
platform: darwin

## Log of coc.nvim

2024-01-21T19:53:20.977 INFO (pid:21892) [plugin] - coc.nvim initialized with node: v21.6.0 after 126
2024-01-21T19:53:20.978 INFO (pid:21892) [services] - LanguageClient Rust Analyzer Language Server state change: stopped => starting
2024-01-21T19:53:20.982 INFO (pid:21892) [language-client-index] - Language server "rust-analyzer" started with 21894
2024-01-21T19:53:20.987 INFO (pid:21892) [services] - LanguageClient Rust Analyzer Language Server state change: starting => running
2024-01-21T19:53:21.004 INFO (pid:21892) [services] - service rust-analyzer started
2024-01-21T19:53:22.188 INFO (pid:21892) [attach] - Request action: doHover []

What's the output of :CocCommand rust-analyzer.serverVersion

[coc.nvim] rust-analyzer 0.3.1807-standalone (9d8889cdf 2024-01-11)

What's your coc-rust-analyzer version? You can get it from :CocList extensions

* coc-rust-analyzer 0.75.0 ~/.config/coc/extensions/node_modules/coc-rust-analyzer
fannheyward commented 6 months ago
image

Can't reproduce this.

your-diary commented 6 months ago

@fannheyward Thank you for trying that.

Reading your response, I tried to reproduce the behavior with minimal configurations. Here are the minimal reproducible configurations:

~/.vimrc

call plug#begin('~/.vim/plugged')
    Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()

let g:coc_global_extensions = ['coc-rust-analyzer']

:CocConfig

{}

~/.vim/syntax/rust.vim

set number

It seems the evil is set number in ~/.vim/syntax/rust.vim. By the way, I also write set number in ~/.vim/syntax/go.vim, but popup window works with no problem as stated in the OP.

fannheyward commented 6 months ago

I also have set number in my vimrc, will test this with syntax's.

your-diary commented 6 months ago

If I remove set number from ~/.vim/syntax/rust.vim and instead put autocmd BufRead *.rs set number in ~/.vimrc, the issue disappears. This is very strange.

fannheyward commented 6 months ago

The floating doc buffer uses the syntax/rust.vim setting, display the number line in floating window, decrease the width by numberwidth.

The problem: why the floating buffer uses syntax/rust.vim cause its filetype is not rust.

your-diary commented 6 months ago

I see...

why the floating buffer uses syntax/rust.vim cause its filetype is not rust.

To highlight the contents inside it, perhaps?

It seems the behavior is not limited to Rust. I tried Go:

" ~/.vim/syntax/go.vim

syntax match __red /./
highlight __red cterm=bold,italic ctermfg=red

set number

Screenshot 2024-01-23 at 21 32 27

Reading your comment, I noticed the line numbers are also shown in the screenshot of Go though no line is missing.

fannheyward commented 6 months ago

To highlight the contents inside it

Yes, coc.nvim will syntax include @RUST syntax/rust.vim, I missed this.

fannheyward commented 6 months ago

Made a fix in https://github.com/neoclide/coc.nvim/pull/4870, disable the number line after floating win created/reused, not perfect but works for better look.