Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-view/src/view.rs')
-rw-r--r--helix-view/src/view.rs81
1 files changed, 52 insertions, 29 deletions
diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs
index 4c067494..af4fdfe4 100644
--- a/helix-view/src/view.rs
+++ b/helix-view/src/view.rs
@@ -1,8 +1,10 @@
use crate::{
align_view,
+ annotations::diagnostics::InlineDiagnostics,
document::DocumentInlayHints,
editor::{GutterConfig, GutterType},
graphics::Rect,
+ handlers::diagnostics::DiagnosticsHandler,
Align, Document, DocumentId, Theme, ViewId,
};
@@ -146,6 +148,14 @@ pub struct View {
/// mapping keeps track of the last applied history revision so that only new changes
/// are applied.
doc_revisions: HashMap<DocumentId, usize>,
+ // HACKS: there should really only be a global diagnostics handler (the
+ // non-focused views should just not have different handling for the cursor
+ // line). For that we would need accces to editor everywhere (we want to use
+ // the positioning code) so this can only happen by refactoring View and
+ // Document into entity component like structure. That is a huge refactor
+ // left to future work. For now we treat all views as focused and give them
+ // each their own handler.
+ pub diagnostics_handler: DiagnosticsHandler,
}
impl fmt::Debug for View {
@@ -175,6 +185,7 @@ impl View {
object_selections: Vec::new(),
gutters,
doc_revisions: HashMap::new(),
+ diagnostics_handler: DiagnosticsHandler::new(),
}
}
@@ -392,11 +403,6 @@ impl View {
text: RopeSlice,
pos: usize,
) -> Option<Position> {
- if pos < self.offset.anchor {
- // Line is not visible on screen
- return None;
- }
-
let viewport = self.inner_area(doc);
let text_fmt = doc.text_format(viewport.width, None);
let annotations = self.text_annotations(doc, None);
@@ -438,37 +444,54 @@ impl View {
text_annotations.add_overlay(labels, style);
}
- let DocumentInlayHints {
+ if let Some(DocumentInlayHints {
id: _,
type_inlay_hints,
parameter_inlay_hints,
other_inlay_hints,
padding_before_inlay_hints,
padding_after_inlay_hints,
- } = match doc.inlay_hints.get(&self.id) {
- Some(doc_inlay_hints) => doc_inlay_hints,
- None => return text_annotations,
- };
+ }) = doc.inlay_hints.get(&self.id)
+ {
+ let type_style = theme
+ .and_then(|t| t.find_scope_index("ui.virtual.inlay-hint.type"))
+ .map(Highlight);
+ let parameter_style = theme
+ .and_then(|t| t.find_scope_index("ui.virtual.inlay-hint.parameter"))
+ .map(Highlight);
+ let other_style = theme
+ .and_then(|t| t.find_scope_index("ui.virtual.inlay-hint"))
+ .map(Highlight);
- let type_style = theme
- .and_then(|t| t.find_scope_index("ui.virtual.inlay-hint.type"))
- .map(Highlight);
- let parameter_style = theme
- .and_then(|t| t.find_scope_index("ui.virtual.inlay-hint.parameter"))
- .map(Highlight);
- let other_style = theme
- .and_then(|t| t.find_scope_index("ui.virtual.inlay-hint"))
- .map(Highlight);
-
- // Overlapping annotations are ignored apart from the first so the order here is not random:
- // types -> parameters -> others should hopefully be the "correct" order for most use cases,
- // with the padding coming before and after as expected.
- text_annotations
- .add_inline_annotations(padding_before_inlay_hints, None)
- .add_inline_annotations(type_inlay_hints, type_style)
- .add_inline_annotations(parameter_inlay_hints, parameter_style)
- .add_inline_annotations(other_inlay_hints, other_style)
- .add_inline_annotations(padding_after_inlay_hints, None);
+ // Overlapping annotations are ignored apart from the first so the order here is not random:
+ // types -> parameters -> others should hopefully be the "correct" order for most use cases,
+ // with the padding coming before and after as expected.
+ text_annotations
+ .add_inline_annotations(padding_before_inlay_hints, None)
+ .add_inline_annotations(type_inlay_hints, type_style)
+ .add_inline_annotations(parameter_inlay_hints, parameter_style)
+ .add_inline_annotations(other_inlay_hints, other_style)
+ .add_inline_annotations(padding_after_inlay_hints, None);
+ };
+ let config = doc.config.load();
+ let width = self.inner_width(doc);
+ let enable_cursor_line = self
+ .diagnostics_handler
+ .show_cursorline_diagnostics(doc, self.id);
+ let config = config.inline_diagnostics.prepare(width, enable_cursor_line);
+ if !config.disabled() {
+ let cursor = doc
+ .selection(self.id)
+ .primary()
+ .cursor(doc.text().slice(..));
+ text_annotations.add_line_annotation(InlineDiagnostics::new(
+ doc,
+ cursor,
+ width,
+ self.offset.horizontal_offset,
+ config,
+ ));
+ }
text_annotations
}