on master help sign in
Hold a reference to executor on the Editor type.
commit51c15da3c32b2f0bf3da6db9bca9496d333ec15a authorBlaž Hrastnik <blaz@mxxn.io> dateTue 16 Mar 2021, 23:14 (6 years ago) parent8dc0b18
5 files changed+18−20
helix-term/src/application.rs+2−2 helix-term/src/commands.rs+6−10 helix-term/src/ui/editor.rs−1 helix-term/src/ui/mod.rs+2−2 helix-view/src/editor.rs+8−5
helix-term/src/application.rs+2−2
@@ -36,11 +36,11 @@ impl Application {
3636 pub fn new(mut args: Args, executor: &'static smol::Executor<'static>) -> Result<Self, Error> {
3737 let mut compositor = Compositor::new()?;
3838 let size = compositor.size();
39− let mut editor = Editor::new(size);
39+ let mut editor = Editor::new(executor, size);
4040
4141 let files = args.values_of_t::<PathBuf>("files").unwrap();
4242 for file in files {
43− editor.open(file, executor)?;
43+ editor.open(file)?;
4444 }
4545
4646 compositor.push(Box::new(ui::EditorView::new()));
helix-term/src/commands.rs+6−10
@@ -28,7 +28,6 @@ use helix_lsp::lsp;
2828pub struct Context<'a> {
2929 pub count: usize,
3030 pub editor: &'a mut Editor,
31− pub executor: &'static smol::Executor<'static>,
3231
3332 pub callback: Option<crate::compositor::Callback>,
3433 pub on_next_key_callback: Option<Box<dyn FnOnce(&mut Context, KeyEvent)>>,
@@ -658,7 +657,6 @@ const COMMAND_LIST: &[&str] = &["write", "open", "quit"];
658657
659658// TODO: I, A, o and O can share a lot of the primitives.
660659pub fn command_mode(cx: &mut Context) {
661− let executor = cx.executor;
662660 let prompt = Prompt::new(
663661 ":".to_owned(),
664662 |input: &str| {
@@ -695,11 +693,11 @@ pub fn command_mode(cx: &mut Context) {
695693
696694 match *parts.as_slice() {
697695 ["q"] | ["quit"] => {
698− editor.close(editor.view().id, executor);
696+ editor.close(editor.view().id);
699697 // editor.should_close = true,
700698 }
701699 ["o", path] | ["open", path] => {
702− editor.open(path.into(), executor);
700+ editor.open(path.into());
703701 }
704702 ["w"] | ["write"] => {
705703 // TODO: non-blocking via save() command
@@ -713,7 +711,7 @@ pub fn command_mode(cx: &mut Context) {
713711 cx.push_layer(Box::new(prompt));
714712}
715713pub fn file_picker(cx: &mut Context) {
716− let picker = ui::file_picker("./", cx.executor);
714+ let picker = ui::file_picker("./");
717715 cx.push_layer(Box::new(picker));
718716}
719717
@@ -851,15 +849,13 @@ pub fn exit_select_mode(cx: &mut Context) {
851849}
852850
853851fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
854− let executor = cx.executor;
855852 let doc = cx.doc();
856853
857854 doc.mode = Mode::Normal;
858855
859856 match locations.as_slice() {
860857 [location] => {
861− cx.editor
862− .open(PathBuf::from(location.uri.path()), cx.executor);
858+ cx.editor.open(PathBuf::from(location.uri.path()));
863859 let doc = cx.doc();
864860 let definition_pos = location.range.start;
865861 let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text().slice(..), definition_pos);
@@ -875,7 +871,7 @@ fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
875871 format!("{}:{}", file, line).into()
876872 },
877873 move |editor: &mut Editor, item| {
878− editor.open(PathBuf::from(item.uri.path()), &executor);
874+ editor.open(PathBuf::from(item.uri.path()));
879875 let mut doc = &mut editor.view_mut().doc;
880876 let definition_pos = item.range.start;
881877 let new_pos =
@@ -1274,7 +1270,7 @@ pub fn save(cx: &mut Context) {
12741270 // Spawns an async task to actually do the saving. This way we prevent blocking.
12751271
12761272 // TODO: handle save errors somehow?
1277− cx.executor.spawn(cx.doc().save()).detach();
1273+ cx.editor.executor.spawn(cx.doc().save()).detach();
12781274}
12791275
12801276pub fn completion(cx: &mut Context) {
helix-term/src/ui/editor.rs−1
@@ -436,7 +436,6 @@ impl Component for EditorView {
436436
437437 let mode = view.doc.mode();
438438 let mut cxt = commands::Context {
439− executor: cx.executor,
440439 editor: &mut cx.editor,
441440 count: 1,
442441 callback: None,
helix-term/src/ui/mod.rs+2−2
@@ -73,7 +73,7 @@ pub fn regex_prompt(
7373}
7474
7575use std::path::{Path, PathBuf};
76−pub fn file_picker(root: &str, ex: &'static smol::Executor) -> Picker<PathBuf> {
76+pub fn file_picker(root: &str) -> Picker<PathBuf> {
7777 use ignore::Walk;
7878 // TODO: determine root based on git root
7979 let files = Walk::new(root).filter_map(|entry| match entry {
@@ -98,7 +98,7 @@ pub fn file_picker(root: &str, ex: &'static smol::Executor) -> Picker<PathBuf> {
9898 path.strip_prefix("./").unwrap().to_str().unwrap().into()
9999 },
100100 move |editor: &mut Editor, path: &PathBuf| {
101− editor.open(path.into(), ex);
101+ editor.open(path.into());
102102 },
103103 )
104104}
helix-view/src/editor.rs+8−5
@@ -14,10 +14,11 @@ pub struct Editor {
1414 pub count: Option<usize>,
1515 pub theme: Theme,
1616 pub language_servers: helix_lsp::Registry,
17+ pub executor: &'static smol::Executor<'static>,
1718}
1819
1920impl Editor {
20− pub fn new(mut area: tui::layout::Rect) -> Self {
21+ pub fn new(executor: &'static smol::Executor<'static>, mut area: tui::layout::Rect) -> Self {
2122 let theme = Theme::default();
2223 let language_servers = helix_lsp::Registry::new();
2324
@@ -29,10 +30,11 @@ impl Editor {
2930 count: None,
3031 theme,
3132 language_servers,
33+ executor,
3234 }
3335 }
3436
35− pub fn open(&mut self, path: PathBuf, executor: &smol::Executor) -> Result<(), Error> {
37+ pub fn open(&mut self, path: PathBuf) -> Result<(), Error> {
3638 let existing_view = self
3739 .tree
3840 .views()
@@ -49,7 +51,7 @@ impl Editor {
4951 let language_server = doc
5052 .language
5153 .as_ref()
52− .and_then(|language| self.language_servers.get(language, &executor));
54+ .and_then(|language| self.language_servers.get(language, self.executor));
5355
5456 if let Some(language_server) = language_server {
5557 doc.set_language_server(Some(language_server.clone()));
@@ -74,17 +76,18 @@ impl Editor {
7476 Ok(())
7577 }
7678
77− pub fn close(&mut self, id: Key, executor: &smol::Executor) {
79+ pub fn close(&mut self, id: Key) {
7880 let view = self.tree.get(self.tree.focus);
7981 // get around borrowck issues
8082 let language_servers = &mut self.language_servers;
83+ let executor = self.executor;
8184
8285 let doc = &view.doc;
8386
8487 let language_server = doc
8588 .language
8689 .as_ref()
87− .and_then(|language| language_servers.get(language, &executor));
90+ .and_then(|language| language_servers.get(language, executor));
8891
8992 if let Some(language_server) = language_server {
9093 smol::block_on(language_server.text_document_did_close(doc.identifier())).unwrap();