diff options
Diffstat (limited to 'helix-view/src/editor.rs')
-rw-r--r-- | helix-view/src/editor.rs | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 24f43c0e..db8ae87a 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -2,7 +2,9 @@ use crate::{theme::Theme, tree::Tree, Document, DocumentId, RegisterSelection, V use tui::layout::Rect; use tui::terminal::CursorKind; +use futures_util::future; use std::path::PathBuf; +use std::time::Duration; use slotmap::SlotMap; @@ -101,19 +103,19 @@ impl Editor { match action { Action::Replace => { - let view = self.view(); + let view = view!(self); let jump = ( view.doc, self.documents[view.doc].selection(view.id).clone(), ); - let view = self.view_mut(); + let view = view_mut!(self); view.jumps.push(jump); view.last_accessed_doc = Some(view.doc); view.doc = id; view.first_line = 0; - let (view, doc) = self.current(); + let (view, doc) = current!(self); // initialize selection for view let selection = doc @@ -238,27 +240,6 @@ impl Editor { self.tree.is_empty() } - pub fn current(&mut self) -> (&mut View, &mut Document) { - let view = self.tree.get_mut(self.tree.focus); - let doc = &mut self.documents[view.doc]; - (view, doc) - } - - pub fn current_with_registers(&mut self) -> (&mut View, &mut Document, &mut Registers) { - let view = self.tree.get_mut(self.tree.focus); - let doc = &mut self.documents[view.doc]; - let registers = &mut self.registers; - (view, doc, registers) - } - - pub fn view(&self) -> &View { - self.tree.get(self.tree.focus) - } - - pub fn view_mut(&mut self) -> &mut View { - self.tree.get_mut(self.tree.focus) - } - pub fn ensure_cursor_in_view(&mut self, id: ViewId) { let view = self.tree.get_mut(id); let doc = &self.documents[view.doc]; @@ -280,7 +261,7 @@ impl Editor { pub fn cursor(&self) -> (Option<Position>, CursorKind) { const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter - let view = self.view(); + let view = view!(self); let doc = &self.documents[view.doc]; let cursor = doc.selection(view.id).cursor(); if let Some(mut pos) = view.screen_coords_at_pos(doc, doc.text().slice(..), cursor) { @@ -291,4 +272,22 @@ impl Editor { (None, CursorKind::Hidden) } } + + /// Closes language servers with timeout. The default timeout is 500 ms, use + /// `timeout` parameter to override this. + pub async fn close_language_servers( + &self, + timeout: Option<u64>, + ) -> Result<(), tokio::time::error::Elapsed> { + tokio::time::timeout( + Duration::from_millis(timeout.unwrap_or(500)), + future::join_all( + self.language_servers + .iter_clients() + .map(|client| client.force_shutdown()), + ), + ) + .await + .map(|_| ()) + } } |