helix
helix copied to clipboard
Add virtual text support
Closes #411, called text annotations in code.
TODO
- [x] End of line annotations
- [x] Overwrite with virtual text
Future Works
- Inline annotations
POC using diagnostics (click to expand patch):
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index b04eef0..9018af7 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -422,8 +422,37 @@ impl Application {
// source
})
})
- .collect();
-
+ .collect::<Vec<_>>();
+
+ doc.remove_text_annotations(|vt| vt.scope == "diagnostics");
+
+ use helix_core::diagnostic::Severity;
+ use helix_view::decorations::{TextAnnotation, TextAnnotationKind};
+ use helix_view::graphics::{Color, Style};
+ let style = Style::default().bg(Color::Gray);
+ doc.extend_text_annotations(
+ diagnostics
+ .iter()
+ .map(|d| TextAnnotation {
+ scope: "diagnostics".into(),
+ text: d.message.clone(),
+ style: d
+ .severity
+ .as_ref()
+ .map(|s| match s {
+ Severity::Error => style.clone().fg(Color::Red),
+ Severity::Warning => {
+ style.clone().fg(Color::Yellow)
+ }
+ Severity::Info => style.clone().fg(Color::Blue),
+ Severity::Hint => style.clone().fg(Color::Green),
+ })
+ .unwrap_or(style.clone().fg(Color::Yellow)),
+ line: d.line,
+ kind: TextAnnotationKind::Eol,
+ })
+ .collect(),
+ );
doc.set_diagnostics(diagnostics);
}
}

I think for an initial implementation, just end-of-line annotations are fine. As I mentioned in the linked issue, any rendering work you do here is likely to be redundant with planned future work. So keeping it to the simple case probably makes the most sense.
I'm also a little concerned that doing inline rendering right now will be a bit delicate, as the current rendering architecture isn't really set up to support it, nor is the cursor navigation system, etc. Inline annotations will need to touch a lot of systems to work properly.
In that case I'll drop the inline rendering plan and keep it as is. Cursor and selection rendering for inline annotations will definitely look hacky with the current architecture.
I'm also a little concerned that doing inline rendering right now will be a bit delicate, as the current rendering architecture isn't really set up to support it, nor is the cursor navigation system, etc. Inline annotations will need to touch a lot of systems to work properly.
Yeah, kak-lsp did the same and it is quite broken in kakoune too.
As discussed on Matrix, this PR has been revived (yay !), and I have rebased the original changes on top of current master.
Missing update in https://github.com/helix-editor/helix/blob/master/helix-core/src/position.rs I think, the visual_coords_at_pos should be updated.
This is awesome, thanks for adding support!
Is anyone using this and have made a snippet for enabling rust-analyzer type hints?
This PR as of now doesn't implement inlayed virtual text, i.e. virtual text in between normal text, which is what we would need to properly add support for rust-analyzer's type hints. Also the type hint API isn't part of the LSP spec yet, so we would have to probably wait on that too.
Ah, I see - that's unfortunate. The type hint API seems to work in vim and vs-code, what is it that they do differently? Do you know?
They usually have dedicated plugins that do the setup for you, for example I use https://github.com/nvim-lua/lsp_extensions.nvim for Neovim which sets up inlay hints for rust. VSCode's rust extension also hooks into the decoration API provided by VSC and renders them.
Also the type hint API isn't part of the LSP spec yet, so we would have to probably wait on that too.
The new spec seems final, rust-analyzer recently switched over: https://rust-analyzer.github.io/thisweek/2022/03/14/changelog-120.html#new-features
This seems to now be part of the LSP spec: https://github.com/microsoft/language-server-protocol/issues/956
This PR as of now doesn't implement inlayed virtual text, i.e. virtual text in between normal text
@sudormrfbin I quite like the inlay hints from https://github.com/simrat39/rust-tools.nvim#inlay-hints
Is it possible to make the hints show up below/above the line? If the hint is long it gets cut off when it is displayed beside the line.
+1 Would love for this PR to land, even if behind an experimental config flag :) (it hasn't already landed experimentally right...?)
Does this branch have working type hints?
LSP 3.17 has support for inlay hints https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_inlayHint
[email protected](0.93.1) has support InlayHint
language support:
- rust-analyzer
- golang gopls
- typescript
- c/c++
- java
LSP 3.17 has support for inlay hints https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_inlayHint
That should be done in another PR I think
This could also be extended to debugging, so it displays the values of variable and objects, which would be of tremendous help.
Update on this? Code folding and inlays are quite useful features currently blocked on this PR.
An update for everyone interested in this: After discussion in the matrix chat, I will be taking over work on virtual text. However after discussion with @kirawi I plan to use a different approach than this PR that will build on his work in #3268 and #2184 so that the efforts on soft-wrapping and virtual text do not end up conflicting. This will involve a generic update to the rendering system that @kirawi and I are planning to develop in cooperation.