prabirshrestha / vim-lsp

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

Place multi-line highlights every lines #1422

Closed ryu-ichiroh closed 1 year ago

ryu-ichiroh commented 1 year ago

Resolve: #1415

Briefly, this change fixes a bug that the rows do not match the lines on the screen.

Vim has a problem with multi-line text_prop not working properly. https://github.com/vim/vim/issues/11846 Therefore, I changed the code to add text_prop one line at a time.

The idea is simple because it's based on the code for Neovim. (https://github.com/prabirshrestha/vim-lsp/blob/master/autoload/lsp/internal/diagnostics/highlights.vim#L137-L163)

ryu-ichiroh commented 1 year ago

This vimrc is for testing this PR.

"test_1422.vim
source $VIMRUNTIME/defaults.vim
set number

colorscheme habamax
let vim_lsp = "~/.vim/pack/test_1422/opt/vim-lsp-1422"
if !isdirectory(vim_lsp)
  call system("git clone https://github.com/ryuichiroh/vim-lsp " .. vim_lsp)
endif

" !! Please switch branch you want to check
"let branch = 'master'
let branch = 'issue-1415-multiline-highlights'

call system("git -C " .. vim_lsp .. " switch " .. branch)

packadd vim-lsp-1422
call lsp#enable()

let vim_lsp_settings = "~/.vim/pack/test_1422/opt/vim-lsp-settings"
if !isdirectory(vim_lsp_settings)
  call system("git clone https://github.com/mattn/vim-lsp-settings " .. vim_lsp_settings)
endif
packadd vim-lsp-settings

let g:lsp_diagnostics_float_cursor = 1
let g:lsp_diagnostics_virtual_text_enabled = 1
let g:lsp_diagnostics_virtual_text_align = 'after'
let g:lsp_diagnostics_virtual_text_wrap = 'truncate'
let g:lsp_diagnostics_highlights_enabled = 1

highlight link LspErrorHighlight SpellBad
highlight link LspErrorVirtualText SpellBad
highlight link LspHintHighlight SpellRare
highlight link LspHintVirtualText SpellRare

call system("mkdir node_modules")

call writefile([
 \   '',
 \   'const func: func.IFunction = ({',
 \   '  setLoading',
 \   '}) => {'
 \ ], 'hello.ts')
silent! edit! ./hello.ts

":LspInstallServer typescript-language-server

Please run vim with above vimrc.

$ cd /tmp/issue_1415
$ vim -N -u test_1422.vim

To clean after testing.

$ rm -rf ~/.vim/pack/test_1422
$ rm -rf /tmp/issue_1415
mattn commented 1 year ago

Thank you