aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/editor.rs45
-rw-r--r--helix-view/src/gutter.rs4
2 files changed, 34 insertions, 15 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index adf0cdf3..8220deb7 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -13,7 +13,6 @@ use futures_util::future;
use futures_util::stream::select_all::SelectAll;
use tokio_stream::wrappers::UnboundedReceiverStream;
-use log::debug;
use std::{
borrow::Cow,
collections::{BTreeMap, HashMap},
@@ -24,7 +23,10 @@ use std::{
sync::Arc,
};
-use tokio::time::{sleep, Duration, Instant, Sleep};
+use tokio::{
+ sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender},
+ time::{sleep, Duration, Instant, Sleep},
+};
use anyhow::{bail, Error};
@@ -40,6 +42,8 @@ use helix_dap as dap;
use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer};
+use arc_swap::access::{DynAccess, DynGuard};
+
fn deserialize_duration_millis<'de, D>(deserializer: D) -> Result<Duration, D::Error>
where
D: serde::Deserializer<'de>,
@@ -287,7 +291,6 @@ pub struct Breakpoint {
pub log_message: Option<String>,
}
-#[derive(Debug)]
pub struct Editor {
pub tree: Tree,
pub next_document_id: DocumentId,
@@ -311,7 +314,7 @@ pub struct Editor {
pub status_msg: Option<(Cow<'static, str>, Severity)>,
pub autoinfo: Option<Info>,
- pub config: Config,
+ pub config: Box<dyn DynAccess<Config>>,
pub auto_pairs: Option<AutoPairs>,
pub idle_timer: Pin<Box<Sleep>>,
@@ -321,6 +324,14 @@ pub struct Editor {
pub last_completion: Option<CompleteAction>,
pub exit_code: i32,
+
+ pub config_events: (UnboundedSender<ConfigEvent>, UnboundedReceiver<ConfigEvent>),
+}
+
+#[derive(Debug, Clone)]
+pub enum ConfigEvent {
+ Refresh,
+ Update(Config),
}
#[derive(Debug, Clone)]
@@ -342,12 +353,11 @@ impl Editor {
mut area: Rect,
theme_loader: Arc<theme::Loader>,
syn_loader: Arc<syntax::Loader>,
- config: Config,
+ config: Box<dyn DynAccess<Config>>,
) -> Self {
let language_servers = helix_lsp::Registry::new();
- let auto_pairs = (&config.auto_pairs).into();
-
- debug!("Editor config: {config:#?}");
+ let conf = config.load();
+ let auto_pairs = (&conf.auto_pairs).into();
// HAXX: offset the render area height by 1 to account for prompt/commandline
area.height -= 1;
@@ -370,16 +380,21 @@ impl Editor {
clipboard_provider: get_clipboard_provider(),
status_msg: None,
autoinfo: None,
- idle_timer: Box::pin(sleep(config.idle_timeout)),
+ idle_timer: Box::pin(sleep(conf.idle_timeout)),
last_motion: None,
last_completion: None,
pseudo_pending: None,
config,
auto_pairs,
exit_code: 0,
+ config_events: unbounded_channel(),
}
}
+ pub fn config(&self) -> DynGuard<Config> {
+ self.config.load()
+ }
+
pub fn clear_idle_timer(&mut self) {
// equivalent to internal Instant::far_future() (30 years)
self.idle_timer
@@ -388,9 +403,10 @@ impl Editor {
}
pub fn reset_idle_timer(&mut self) {
+ let config = self.config();
self.idle_timer
.as_mut()
- .reset(Instant::now() + self.config.idle_timeout);
+ .reset(Instant::now() + config.idle_timeout);
}
pub fn clear_status(&mut self) {
@@ -466,9 +482,10 @@ impl Editor {
}
fn _refresh(&mut self) {
+ let config = self.config();
for (view, _) in self.tree.views_mut() {
let doc = &self.documents[&view.doc];
- view.ensure_cursor_in_view(doc, self.config.scrolloff)
+ view.ensure_cursor_in_view(doc, config.scrolloff)
}
}
@@ -716,9 +733,10 @@ impl Editor {
}
pub fn ensure_cursor_in_view(&mut self, id: ViewId) {
+ let config = self.config();
let view = self.tree.get_mut(id);
let doc = &self.documents[&view.doc];
- view.ensure_cursor_in_view(doc, self.config.scrolloff)
+ view.ensure_cursor_in_view(doc, config.scrolloff)
}
#[inline]
@@ -752,6 +770,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)
@@ -761,7 +780,7 @@ impl Editor {
let inner = view.inner_area();
pos.col += inner.x as usize;
pos.row += inner.y as usize;
- let cursorkind = self.config.cursor_shape.from_mode(doc.mode());
+ let cursorkind = config.cursor_shape.from_mode(doc.mode());
(Some(pos), cursorkind)
} else {
(None, CursorKind::default())
diff --git a/helix-view/src/gutter.rs b/helix-view/src/gutter.rs
index 6a77c41f..7327ed1a 100644
--- a/helix-view/src/gutter.rs
+++ b/helix-view/src/gutter.rs
@@ -60,7 +60,7 @@ pub fn line_number<'doc>(
.text()
.char_to_line(doc.selection(view.id).primary().cursor(text));
- let config = editor.config.line_number;
+ let line_number = editor.config().line_number;
let mode = doc.mode;
Box::new(move |line: usize, selected: bool, out: &mut String| {
@@ -70,7 +70,7 @@ pub fn line_number<'doc>(
} else {
use crate::{document::Mode, editor::LineNumber};
- let relative = config == LineNumber::Relative
+ let relative = line_number == LineNumber::Relative
&& mode != Mode::Insert
&& is_focused
&& current_line != line;