summaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-05-06 04:56:34 +0000
committerBlaž Hrastnik2021-05-06 04:56:34 +0000
commit355ad3cb8289611b06cd42fa62ddfe0a5c716e83 (patch)
tree7c94da6e122a9ecf542103b46a3ca9e80654a52e /helix-term/src
parent0e5308bce1a6e7d7d00854ae50902546cea9578d (diff)
Tokio migration.
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/application.rs14
-rw-r--r--helix-term/src/commands.rs42
-rw-r--r--helix-term/src/compositor.rs2
-rw-r--r--helix-term/src/main.rs14
-rw-r--r--helix-term/src/ui/editor.rs3
5 files changed, 36 insertions, 39 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index 8849ee81..3bf746ea 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -7,14 +7,13 @@ use crate::{compositor::Compositor, ui};
use log::{error, info};
use std::{
+ future::Future,
io::{self, stdout, Stdout, Write},
path::PathBuf,
sync::Arc,
time::Duration,
};
-use smol::prelude::*;
-
use anyhow::Error;
use crossterm::{
@@ -39,16 +38,15 @@ pub struct Application {
compositor: Compositor,
editor: Editor,
- executor: &'static smol::Executor<'static>,
callbacks: LspCallbacks,
}
impl Application {
- pub fn new(mut args: Args, executor: &'static smol::Executor<'static>) -> Result<Self, Error> {
+ pub fn new(mut args: Args) -> Result<Self, Error> {
use helix_view::editor::Action;
let mut compositor = Compositor::new()?;
let size = compositor.size();
- let mut editor = Editor::new(executor, size);
+ let mut editor = Editor::new(size);
if let Ok(files) = args.values_of_t::<PathBuf>("files") {
for file in files {
@@ -64,7 +62,6 @@ impl Application {
compositor,
editor,
- executor,
callbacks: FuturesUnordered::new(),
};
@@ -72,14 +69,12 @@ impl Application {
}
fn render(&mut self) {
- let executor = &self.executor;
let editor = &mut self.editor;
let compositor = &mut self.compositor;
let callbacks = &mut self.callbacks;
let mut cx = crate::compositor::Context {
editor,
- executor,
callbacks,
scroll: None,
};
@@ -97,7 +92,7 @@ impl Application {
break;
}
- use futures_util::{select, FutureExt};
+ use futures_util::{select, FutureExt, StreamExt};
select! {
event = reader.next().fuse() => {
self.handle_terminal_events(event)
@@ -125,7 +120,6 @@ impl Application {
pub fn handle_terminal_events(&mut self, event: Option<Result<Event, crossterm::ErrorKind>>) {
let mut cx = crate::compositor::Context {
editor: &mut self.editor,
- executor: self.executor,
callbacks: &mut self.callbacks,
scroll: None,
};
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 72ebf7f9..3292d39f 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -108,6 +108,16 @@ impl<'a> Context<'a> {
/// state (usually by creating and applying a transaction).
pub type Command = fn(cx: &mut Context);
+#[inline]
+fn block_on<T>(future: impl Future<Output = T>) -> T {
+ use tokio::runtime::Runtime;
+ // let rt = Runtime::new().unwrap();
+ let rt = tokio::runtime::Handle::current();
+ // let local = LocalSet::new();
+ // local.block_on(&rt, future)
+ rt.block_on(future)
+}
+
pub fn move_char_left(cx: &mut Context) {
let count = cx.count;
let (view, doc) = cx.current();
@@ -861,7 +871,6 @@ pub fn command_mode(cx: &mut Context) {
match *parts.as_slice() {
["q"] | ["quit"] => {
editor.close(editor.view().id);
- // editor.should_close = true,
}
["o", path] | ["open", path] => {
use helix_view::editor::Action;
@@ -871,7 +880,7 @@ pub fn command_mode(cx: &mut Context) {
// TODO: non-blocking via save() command
let id = editor.view().doc;
let doc = &mut editor.documents[id];
- smol::block_on(doc.save());
+ block_on(doc.save());
}
_ => (),
@@ -1175,8 +1184,7 @@ pub fn goto_definition(cx: &mut Context) {
let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
// TODO: handle fails
- let res =
- smol::block_on(language_server.goto_definition(doc.identifier(), pos)).unwrap_or_default();
+ let res = block_on(language_server.goto_definition(doc.identifier(), pos)).unwrap_or_default();
_goto(cx, res, offset_encoding);
}
@@ -1192,8 +1200,8 @@ pub fn goto_type_definition(cx: &mut Context) {
let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
// TODO: handle fails
- let res = smol::block_on(language_server.goto_type_definition(doc.identifier(), pos))
- .unwrap_or_default();
+ let res =
+ block_on(language_server.goto_type_definition(doc.identifier(), pos)).unwrap_or_default();
_goto(cx, res, offset_encoding);
}
@@ -1209,8 +1217,8 @@ pub fn goto_implementation(cx: &mut Context) {
let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
// TODO: handle fails
- let res = smol::block_on(language_server.goto_implementation(doc.identifier(), pos))
- .unwrap_or_default();
+ let res =
+ block_on(language_server.goto_implementation(doc.identifier(), pos)).unwrap_or_default();
_goto(cx, res, offset_encoding);
}
@@ -1226,8 +1234,7 @@ pub fn goto_reference(cx: &mut Context) {
let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
// TODO: handle fails
- let res =
- smol::block_on(language_server.goto_reference(doc.identifier(), pos)).unwrap_or_default();
+ let res = block_on(language_server.goto_reference(doc.identifier(), pos)).unwrap_or_default();
_goto(cx, res, offset_encoding);
}
@@ -1247,7 +1254,7 @@ pub fn signature_help(cx: &mut Context) {
// TODO: handle fails
- let res = smol::block_on(language_server.text_document_signature_help(doc.identifier(), pos))
+ let res = block_on(language_server.text_document_signature_help(doc.identifier(), pos))
.unwrap_or_default();
if let Some(signature_help) = res {
@@ -1636,7 +1643,7 @@ pub fn format_selections(cx: &mut Context) {
};
// TODO: handle fails
// TODO: concurrent map
- let edits = smol::block_on(language_server.text_document_range_formatting(
+ let edits = block_on(language_server.text_document_range_formatting(
doc.identifier(),
range,
lsp::FormattingOptions::default(),
@@ -1726,7 +1733,8 @@ pub fn save(cx: &mut Context) {
// Spawns an async task to actually do the saving. This way we prevent blocking.
// TODO: handle save errors somehow?
- cx.editor.executor.spawn(cx.doc().save()).detach();
+ // TODO: don't block
+ block_on(cx.doc().save());
}
pub fn completion(cx: &mut Context) {
@@ -1782,7 +1790,7 @@ pub fn completion(cx: &mut Context) {
);
// TODO: handle fails
- let res = smol::block_on(language_server.completion(doc.identifier(), pos)).unwrap();
+ let res = block_on(language_server.completion(doc.identifier(), pos)).unwrap();
let trigger_offset = doc.selection(view.id).cursor();
@@ -1839,8 +1847,8 @@ pub fn hover(cx: &mut Context) {
);
// TODO: handle fails
- let res = smol::block_on(language_server.text_document_hover(doc.identifier(), pos))
- .unwrap_or_default();
+ let res =
+ block_on(language_server.text_document_hover(doc.identifier(), pos)).unwrap_or_default();
if let Some(hover) = res {
// hover.contents / .range <- used for visualizing
@@ -1963,7 +1971,7 @@ pub fn space_mode(cx: &mut Context) {
'w' => {
// save current buffer
let doc = cx.doc();
- smol::block_on(doc.save());
+ block_on(doc.save());
}
'c' => {
// close current split
diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs
index 6e81cc81..4570cab9 100644
--- a/helix-term/src/compositor.rs
+++ b/helix-term/src/compositor.rs
@@ -4,7 +4,6 @@
use crossterm::event::Event;
use helix_core::Position;
-use smol::Executor;
use tui::{buffer::Buffer as Surface, layout::Rect};
pub type Callback = Box<dyn FnOnce(&mut Compositor, &mut Editor)>;
@@ -29,7 +28,6 @@ use crate::application::LspCallbacks;
pub struct Context<'a> {
pub editor: &'a mut Editor,
- pub executor: &'static smol::Executor<'static>,
pub scroll: Option<usize>,
pub callbacks: &'a mut LspCallbacks,
}
diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs
index 612f8cf0..b0d244b7 100644
--- a/helix-term/src/main.rs
+++ b/helix-term/src/main.rs
@@ -14,8 +14,6 @@ use std::path::PathBuf;
use anyhow::Error;
-static EX: smol::Executor = smol::Executor::new();
-
fn setup_logging(verbosity: u64) -> Result<(), fern::InitError> {
let mut base_config = fern::Dispatch::new();
@@ -88,12 +86,12 @@ fn main() {
Loader::new(config)
});
- for _ in 0..num_cpus::get() {
- std::thread::spawn(move || smol::block_on(EX.run(smol::future::pending::<()>())));
- }
+ let runtime = tokio::runtime::Runtime::new().unwrap();
- let mut app = Application::new(args, &EX).unwrap();
+ // TODO: use the thread local executor to spawn the application task separately from the work pool
+ runtime.block_on(async move {
+ let mut app = Application::new(args).unwrap();
- // we use the thread local executor to spawn the application task separately from the work pool
- smol::block_on(app.run());
+ app.run().await;
+ });
}
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index 041096d6..49024226 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -207,7 +207,7 @@ impl EditorView {
});
let style = if is_diagnostic {
- style.clone().add_modifier(Modifier::UNDERLINED)
+ style.add_modifier(Modifier::UNDERLINED)
} else {
style
};
@@ -569,7 +569,6 @@ impl Component for EditorView {
let mut cx = Context {
editor: cxt.editor,
callbacks: cxt.callbacks,
- executor: cx.executor,
scroll: None,
};
let res = completion.handle_event(event, &mut cx);