Skip to content

Conversation

bfredl
Copy link
Member

@bfredl bfredl commented Mar 25, 2018

Currently mostly to show that it is possible, not sure what the best API is. Should work like vim/vim#2388, except that it is memory safe and it is possible to specify highlight group. Use

call nvim_buf_set_eol_text(0, 0, "WarningMsg", 5, " some text")

to show a warning annotation after line 6. Ideally detailed highlighting should be supported, perhaps by adding a flag to bufhl entries. Also a flag to highlight to the end of the current screenline would be nice.

final API:

call nvim_buf_set_virtual_text(0, src_id, linenr, [["text "], ["more text", "Comment"]], {})

Ref #1767 #8068

@bfredl
Copy link
Member Author

bfredl commented Mar 25, 2018

Known limitations:

  • doesn't look good with listchars=eol
  • doesn't look good with area highlighting (visual mode)

@justinmk justinmk added api libnvim, Nvim RPC API enhancement display redraw, layout, presentation labels Mar 25, 2018
@justinmk
Copy link
Member

justinmk commented Mar 25, 2018

When the cursor moves past EOL into "non-text" space Vim calls that "virtual editing".

Is there a reason this needs to be limited to EOL? Or could it instead be offset-driven? IIUC this PR adds management for per-line annotations, it just doesn't yet give the capability to say where the offset is.

@bfredl
Copy link
Member Author

bfredl commented Mar 25, 2018

@justinmk the honest answer is I've tried that, but I've never got the cursor positioning to work. EOL is simpler as it does never affect cursor positioning...

@justinmk
Copy link
Member

justinmk commented Mar 25, 2018

Fair enough, I would suggest something like nvim_buf_set_virtual_text({buf}, {column}, ...) with a current limitation that {column} must be -1 which means EOL. So we have a partial implementation and can enhance it later.

@bfredl
Copy link
Member Author

bfredl commented Mar 25, 2018

EOL is simpler as it does never affect cursor positioning...

Well, unless the annotated text contains a double width char and virtualedit is active :P (for nvim it works, but terminals might not like it, pangoterm does not)

{offset} must be INTMAX which means EOL.

Agree, we have used this pattern before (parameter with forced value, sockconnect(..., {'rpc': v:true}) comes to mind)

@marvim marvim added the WIP label Mar 25, 2018
@bfredl
Copy link
Member Author

bfredl commented Mar 25, 2018

unless the annotated text contains a double width char and virtualedit is active :P (for nvim it works, but terminals might not like it, pangoterm does not)

But actually, double-width+block visual mode already has some glitches with pangoterm (and supposedly with other terminals), so maybe this actually doesn't make stuff worse...

@bfredl
Copy link
Member Author

bfredl commented Sep 8, 2018

Instead of messing the line-drawing loop I tried another approach: add char putting to the existing post-end-of-line loop. This fixes some issues:

  • reasonable interaction with lcs=eol:$
  • visual selection doesn't "select" the eol text (though I have fixed this in the old implementation also)
  • does not change line breaking, rather truncates the eol text. This is probably more reasonable, rather than flicker the line layout as diagnostics are received from LSP (for instance)

@bfredl
Copy link
Member Author

bfredl commented Sep 9, 2018

Changed the API to allow multiple highlights: (1-element chunk implies no highlight)

call nvim_buf_set_virtual_text(0, src_id, linenr, [["text "], ["more text", "Comment"]], {})

I think I will add a forced-empty options dict (because I have some ideas of extensions, including more control of positioning), but otherwise I think the API is good enough as a first step (and I want to release my LSP inline diagostics plugin :P).

typedef struct {
char *text;
int hl_id;
} EolTextChunk;
Copy link
Member

@justinmk justinmk Sep 9, 2018

Choose a reason for hiding this comment

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

If we plan to (later) support overlays at any column (not just EOL), does it make sense to name this (and other similar identifiers) TextOverlayChunk VirtualTextChunk ?

(I guess it's not an "overlay" since it doesn't combine with the hidden text. Instead it's just "virtual text" or something like that. And "virtual" is semantically consistent with the existing concept of 'virtualedit'.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably, but I would start with naming the API function properly and derive everything else from there.

@bfredl bfredl force-pushed the eol_text branch 3 times, most recently from 9f850ab to ac484f6 Compare September 16, 2018 18:25
@bfredl bfredl changed the title [WIP] end of line annotations [RFC] support "virtual text" annotations (currently after EOL only) Sep 16, 2018
@bfredl
Copy link
Member Author

bfredl commented Sep 16, 2018

Renamed to nvim_buf_set_virtual_text. Added some docs and some tests, marking RFC.

free_exit:
kv_destroy(virt_text);
return 0;
}
// Check if deleting lines made the cursor position invalid.
Copy link
Member

Choose a reason for hiding this comment

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

need blank line after the function body

@marvim marvim removed the WIP label Sep 16, 2018
@wsdjeg
Copy link
Contributor

wsdjeg commented Oct 12, 2018

@bfredl I just have a try with this PR, here is my follow questions:

  1. can not view help file via :h nvim_buf_set_virtual_text()
  2. how to clear this virtual text?
  3. after adding many virtual texts, can we group them, that will be easy to clear one group.

@wsdjeg
Copy link
Contributor

wsdjeg commented Oct 12, 2018

and this feature is to show virtual text, we can not override exist line, for example , I want to show an infor under cursorline, and start with col 1, instead of end of next line.

@bfredl
Copy link
Member Author

bfredl commented Oct 12, 2018

we can not override exist line, for example , I want to show an infor under cursorline, and start with col 1, instead of end of next line.

Not yet, but the options dict is meant for adding additional behaviors. We could add support for something like {'col': 0, 'conceal': v:true} (or maybe concealing should just be the default and not shifting, is is easier to implement anyway). Another option is simply {'replace': v:true} which just skips the ordinary text loop (but it would imply potentially changing text flow, and more redraws, something I have avoided so far).

@wsdjeg
Copy link
Contributor

wsdjeg commented Oct 12, 2018

OK,if we are using conceal in the dictionary, can I use new colorscheme group ?

@bfredl
Copy link
Member Author

bfredl commented Oct 13, 2018

OK,if we are using conceal in the dictionary, can I use new colorscheme group ?

Yes, no need to inherit arbitrary restrictions from matchaddpos().

@luan
Copy link

luan commented Nov 5, 2018

@bfredl I just have a try with this PR, here is my follow questions:

  1. can not view help file via :h nvim_buf_set_virtual_text()
  2. how to clear this virtual text?
  3. after adding many virtual texts, can we group them, that will be easy to clear one group.

I'm also curious about 2 and 3 here. It's pretty painful to have to track all the virutal texts added to clear one by one.

@bfredl
Copy link
Member Author

bfredl commented Nov 5, 2018

I responded to that on gitter and updated the documentation. Though api.txt docs might not have been regenerated since then. The same mechanism as for nvim_buf_add_highlight is used for grouping.

@justinmk
Copy link
Member

justinmk commented Nov 6, 2018

Updated API docs: b96730b

@pwntester
Copy link
Contributor

Awesome feature, thanks!

May I suggest right justification of text as one of the future opts?

@weilbith
Copy link
Contributor

weilbith commented Nov 28, 2018

How to handle wrapping?
Cause so far if the virtual text behind the line is long (or the lines content itself is quite long) it does not fit within the width of the window. So only the beginning of the text is visible. And since the virtual text is not part of the buffer, there seems to be no way to scroll to the right, cause the cursor just move to the next line.

@justinmk
Copy link
Member

@weilbith This is a current limitation / by design. How would you expect it to handle wrapping?

@weilbith
Copy link
Contributor

🤔

I guess as right now if using wrapping for the buffers content. The line is split into two visual lines in the buffer, while the file has only one. (isn't it the default behavior?)
Maybe in this case I could imagine the feature (configurable?) of wrapping the line, but don't start the virtual text on the first buffer line and wrap the not fitting part into the next, but display the whole virtual text in the new line of the wrapped line, just in case the content plus the virtual text would not fit for the current windows width. I believe this could look nice. 🤷‍♂️

@blueyed
Copy link
Contributor

blueyed commented Nov 28, 2018

Yes, it could maybe just trigger the wrapping with set wrap?
Not sure if this needs a configuration option though, but should rather be the default.
(It works quite nice already for when the line itself is wrapped already.)

@weilbith
Copy link
Contributor

(It works quite nice already for when the line itself is wrapped already.)

How do you mean this? Sounds more like a situation that could occur and where this looks nice, rather than something that is "working". Or did I get this wrong by you?
The sentence before the last one has no negative intention. I love this feature here. 👍

@bfredl
Copy link
Member Author

bfredl commented Nov 28, 2018

the line is split into two visual lines in the buffer, while the file has only one. (isn't it the default behavior?)

It is currently by (general, not feature-specific) design. If I just change the vertical space of a line inside win_line, the rest of the window might get garbled up. conceal has the reverse problem, a large conceal should allow a line to wrap less and occupy less vertical space, but vim currently doesn't allow this. So you will then get a line that is wrapped even if it visually shouldn't need to be. I might look into all this when my next battle with win_line.

@weilbith
Copy link
Contributor

weilbith commented Nov 28, 2018

@BFedL okay, make sense. Sound like and awful problem. 🤔
So can be mention this anywhere? Since you said the win_lin stuff is already planned, is there an issue open to do so?

yardnsm pushed a commit to yardnsm/vim-import-cost that referenced this pull request Dec 8, 2018
![](https://i.imgur.com/2rbeRZm.png)


With this PR (neovim/neovim#8180) neovim has support to display text that is not part of the file in a buffer. Using this instead of opening a new split will be a better way to display the size.

> Docs need to be added.


### Two new variables
`g:import_cost_virtualtext_hl_group` : set highlight group (default LineNr)
`g:import_cost_virtualtext_prefix`: prefix for virtualtext ( default > )
justinmk added a commit to justinmk/neovim that referenced this pull request Dec 30, 2018
Besides the "visible" improvements, this release features numerous
internal improvements to the UI/screen code and test infrastructure.

Numerous patches were merged from Vim, which are not mentioned below.

FEATURES:

07ad5d7 clipboard: Support custom VimL functions neovim#9304
725da1f neovim#9401 win/TUI: Improve terminal/console support
7a8dadb neovim#9077 startup: Use $XDG_CONFIG_DIRS/nvim/sysinit.vim if it exists
feec926 neovim#9299 support <cmd> mapping in more places
0653ed6 neovim#9028 diff/highlight: Show underline for low-priority CursorLine
bddcbbb signs: Add "numhl" argument neovim#9113
05f9c7c clipboard: support Wayland (neovim#9230)
14ae394 neovim#9052 TUI: add support for undercurl and underline color
4fa3492 neovim#9023 man.vim: soft (dynamic) wrap neovim#9023

API:

8b39e4e neovim#6920 API: implement object namespaces
b1aaa0a API: Implement nvim_win_set_buf() neovim#9100
8de87c7 neovim#8180 API: virtual text annotations (nvim_buf_set_virtual_text)
2b9fc9a neovim#8660 API: add nvim_buf_is_loaded()
    API: buf_get_lines, buf_line_count handle unloaded buffers
88f77c2 API: nvim_buf_get_offset_for_line
94841e5 API/UI: neovim#8221 ext_newgrid, ext_hlstate
    (use line-based rather than char-based updates)

UI

b5cfac0 neovim#8806 TUI: use BCE again more often, (smoother resizes/scrolling)
77b5e9a neovim#9315 screen: add missing status redraw when redraw_later(CLEAR) was used
5f15788 TUI: clip invalid regions on resize (neovim#8779), fixes neovim#8774
c936ae0 neovim#9193 TUI: improvements for scrolling and clearing
f204274 neovim#9143 UI: disable clearing almost everywhere
f4b2b66 neovim#9079 TUI: always use safe cursor movement after resize
d36afaf neovim#9211 ui_options: also send when starting or from OptionSet
67f80d4 TUI: Avoid reset_cursor_color in old VTE neovim#9191
e55ebae neovim#9021 don't erase screen on `:hi Normal` during startup
c5790d9 neovim#8915 TUI: Hint wrapped lines to terminals.

FIXES:

231de72 RPC: turn errors from async calls into notifications
907ad92 TUI: Restore terminal title via "title stacking" (neovim#9407)
cb76a8a genappimage: Unset $ARGV0 at invocation neovim#9376
b48efd9 neovim#9347 TUI: FreeBSD: Improve support for BSD vt console
c16529a TUI: Konsole 18.07.70 supports DECSCUSR (neovim#9364)
aec096f os/lang: use the correct LC_NUMERIC also for OS X
5fee0be provider: improve error message (neovim#9344)
3c42d7a TUI: alacritty supports set_cursor_color neovim#9353
7bff9a5 TUI: Alacritty supports DECSCUSR (neovim#9048)
57acfce macOS: infer primary language if $LANG is empty neovim#9345
bc132ae runtime/syntax: Fix highlighting of augroup contents (neovim#9328)
715fdfe neovim#9297 VimL/confirm(): Show dialog even if :silent
799d9c3 clipboard: Prefer xclip (neovim#9302)
6dae777 provider/nodejs: fix npm,yarn detection
16bc1e9 neovim#9218 channel: avoid buffering output when only terminal and no callbacks are active
72fecad neovim#8804 Fix crash in lang_init() on macOS if lang_region = NULL
d581398 ruby: detect rbenv shims for other versions (neovim#8733)
e568ac7 neovim#9123 third-party/unibilium: Fix parsing of extended capability entries
c4c74c3 jobstart(): Fix hang on non-executable cwd neovim#9204
1cf50cb provider/nodejs: Simultaneously query npm and yarn neovim#9054
6c496db undo: Fix infinite loop if undo_read_byte returns EOF neovim#2880
f8f8357 neovim#9034 'swapfile: always show dialog'

CHANGES:

c236e80 neovim#9024 --embed: wait for UI unless --headless
180b50d neovim#9248 python: 'neovim' module was renamed to 'pynvim'
2000b6a neovim#8589 VimL: Remove legacy aliases "v:errmsg", "v:shell_error", "v:this_session"
deb18a0 defaults: background=dark neovim#2894 (neovim#9205)
c1187d4 defaults: win: 'shellpipe' for cmd.exe (neovim#8827)
justinmk added a commit to justinmk/neovim that referenced this pull request Dec 31, 2018
Besides the "visible" improvements, this release features numerous
internal improvements to the UI/screen code and test infrastructure.

Numerous patches were merged from Vim, which are not mentioned below.

FEATURES:

07ad5d7 clipboard: Support custom VimL functions neovim#9304
725da1f neovim#9401 win/TUI: Improve terminal/console support
7a8dadb neovim#9077 startup: Use $XDG_CONFIG_DIRS/nvim/sysinit.vim if it exists
feec926 neovim#9299 support <cmd> mapping in more places
0653ed6 neovim#9028 diff/highlight: Show underline for low-priority CursorLine
bddcbbb signs: Add "numhl" argument neovim#9113
05f9c7c clipboard: support Wayland (neovim#9230)
14ae394 neovim#9052 TUI: add support for undercurl and underline color
4fa3492 neovim#9023 man.vim: soft (dynamic) wrap neovim#9023

API:

8b39e4e neovim#6920 API: implement object namespaces
b1aaa0a API: Implement nvim_win_set_buf() neovim#9100
8de87c7 neovim#8180 API: virtual text annotations (nvim_buf_set_virtual_text)
2b9fc9a neovim#8660 API: add nvim_buf_is_loaded()
    API: buf_get_lines, buf_line_count handle unloaded buffers
88f77c2 API: nvim_buf_get_offset_for_line
94841e5 API/UI: neovim#8221 ext_newgrid, ext_hlstate
    (use line-based rather than char-based updates)

UI

b5cfac0 neovim#8806 TUI: use BCE again more often, (smoother resizes/scrolling)
77b5e9a neovim#9315 screen: add missing status redraw when redraw_later(CLEAR) was used
5f15788 TUI: clip invalid regions on resize (neovim#8779), fixes neovim#8774
c936ae0 neovim#9193 TUI: improvements for scrolling and clearing
f204274 neovim#9143 UI: disable clearing almost everywhere
f4b2b66 neovim#9079 TUI: always use safe cursor movement after resize
d36afaf neovim#9211 ui_options: also send when starting or from OptionSet
67f80d4 TUI: Avoid reset_cursor_color in old VTE neovim#9191
e55ebae neovim#9021 don't erase screen on `:hi Normal` during startup
c5790d9 neovim#8915 TUI: Hint wrapped lines to terminals.

FIXES:

231de72 RPC: turn errors from async calls into notifications
907ad92 TUI: Restore terminal title via "title stacking" (neovim#9407)
cb76a8a genappimage: Unset $ARGV0 at invocation neovim#9376
b48efd9 neovim#9347 TUI: FreeBSD: Improve support for BSD vt console
c16529a TUI: Konsole 18.07.70 supports DECSCUSR (neovim#9364)
aec096f os/lang: use the correct LC_NUMERIC also for OS X
5fee0be provider: improve error message (neovim#9344)
3c42d7a TUI: alacritty supports set_cursor_color neovim#9353
7bff9a5 TUI: Alacritty supports DECSCUSR (neovim#9048)
57acfce macOS: infer primary language if $LANG is empty neovim#9345
bc132ae runtime/syntax: Fix highlighting of augroup contents (neovim#9328)
715fdfe neovim#9297 VimL/confirm(): Show dialog even if :silent
799d9c3 clipboard: Prefer xclip (neovim#9302)
6dae777 provider/nodejs: fix npm,yarn detection
16bc1e9 neovim#9218 channel: avoid buffering output when only terminal and no callbacks are active
72fecad neovim#8804 Fix crash in lang_init() on macOS if lang_region = NULL
d581398 ruby: detect rbenv shims for other versions (neovim#8733)
e568ac7 neovim#9123 third-party/unibilium: Fix parsing of extended capability entries
c4c74c3 jobstart(): Fix hang on non-executable cwd neovim#9204
1cf50cb provider/nodejs: Simultaneously query npm and yarn neovim#9054
6c496db undo: Fix infinite loop if undo_read_byte returns EOF neovim#2880
f8f8357 neovim#9034 'swapfile: always show dialog'

CHANGES:

c236e80 neovim#9024 --embed: wait for UI unless --headless
180b50d neovim#9248 python: 'neovim' module was renamed to 'pynvim'
2000b6a neovim#8589 VimL: Remove legacy aliases "v:errmsg", "v:shell_error", "v:this_session"
deb18a0 defaults: background=dark neovim#2894 (neovim#9205)
c1187d4 defaults: win: 'shellpipe' for cmd.exe (neovim#8827)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api libnvim, Nvim RPC API display redraw, layout, presentation has:vim-patch issue is fixed in vim and patch needs to be ported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants