on master help sign in
Hold a reference to executor on the Editor type.
51c15daBlaž Hrastnik
helix-term/src/application.rs+2−2
@@ -36,11 +36,11 @@ impl Application {
36 pub fn new(mut args: Args, executor: &'static smol::Executor<'static>) -> Result<Self, Error> {
36 pub fn new(mut args: Args, executor: &'static smol::Executor<'static>) -> Result<Self, Error> {
37 let mut compositor = Compositor::new()?;
37 let mut compositor = Compositor::new()?;
38 let size = compositor.size();
38 let size = compositor.size();
39− let mut editor = Editor::new(size);
39+ let mut editor = Editor::new(executor, size);
40
40
41 let files = args.values_of_t::<PathBuf>("files").unwrap();
41 let files = args.values_of_t::<PathBuf>("files").unwrap();
42 for file in files {
42 for file in files {
43− editor.open(file, executor)?;
43+ editor.open(file)?;
44 }
44 }
45
45
46 compositor.push(Box::new(ui::EditorView::new()));
46 compositor.push(Box::new(ui::EditorView::new()));
helix-term/src/commands.rs+6−10
@@ -28,7 +28,6 @@ use helix_lsp::lsp;
28pub struct Context<'a> {
28pub struct Context<'a> {
29 pub count: usize,
29 pub count: usize,
30 pub editor: &'a mut Editor,
30 pub editor: &'a mut Editor,
31− pub executor: &'static smol::Executor<'static>,
32
31
33 pub callback: Option<crate::compositor::Callback>,
32 pub callback: Option<crate::compositor::Callback>,
34 pub on_next_key_callback: Option<Box<dyn FnOnce(&mut Context, KeyEvent)>>,
33 pub on_next_key_callback: Option<Box<dyn FnOnce(&mut Context, KeyEvent)>>,
@@ -658,7 +657,6 @@ const COMMAND_LIST: &[&str] = &["write", "open", "quit"];
658
657
659// TODO: I, A, o and O can share a lot of the primitives.
658// TODO: I, A, o and O can share a lot of the primitives.
660pub fn command_mode(cx: &mut Context) {
659pub fn command_mode(cx: &mut Context) {
661− let executor = cx.executor;
662 let prompt = Prompt::new(
660 let prompt = Prompt::new(
663 ":".to_owned(),
661 ":".to_owned(),
664 |input: &str| {
662 |input: &str| {
@@ -695,11 +693,11 @@ pub fn command_mode(cx: &mut Context) {
695
693
696 match *parts.as_slice() {
694 match *parts.as_slice() {
697 ["q"] | ["quit"] => {
695 ["q"] | ["quit"] => {
698− editor.close(editor.view().id, executor);
696+ editor.close(editor.view().id);
699 // editor.should_close = true,
697 // editor.should_close = true,
700 }
698 }
701 ["o", path] | ["open", path] => {
699 ["o", path] | ["open", path] => {
702− editor.open(path.into(), executor);
700+ editor.open(path.into());
703 }
701 }
704 ["w"] | ["write"] => {
702 ["w"] | ["write"] => {
705 // TODO: non-blocking via save() command
703 // TODO: non-blocking via save() command
@@ -713,7 +711,7 @@ pub fn command_mode(cx: &mut Context) {
713 cx.push_layer(Box::new(prompt));
711 cx.push_layer(Box::new(prompt));
714}
712}
715pub fn file_picker(cx: &mut Context) {
713pub fn file_picker(cx: &mut Context) {
716− let picker = ui::file_picker("./", cx.executor);
714+ let picker = ui::file_picker("./");
717 cx.push_layer(Box::new(picker));
715 cx.push_layer(Box::new(picker));
718}
716}
719
717
@@ -851,15 +849,13 @@ pub fn exit_select_mode(cx: &mut Context) {
851}
849}
852
850
853fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
851fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
854− let executor = cx.executor;
855 let doc = cx.doc();
852 let doc = cx.doc();
856
853
857 doc.mode = Mode::Normal;
854 doc.mode = Mode::Normal;
858
855
859 match locations.as_slice() {
856 match locations.as_slice() {
860 [location] => {
857 [location] => {
861− cx.editor
862− .open(PathBuf::from(location.uri.path()), cx.executor);
858+ cx.editor.open(PathBuf::from(location.uri.path()));
863 let doc = cx.doc();
859 let doc = cx.doc();
864 let definition_pos = location.range.start;
860 let definition_pos = location.range.start;
865 let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text().slice(..), definition_pos);
861 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>) {
875 format!("{}:{}", file, line).into()
871 format!("{}:{}", file, line).into()
876 },
872 },
877 move |editor: &mut Editor, item| {
873 move |editor: &mut Editor, item| {
878− editor.open(PathBuf::from(item.uri.path()), &executor);
874+ editor.open(PathBuf::from(item.uri.path()));
879 let mut doc = &mut editor.view_mut().doc;
875 let mut doc = &mut editor.view_mut().doc;
880 let definition_pos = item.range.start;
876 let definition_pos = item.range.start;
881 let new_pos =
877 let new_pos =
@@ -1274,7 +1270,7 @@ pub fn save(cx: &mut Context) {
1274 // Spawns an async task to actually do the saving. This way we prevent blocking.
1270 // Spawns an async task to actually do the saving. This way we prevent blocking.
1275
1271
1276 // TODO: handle save errors somehow?
1272 // TODO: handle save errors somehow?
1277− cx.executor.spawn(cx.doc().save()).detach();
1273+ cx.editor.executor.spawn(cx.doc().save()).detach();
1278}
1274}
1279
1275
1280pub fn completion(cx: &mut Context) {
1276pub fn completion(cx: &mut Context) {
helix-term/src/ui/editor.rs−1
@@ -436,7 +436,6 @@ impl Component for EditorView {
436
436
437 let mode = view.doc.mode();
437 let mode = view.doc.mode();
438 let mut cxt = commands::Context {
438 let mut cxt = commands::Context {
439− executor: cx.executor,
440 editor: &mut cx.editor,
439 editor: &mut cx.editor,
441 count: 1,
440 count: 1,
442 callback: None,
441 callback: None,
helix-term/src/ui/mod.rs+2−2
@@ -73,7 +73,7 @@ pub fn regex_prompt(
73}
73}
74
74
75use std::path::{Path, PathBuf};
75use 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> {
77 use ignore::Walk;
77 use ignore::Walk;
78 // TODO: determine root based on git root
78 // TODO: determine root based on git root
79 let files = Walk::new(root).filter_map(|entry| match entry {
79 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> {
98 path.strip_prefix("./").unwrap().to_str().unwrap().into()
98 path.strip_prefix("./").unwrap().to_str().unwrap().into()
99 },
99 },
100 move |editor: &mut Editor, path: &PathBuf| {
100 move |editor: &mut Editor, path: &PathBuf| {
101− editor.open(path.into(), ex);
101+ editor.open(path.into());
102 },
102 },
103 )
103 )
104}
104}
helix-view/src/editor.rs+8−5
@@ -14,10 +14,11 @@ pub struct Editor {
14 pub count: Option<usize>,
14 pub count: Option<usize>,
15 pub theme: Theme,
15 pub theme: Theme,
16 pub language_servers: helix_lsp::Registry,
16 pub language_servers: helix_lsp::Registry,
17+ pub executor: &'static smol::Executor<'static>,
17}
18}
18
19
19impl Editor {
20impl 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 {
21 let theme = Theme::default();
22 let theme = Theme::default();
22 let language_servers = helix_lsp::Registry::new();
23 let language_servers = helix_lsp::Registry::new();
23
24
@@ -29,10 +30,11 @@ impl Editor {
29 count: None,
30 count: None,
30 theme,
31 theme,
31 language_servers,
32 language_servers,
33+ executor,
32 }
34 }
33 }
35 }
34
36
35− pub fn open(&mut self, path: PathBuf, executor: &smol::Executor) -> Result<(), Error> {
37+ pub fn open(&mut self, path: PathBuf) -> Result<(), Error> {
36 let existing_view = self
38 let existing_view = self
37 .tree
39 .tree
38 .views()
40 .views()
@@ -49,7 +51,7 @@ impl Editor {
49 let language_server = doc
51 let language_server = doc
50 .language
52 .language
51 .as_ref()
53 .as_ref()
52− .and_then(|language| self.language_servers.get(language, &executor));
54+ .and_then(|language| self.language_servers.get(language, self.executor));
53
55
54 if let Some(language_server) = language_server {
56 if let Some(language_server) = language_server {
55 doc.set_language_server(Some(language_server.clone()));
57 doc.set_language_server(Some(language_server.clone()));
@@ -74,17 +76,18 @@ impl Editor {
74 Ok(())
76 Ok(())
75 }
77 }
76
78
77− pub fn close(&mut self, id: Key, executor: &smol::Executor) {
79+ pub fn close(&mut self, id: Key) {
78 let view = self.tree.get(self.tree.focus);
80 let view = self.tree.get(self.tree.focus);
79 // get around borrowck issues
81 // get around borrowck issues
80 let language_servers = &mut self.language_servers;
82 let language_servers = &mut self.language_servers;
83+ let executor = self.executor;
81
84
82 let doc = &view.doc;
85 let doc = &view.doc;
83
86
84 let language_server = doc
87 let language_server = doc
85 .language
88 .language
86 .as_ref()
89 .as_ref()
87− .and_then(|language| language_servers.get(language, &executor));
90+ .and_then(|language| language_servers.get(language, executor));
88
91
89 if let Some(language_server) = language_server {
92 if let Some(language_server) = language_server {
90 smol::block_on(language_server.text_document_did_close(doc.identifier())).unwrap();
93 smol::block_on(language_server.text_document_did_close(doc.identifier())).unwrap();