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

Use native virtual-text for vim9 #4281

Merged
merged 1 commit into from Aug 23, 2022

Conversation

vimpostor
Copy link
Contributor

@vimpostor vimpostor commented Aug 12, 2022

This reimplements virtual text for vim with the new native virtual text API. Please see the commit message for more details.

When this gets merged, I can finally tackle #2962 and implement multiple virtual texts being visible at once.

Screenshot

Before: At the top (implementation is a bit janky)
After: At the bottom (jank is fixed with native virtual text)
Screenshot_20220812_135049

Copy link
Contributor

@hsanson hsanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but I can only verify it does not break things in neovim. Would be great if someone, that is not the PR author, can verify it works as expected in vim.

@vimpostor
Copy link
Contributor Author

vimpostor commented Aug 14, 2022

Would be great if someone can verify it works as expected in vim.

I am a someone and I can verify it works in vim. ^^

@blayz3r You linked in the issue to the new vim9 implementation, would you mind compiling latest vim from source and verifying that everything works as expected with this PR?

@darkseid-is
Copy link

darkseid-is commented Aug 20, 2022

Needs bug fixes .

  1. Underline remains even after fixing the error
    image

  2. Not working as expected in general
    image

vim version : 9.0.228

ale settings
let g:ale_linters = {'rust': ['analyzer']}
let g:ale_fixers = { 'rust': ['rustfmt', 'trim_whitespace', 'remove_trailing_lines'] }
let g:ale_fix_on_save = 1
let g:ale_sign_error = '✗'
let g:ale_sign_warning = ''
let g:ale_sign_column_always = 1
let g:ale_rust_cargo_use_clippy = 1
let g:ale_completion_enabled = 1

let g:ale_virtualtext_cursor = 1
let g:ale_virtualtext_delay = 1

@vimpostor
Copy link
Contributor Author

Needs bug fixes .

  1. Underline remains even after fixing the error
  2. Not working as expected in general

Cannot reproduce any of these problems with your config. Please provide a minimal working config to reproduce the problem.

The part of your config that you shared, does not reproduce the problem with a clean config as can be tested with:

vim --clean -Nu <(cat<<EOF
set rtp+=/path/to/ale/with/my/branch/checkedout
let g:ale_linters = {'rust': ['analyzer']}
let g:ale_fixers = { 'rust': ['rustfmt', 'trim_whitespace', 'remove_trailing_lines'] }
let g:ale_fix_on_save = 1
let g:ale_sign_error = '✗'
let g:ale_sign_warning = ''
let g:ale_sign_column_always = 1
let g:ale_rust_cargo_use_clippy = 1
let g:ale_completion_enabled = 1

let g:ale_virtualtext_cursor = 1
let g:ale_virtualtext_delay = 1

au BufEnter *.rs set ft=rust
EOF
) /path/to/main.rs

@darkseid-is
Copy link

vimrc
``
filetype plugin indent on
filetype plugin on
set autoread
set backspace=indent,eol,start
set belloff=all
set clipboard=unnamedplus
set colorcolumn=80
set cursorline
set display+=lastline "prevent @ symbol from being shown
set encoding=utf8
set expandtab
set foldlevel=99
set foldmethod=indent
set ignorecase
set incsearch
set modelines=0
set noautochdir
set nocompatible
set nomodeline
set noshowmode
set number
set path+=**
set scrolloff=15
set showcmd
set signcolumn=yes
set smartcase
set smartindent
set splitbelow
set splitright
set tags+=tags;/
set ttyfast
set updatetime=50
set viminfo=
set wildmenu
set wildmode=list:longest,full
syntax on
set wildoptions=pum
set wildcharm=
set completepopup=height:10,width:60,highlight:InfoPopup

set t_Co=256
set background=dark
set termguicolors " enable true colors support
let ayucolor="dark" " for dark version of theme
colorscheme ayu
hi ColorColumn ctermbg=darkgrey " Colorcolumn
hi Comment ctermfg=yellow " Comment
hi Folded ctermbg=yellow " Folds
hi Normal ctermbg=NONE guibg=NONE
hi StatusLine ctermfg=green ctermbg=black guifg=green guibg=black " Focused
hi StatusLineNC ctermfg=grey ctermbg=black guifg=Grey guibg=black " NonFocused
hi TabLine ctermfg=grey ctermbg=black guifg=grey guibg=black " Inactive
hi TabLineFill ctermfg=grey ctermbg=black guifg=Black guibg=black " NoLabled
hi TabLineSel ctermfg=grey ctermbg=black guifg=Red guibg=black " Active

packloadall
silent! helptags ALL
let g:ale_linters = {'rust': ['analyzer']}
let g:ale_fixers = { 'rust': ['rustfmt', 'trim_whitespace', 'remove_trailing_lines'] }
let g:ale_fix_on_save = 1
let g:ale_sign_error = '✗'
let g:ale_sign_warning = ''
let g:ale_sign_column_always = 1
let g:ale_rust_cargo_use_clippy = 1
let g:ale_completion_enabled = 1

let g:ale_virtualtext_cursor = 1
let g:ale_virtualtext_delay = 0
``
image
Cursor is in line 7 and virtual text is shown in line 3.

@vimpostor
Copy link
Contributor Author

vimpostor commented Aug 21, 2022

That config is neither minimal, nor does it reproduce the problem on my system.

It is not even a valid config, for example the line with set wildcharm= is not valid, because wildcharm expects a number.

There are other problems with that config too so please provide a minimal config, that actually reproduces the problem.

Also are you sure that you have checked out my branch? Your problem sounds more like something that could happen with the legacy virtual text implementation.

@darkseid-is
Copy link

Sorry for posting buggy rc.
cloned repo from https://github.com/vimpostor/ale
git branch native_virt_text

minimal working rc
filetype plugin indent on
filetype plugin on
syntax on
set number
colorscheme desert

packloadall
silent! helptags ALL
let g:ale_linters = {'rust': ['analyzer']}
let g:ale_fixers = { 'rust': ['rustfmt', 'trim_whitespace', 'remove_trailing_lines'] }
let g:ale_fix_on_save = 1
let g:ale_sign_error = '✗'
let g:ale_sign_warning = ''
let g:ale_sign_column_always = 1
let g:ale_rust_cargo_use_clippy = 1
let g:ale_completion_enabled = 1

let g:ale_virtualtext_cursor = 1
let g:ale_virtualtext_delay = 1

@vimpostor
Copy link
Contributor Author

vimpostor commented Aug 22, 2022 via email

@darkseid-is
Copy link

Setting rtp fixed the issue.

Our current virtual text implementation for vim emulates it by abusing
the textprop and popupwin feature from vim 8.2 (for more details see
commit 708e810).
This implementation sometimes is janky, for example the popups may leak
into other vim windows next to the current window.

Luckily, vim just got native virtual-text support as a proper subtype to
the prop_add() function. By using the 'text' option, the text property
automatically becomes virtual text that is appended to the current line
if col is zero.

Note that the prop_add() method now returns negative IDs for virtual
text properties.

This feature was added in vim 9.0.0067, but it got a lot of bugfixes
which is why we only use this new API if vim has at least version
9.0.0214.
However, there are still some minor bugs with vim's native virtual text,
so we might have to bump the version check again in the future.

Also see dense-analysis#3906.

Now with proper virtual text support for both vim and neovim available,
we can tackle dense-analysis#2962 in the future by simply tracking multiple virt-texts
instead of just the last one.

In the future we might also want to disable our virtual text emulation
support for vim, as it is a total hack, but for now we should keep it
for backwards compatibility.
@vimpostor
Copy link
Contributor Author

vimpostor commented Aug 22, 2022

Setting rtp fixed the issue.

Thanks, so it looks like you used the wrong checkout of Ale all along.
If you confirm that now everything is working correctly, then I guess @hsanson could merge it in.

I just pushed my patch again restricting it to at least vim 9.0.0214, because there were a lot of virtual text bugfixes in vim since its initial implementation.

@darkseid-is
Copy link

Setting rtp fixed the issue.

Thanks, so it looks like you used the wrong checkout of Ale all along. If you confirm that now everything is working correctly, then I guess @hsanson could merge it in.

I just pushed my patch again restricting it to at least vim 9.0.0214, because there were a lot of virtual text bugfixes in vim since its initial implementation.

Yes, I can confirm it works as expected.
Keep up the good work mate.

Copy link
Contributor

@hsanson hsanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution and testing.

@hsanson hsanson merged commit d93bc2b into dense-analysis:master Aug 23, 2022
vimpostor added a commit to vimpostor/vim-prism that referenced this pull request Aug 23, 2022
The hardcoded background was a workaround to fix the wrong background
for Ale's virtual text.

We can remove the workaround now, because Ale uses vim's native virtual
text now, which does not have this problem.

refs: dense-analysis/ale#4281
mnikulin pushed a commit to mnikulin/ale that referenced this pull request Nov 12, 2023
Our current virtual text implementation for vim emulates it by abusing
the textprop and popupwin feature from vim 8.2 (for more details see
commit 708e810).
This implementation sometimes is janky, for example the popups may leak
into other vim windows next to the current window.

Luckily, vim just got native virtual-text support as a proper subtype to
the prop_add() function. By using the 'text' option, the text property
automatically becomes virtual text that is appended to the current line
if col is zero.

Note that the prop_add() method now returns negative IDs for virtual
text properties.

This feature was added in vim 9.0.0067, but it got a lot of bugfixes
which is why we only use this new API if vim has at least version
9.0.0214.
However, there are still some minor bugs with vim's native virtual text,
so we might have to bump the version check again in the future.

Also see dense-analysis#3906.

Now with proper virtual text support for both vim and neovim available,
we can tackle dense-analysis#2962 in the future by simply tracking multiple virt-texts
instead of just the last one.

In the future we might also want to disable our virtual text emulation
support for vim, as it is a total hack, but for now we should keep it
for backwards compatibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants