Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-view/src/editor.rs')
-rw-r--r--helix-view/src/editor.rs45
1 files changed, 34 insertions, 11 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 29059095..cead30d7 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -1,5 +1,6 @@
use crate::{
align_view,
+ annotations::diagnostics::{DiagnosticFilter, InlineDiagnosticsConfig},
document::{
DocumentOpenError, DocumentSavedEventFuture, DocumentSavedEventResult, Mode, SavePoint,
},
@@ -343,6 +344,9 @@ pub struct Config {
deserialize_with = "deserialize_alphabet"
)]
pub jump_label_alphabet: Vec<char>,
+ /// Display diagnostic below the line they occur.
+ pub inline_diagnostics: InlineDiagnosticsConfig,
+ pub end_of_line_diagnostics: DiagnosticFilter,
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq, PartialOrd, Ord)]
@@ -975,6 +979,8 @@ impl Default for Config {
popup_border: PopupBorderConfig::None,
indent_heuristic: IndentationHeuristic::default(),
jump_label_alphabet: ('a'..='z').collect(),
+ inline_diagnostics: InlineDiagnosticsConfig::default(),
+ end_of_line_diagnostics: DiagnosticFilter::Disable,
}
}
}
@@ -1070,10 +1076,10 @@ pub struct Editor {
/// This cache is only a performance optimization to
/// avoid calculating the cursor position multiple
/// times during rendering and should not be set by other functions.
- pub cursor_cache: Cell<Option<Option<Position>>>,
pub handlers: Handlers,
pub mouse_down_range: Option<Range>,
+ pub cursor_cache: CursorCache,
}
pub type Motion = Box<dyn Fn(&mut Editor)>;
@@ -1188,9 +1194,9 @@ impl Editor {
exit_code: 0,
config_events: unbounded_channel(),
needs_redraw: false,
- cursor_cache: Cell::new(None),
handlers,
mouse_down_range: None,
+ cursor_cache: CursorCache::default(),
}
}
@@ -1985,15 +1991,7 @@ impl Editor {
pub fn cursor(&self) -> (Option<Position>, CursorKind) {
let config = self.config();
let (view, doc) = current_ref!(self);
- let cursor = doc
- .selection(view.id)
- .primary()
- .cursor(doc.text().slice(..));
- let pos = self
- .cursor_cache
- .get()
- .unwrap_or_else(|| view.screen_coords_at_pos(doc, doc.text().slice(..), cursor));
- if let Some(mut pos) = pos {
+ if let Some(mut pos) = self.cursor_cache.get(view, doc) {
let inner = view.inner_area(doc);
pos.col += inner.x as usize;
pos.row += inner.y as usize;
@@ -2188,3 +2186,28 @@ fn try_restore_indent(doc: &mut Document, view: &mut View) {
doc.apply(&transaction, view.id);
}
}
+
+#[derive(Default)]
+pub struct CursorCache(Cell<Option<Option<Position>>>);
+
+impl CursorCache {
+ pub fn get(&self, view: &View, doc: &Document) -> Option<Position> {
+ if let Some(pos) = self.0.get() {
+ return pos;
+ }
+
+ let text = doc.text().slice(..);
+ let cursor = doc.selection(view.id).primary().cursor(text);
+ let res = view.screen_coords_at_pos(doc, text, cursor);
+ self.set(res);
+ res
+ }
+
+ pub fn set(&self, cursor_pos: Option<Position>) {
+ self.0.set(Some(cursor_pos))
+ }
+
+ pub fn reset(&self) {
+ self.0.set(None)
+ }
+}