on master help sign in
Tokio migration.
commit355ad3cb8289611b06cd42fa62ddfe0a5c716e83 authorBlaž Hrastnik <blaz@mxxn.io> dateThu 6 May 2021, 13:56 (5 years ago) parent0e5308b
15 files changed+169−378
Cargo.lock+51−257 helix-lsp/Cargo.toml+2−2 helix-lsp/src/client.rs+42−37 helix-lsp/src/lib.rs+8−10 helix-lsp/src/select_all.rs+1−1 helix-lsp/src/transport.rs+15−19 helix-term/Cargo.toml+1−2 helix-term/src/application.rs+4−10 helix-term/src/commands.rs+25−17 helix-term/src/compositor.rs−2 helix-term/src/main.rs+6−8 helix-term/src/ui/editor.rs+1−2 helix-view/Cargo.toml+1−1 helix-view/src/document.rs+4−2 helix-view/src/editor.rs+8−8
Cargo.lock+51−257
@@ -17,112 +17,6 @@ version = "1.0.40"
1717source = "registry+https://github.com/rust-lang/crates.io-index"
1818checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b"
1919
20−[[package]]
21−name = "async-channel"
22−version = "1.6.1"
23−source = "registry+https://github.com/rust-lang/crates.io-index"
24−checksum = "2114d64672151c0c5eaa5e131ec84a74f06e1e559830dabba01ca30605d66319"
25−dependencies = [
26− "concurrent-queue",
27− "event-listener",
28− "futures-core",
29−]
30−
31−[[package]]
32−name = "async-executor"
33−version = "1.4.1"
34−source = "registry+https://github.com/rust-lang/crates.io-index"
35−checksum = "871f9bb5e0a22eeb7e8cf16641feb87c9dc67032ccf8ff49e772eb9941d3a965"
36−dependencies = [
37− "async-task",
38− "concurrent-queue",
39− "fastrand",
40− "futures-lite",
41− "once_cell",
42− "slab",
43−]
44−
45−[[package]]
46−name = "async-fs"
47−version = "1.5.0"
48−source = "registry+https://github.com/rust-lang/crates.io-index"
49−checksum = "8b3ca4f8ff117c37c278a2f7415ce9be55560b846b5bc4412aaa5d29c1c3dae2"
50−dependencies = [
51− "async-lock",
52− "blocking",
53− "futures-lite",
54−]
55−
56−[[package]]
57−name = "async-io"
58−version = "1.4.1"
59−source = "registry+https://github.com/rust-lang/crates.io-index"
60−checksum = "4bbfd5cf2794b1e908ea8457e6c45f8f8f1f6ec5f74617bf4662623f47503c3b"
61−dependencies = [
62− "concurrent-queue",
63− "fastrand",
64− "futures-lite",
65− "libc",
66− "log",
67− "once_cell",
68− "parking",
69− "polling",
70− "slab",
71− "socket2",
72− "waker-fn",
73− "winapi",
74−]
75−
76−[[package]]
77−name = "async-lock"
78−version = "2.4.0"
79−source = "registry+https://github.com/rust-lang/crates.io-index"
80−checksum = "e6a8ea61bf9947a1007c5cada31e647dbc77b103c679858150003ba697ea798b"
81−dependencies = [
82− "event-listener",
83−]
84−
85−[[package]]
86−name = "async-net"
87−version = "1.6.0"
88−source = "registry+https://github.com/rust-lang/crates.io-index"
89−checksum = "69b0a74e7f70af3c8cf1aa539edbd044795706659ac52b78a71dc1a205ecefdf"
90−dependencies = [
91− "async-io",
92− "blocking",
93− "fastrand",
94− "futures-lite",
95−]
96−
97−[[package]]
98−name = "async-process"
99−version = "1.1.0"
100−source = "registry+https://github.com/rust-lang/crates.io-index"
101−checksum = "a8f38756dd9ac84671c428afbf7c9f7495feff9ec5b0710f17100098e5b354ac"
102−dependencies = [
103− "async-io",
104− "blocking",
105− "cfg-if",
106− "event-listener",
107− "futures-lite",
108− "libc",
109− "once_cell",
110− "signal-hook 0.3.8",
111− "winapi",
112−]
113−
114−[[package]]
115−name = "async-task"
116−version = "4.0.3"
117−source = "registry+https://github.com/rust-lang/crates.io-index"
118−checksum = "e91831deabf0d6d7ec49552e489aed63b7456a7a3c46cff62adad428110b0af0"
119−
120−[[package]]
121−name = "atomic-waker"
122−version = "1.0.0"
123−source = "registry+https://github.com/rust-lang/crates.io-index"
124−checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a"
125−
12620[[package]]
12721name = "autocfg"
12822version = "1.0.1"
@@ -135,20 +29,6 @@ version = "1.2.1"
13529source = "registry+https://github.com/rust-lang/crates.io-index"
13630checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
13731
138−[[package]]
139−name = "blocking"
140−version = "1.0.2"
141−source = "registry+https://github.com/rust-lang/crates.io-index"
142−checksum = "c5e170dbede1f740736619b776d7251cb1b9095c435c34d8ca9f57fcd2f335e9"
143−dependencies = [
144− "async-channel",
145− "async-task",
146− "atomic-waker",
147− "fastrand",
148− "futures-lite",
149− "once_cell",
150−]
151−
15232[[package]]
15333name = "bstr"
15434version = "0.2.16"
@@ -159,10 +39,10 @@ dependencies = [
15939]
16040
16141[[package]]
162−name = "cache-padded"
163−version = "1.1.1"
42+name = "bytes"
43+version = "1.0.1"
16444source = "registry+https://github.com/rust-lang/crates.io-index"
165−checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba"
45+checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040"
16646
16747[[package]]
16848name = "cassowary"
@@ -212,15 +92,6 @@ dependencies = [
21292 "vec_map",
21393]
21494
215−[[package]]
216−name = "concurrent-queue"
217−version = "1.2.2"
218−source = "registry+https://github.com/rust-lang/crates.io-index"
219−checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3"
220−dependencies = [
221− "cache-padded",
222−]
223−
22495[[package]]
22596name = "crossbeam-utils"
22697version = "0.8.4"
@@ -245,7 +116,7 @@ dependencies = [
245116 "libc",
246117 "mio",
247118 "parking_lot",
248− "signal-hook 0.1.17",
119+ "signal-hook",
249120 "winapi",
250121]
251122
@@ -279,21 +150,6 @@ dependencies = [
279150 "winapi",
280151]
281152
282−[[package]]
283−name = "event-listener"
284−version = "2.5.1"
285−source = "registry+https://github.com/rust-lang/crates.io-index"
286−checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59"
287−
288−[[package]]
289−name = "fastrand"
290−version = "1.4.1"
291−source = "registry+https://github.com/rust-lang/crates.io-index"
292−checksum = "77b705829d1e87f762c2df6da140b26af5839e1033aa84aa5f56bb688e4e1bdb"
293−dependencies = [
294− "instant",
295−]
296−
297153[[package]]
298154name = "fern"
299155version = "0.6.0"
@@ -377,21 +233,6 @@ version = "0.3.14"
377233source = "registry+https://github.com/rust-lang/crates.io-index"
378234checksum = "365a1a1fb30ea1c03a830fdb2158f5236833ac81fa0ad12fe35b29cddc35cb04"
379235
380−[[package]]
381−name = "futures-lite"
382−version = "1.11.3"
383−source = "registry+https://github.com/rust-lang/crates.io-index"
384−checksum = "b4481d0cd0de1d204a4fa55e7d45f07b1d958abcb06714b3446438e2eff695fb"
385−dependencies = [
386− "fastrand",
387− "futures-core",
388− "futures-io",
389− "memchr",
390− "parking",
391− "pin-project-lite 0.2.6",
392− "waker-fn",
393−]
394−
395236[[package]]
396237name = "futures-macro"
397238version = "0.3.14"
@@ -429,7 +270,7 @@ dependencies = [
429270 "futures-sink",
430271 "futures-task",
431272 "memchr",
432− "pin-project-lite 0.2.6",
273+ "pin-project-lite",
433274 "pin-utils",
434275 "proc-macro-hack",
435276 "proc-macro-nested",
@@ -515,9 +356,9 @@ dependencies = [
515356 "serde",
516357 "serde_json",
517358 "shellexpand",
518− "smol",
519− "smol-timeout",
520359 "thiserror",
360+ "tokio",
361+ "tokio-stream",
521362 "url",
522363]
523364
@@ -553,8 +394,7 @@ dependencies = [
553394 "pulldown-cmark",
554395 "serde",
555396 "serde_json",
556− "smol",
557− "smol-timeout",
397+ "tokio",
558398 "toml",
559399 "tui",
560400]
@@ -571,7 +411,7 @@ dependencies = [
571411 "once_cell",
572412 "serde",
573413 "slotmap",
574− "smol",
414+ "tokio",
575415 "toml",
576416 "tui",
577417 "url",
@@ -801,12 +641,6 @@ version = "2.4.0"
801641source = "registry+https://github.com/rust-lang/crates.io-index"
802642checksum = "afb2e1c3ee07430c2cf76151675e583e0f19985fa6efae47d6848a3e2c824f85"
803643
804−[[package]]
805−name = "parking"
806−version = "2.0.0"
807−source = "registry+https://github.com/rust-lang/crates.io-index"
808−checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72"
809−
810644[[package]]
811645name = "parking_lot"
812646version = "0.11.1"
@@ -844,12 +678,6 @@ version = "2.1.0"
844678source = "registry+https://github.com/rust-lang/crates.io-index"
845679checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
846680
847−[[package]]
848−name = "pin-project-lite"
849−version = "0.1.12"
850−source = "registry+https://github.com/rust-lang/crates.io-index"
851−checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777"
852−
853681[[package]]
854682name = "pin-project-lite"
855683version = "0.2.6"
@@ -862,19 +690,6 @@ version = "0.1.0"
862690source = "registry+https://github.com/rust-lang/crates.io-index"
863691checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
864692
865−[[package]]
866−name = "polling"
867−version = "2.0.3"
868−source = "registry+https://github.com/rust-lang/crates.io-index"
869−checksum = "4fc12d774e799ee9ebae13f4076ca003b40d18a11ac0f3641e6f899618580b7b"
870−dependencies = [
871− "cfg-if",
872− "libc",
873− "log",
874− "wepoll-sys",
875− "winapi",
876−]
877−
878693[[package]]
879694name = "proc-macro-hack"
880695version = "0.5.19"
@@ -1044,16 +859,6 @@ dependencies = [
1044859 "signal-hook-registry",
1045860]
1046861
1047−[[package]]
1048−name = "signal-hook"
1049−version = "0.3.8"
1050−source = "registry+https://github.com/rust-lang/crates.io-index"
1051−checksum = "ef33d6d0cd06e0840fba9985aab098c147e67e05cee14d412d3345ed14ff30ac"
1052−dependencies = [
1053− "libc",
1054− "signal-hook-registry",
1055−]
1056−
1057862[[package]]
1058863name = "signal-hook-registry"
1059864version = "1.3.0"
@@ -1084,44 +889,6 @@ version = "1.6.1"
1084889source = "registry+https://github.com/rust-lang/crates.io-index"
1085890checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e"
1086891
1087−[[package]]
1088−name = "smol"
1089−version = "1.2.5"
1090−source = "registry+https://github.com/rust-lang/crates.io-index"
1091−checksum = "85cf3b5351f3e783c1d79ab5fc604eeed8b8ae9abd36b166e8b87a089efd85e4"
1092−dependencies = [
1093− "async-channel",
1094− "async-executor",
1095− "async-fs",
1096− "async-io",
1097− "async-lock",
1098− "async-net",
1099− "async-process",
1100− "blocking",
1101− "futures-lite",
1102− "once_cell",
1103−]
1104−
1105−[[package]]
1106−name = "smol-timeout"
1107−version = "0.6.0"
1108−source = "registry+https://github.com/rust-lang/crates.io-index"
1109−checksum = "847d777e2c6c166bad26264479e80a9820f3d364fcb4a0e23cd57bbfa8e94961"
1110−dependencies = [
1111− "async-io",
1112− "pin-project-lite 0.1.12",
1113−]
1114−
1115−[[package]]
1116−name = "socket2"
1117−version = "0.4.0"
1118−source = "registry+https://github.com/rust-lang/crates.io-index"
1119−checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2"
1120−dependencies = [
1121− "libc",
1122− "winapi",
1123−]
1124−
1125892[[package]]
1126893name = "syn"
1127894version = "1.0.71"
@@ -1206,6 +973,48 @@ version = "0.1.0"
1206973source = "registry+https://github.com/rust-lang/crates.io-index"
1207974checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
1208975
976+[[package]]
977+name = "tokio"
978+version = "1.5.0"
979+source = "registry+https://github.com/rust-lang/crates.io-index"
980+checksum = "83f0c8e7c0addab50b663055baf787d0af7f413a46e6e7fb9559a4e4db7137a5"
981+dependencies = [
982+ "autocfg",
983+ "bytes",
984+ "libc",
985+ "memchr",
986+ "mio",
987+ "num_cpus",
988+ "once_cell",
989+ "parking_lot",
990+ "pin-project-lite",
991+ "signal-hook-registry",
992+ "tokio-macros",
993+ "winapi",
994+]
995+
996+[[package]]
997+name = "tokio-macros"
998+version = "1.1.0"
999+source = "registry+https://github.com/rust-lang/crates.io-index"
1000+checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57"
1001+dependencies = [
1002+ "proc-macro2",
1003+ "quote",
1004+ "syn",
1005+]
1006+
1007+[[package]]
1008+name = "tokio-stream"
1009+version = "0.1.5"
1010+source = "registry+https://github.com/rust-lang/crates.io-index"
1011+checksum = "e177a5d8c3bf36de9ebe6d58537d8879e964332f93fb3339e43f618c81361af0"
1012+dependencies = [
1013+ "futures-core",
1014+ "pin-project-lite",
1015+ "tokio",
1016+]
1017+
12091018[[package]]
12101019name = "toml"
12111020version = "0.5.8"
@@ -1314,12 +1123,6 @@ version = "0.9.3"
13141123source = "registry+https://github.com/rust-lang/crates.io-index"
13151124checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
13161125
1317−[[package]]
1318−name = "waker-fn"
1319−version = "1.1.0"
1320−source = "registry+https://github.com/rust-lang/crates.io-index"
1321−checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca"
1322−
13231126[[package]]
13241127name = "walkdir"
13251128version = "2.3.2"
@@ -1337,15 +1140,6 @@ version = "0.10.2+wasi-snapshot-preview1"
13371140source = "registry+https://github.com/rust-lang/crates.io-index"
13381141checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
13391142
1340−[[package]]
1341−name = "wepoll-sys"
1342−version = "3.0.1"
1343−source = "registry+https://github.com/rust-lang/crates.io-index"
1344−checksum = "0fcb14dea929042224824779fbc82d9fab8d2e6d3cbc0ac404de8edf489e77ff"
1345−dependencies = [
1346− "cc",
1347−]
1348−
13491143[[package]]
13501144name = "winapi"
13511145version = "0.3.9"
helix-lsp/Cargo.toml+2−2
@@ -12,8 +12,8 @@ helix-core = { path = "../helix-core" }
1212once_cell = "1.4"
1313
1414lsp-types = { version = "0.89", features = ["proposed"] }
15−smol = "1.2"
16−smol-timeout = "0.6"
15+tokio = { version = "1", features = ["full"] }
16+tokio-stream = "0.1.5"
1717url = "2"
1818pathdiff = "0.2"
1919shellexpand = "2.0"
helix-lsp/src/client.rs+42−37
@@ -13,18 +13,18 @@ use jsonrpc_core as jsonrpc;
1313use lsp_types as lsp;
1414use serde_json::Value;
1515
16−use smol::{
17− channel::{Receiver, Sender},
16+use std::process::Stdio;
17+use tokio::{
1818 io::{BufReader, BufWriter},
1919 // prelude::*,
20− process::{Child, Command, Stdio},
21− Executor,
20+ process::{Child, Command},
21+ sync::mpsc::{channel, UnboundedReceiver, UnboundedSender},
2222};
2323
2424pub struct Client {
2525 _process: Child,
2626
27− outgoing: Sender<Payload>,
27+ outgoing: UnboundedSender<Payload>,
2828 // pub incoming: Receiver<Call>,
2929 pub request_counter: AtomicU64,
3030
@@ -33,13 +33,14 @@ pub struct Client {
3333}
3434
3535impl Client {
36− pub fn start(ex: &Executor, cmd: &str, args: &[String]) -> Result<(Self, Receiver<Call>)> {
37− // smol makes sure the process is reaped on drop, but using kill_on_drop(true) maybe?
36+ pub fn start(cmd: &str, args: &[String]) -> Result<(Self, UnboundedReceiver<Call>)> {
3837 let process = Command::new(cmd)
3938 .args(args)
4039 .stdin(Stdio::piped())
4140 .stdout(Stdio::piped())
4241 .stderr(Stdio::piped())
42+ // make sure the process is reaped on drop
43+ .kill_on_drop(true)
4344 .spawn();
4445
4546 // use std::io::ErrorKind;
@@ -58,7 +59,7 @@ impl Client {
5859 let reader = BufReader::new(process.stdout.take().expect("Failed to open stdout"));
5960 let stderr = BufReader::new(process.stderr.take().expect("Failed to open stderr"));
6061
61− let (incoming, outgoing) = Transport::start(ex, reader, writer, stderr);
62+ let (incoming, outgoing) = Transport::start(reader, writer, stderr);
6263
6364 let client = Client {
6465 _process: process,
@@ -134,49 +135,53 @@ impl Client {
134135 params: Self::value_into_params(params),
135136 };
136137
137− let (tx, rx) = smol::channel::bounded::<Result<Value>>(1);
138+ let (tx, mut rx) = channel::<Result<Value>>(1);
138139
139140 self.outgoing
140141 .send(Payload::Request {
141142 chan: tx,
142143 value: request,
143144 })
144− .await
145145 .map_err(|e| Error::Other(e.into()))?;
146146
147− use smol_timeout::TimeoutExt;
148147 use std::time::Duration;
148+ use tokio::time::timeout;
149149
150150 let future = async move {
151− rx.recv()
152− .timeout(Duration::from_secs(2))
151+ timeout(Duration::from_secs(2), rx.recv())
153152 .await
154− .ok_or(Error::Timeout)? // return Timeout
155− .map_err(|e| Error::Other(e.into()))?
153+ .map_err(|e| Error::Timeout)? // return Timeout
154+ .unwrap() // TODO: None if channel closed
156155 };
157156
158157 Ok(future)
159158 }
160159
161160 /// Send a RPC notification to the language server.
162− pub async fn notify<R: lsp::notification::Notification>(&self, params: R::Params) -> Result<()>
161+ pub fn notify<R: lsp::notification::Notification>(
162+ &self,
163+ params: R::Params,
164+ ) -> impl Future<Output = Result<()>>
163165 where
164166 R::Params: serde::Serialize,
165167 {
166− let params = serde_json::to_value(params)?;
168+ let outgoing = self.outgoing.clone();
167169
168− let notification = jsonrpc::Notification {
169− jsonrpc: Some(jsonrpc::Version::V2),
170− method: R::METHOD.to_string(),
171− params: Self::value_into_params(params),
172− };
170+ async move {
171+ let params = serde_json::to_value(params)?;
173172
174− self.outgoing
175− .send(Payload::Notification(notification))
176− .await
177− .map_err(|e| Error::Other(e.into()))?;
173+ let notification = jsonrpc::Notification {
174+ jsonrpc: Some(jsonrpc::Version::V2),
175+ method: R::METHOD.to_string(),
176+ params: Self::value_into_params(params),
177+ };
178178
179− Ok(())
179+ outgoing
180+ .send(Payload::Notification(notification))
181+ .map_err(|e| Error::Other(e.into()))?;
182+
183+ Ok(())
184+ }
180185 }
181186
182187 /// Reply to a language server RPC call.
@@ -202,7 +207,6 @@ impl Client {
202207
203208 self.outgoing
204209 .send(Payload::Response(output))
205− .await
206210 .map_err(|e| Error::Other(e.into()))?;
207211
208212 Ok(())
@@ -387,13 +391,13 @@ impl Client {
387391 changes
388392 }
389393
390− pub async fn text_document_did_change(
394+ pub fn text_document_did_change(
391395 &self,
392396 text_document: lsp::VersionedTextDocumentIdentifier,
393397 old_text: &Rope,
394398 new_text: &Rope,
395399 changes: &ChangeSet,
396− ) -> Result<()> {
400+ ) -> Option<impl Future<Output = Result<()>>> {
397401 // figure out what kind of sync the server supports
398402
399403 let capabilities = self.capabilities.as_ref().unwrap();
@@ -405,7 +409,7 @@ impl Client {
405409 ..
406410 })) => kind,
407411 // None | SyncOptions { changes: None }
408− _ => return Ok(()),
412+ _ => return None,
409413 };
410414
411415 let changes = match sync_capabilities {
@@ -420,14 +424,15 @@ impl Client {
420424 lsp::TextDocumentSyncKind::Incremental => {
421425 Self::changeset_to_changes(old_text, new_text, changes, self.offset_encoding)
422426 }
423− lsp::TextDocumentSyncKind::None => return Ok(()),
427+ lsp::TextDocumentSyncKind::None => return None,
424428 };
425429
426− self.notify::<lsp::notification::DidChangeTextDocument>(lsp::DidChangeTextDocumentParams {
427− text_document,
428− content_changes: changes,
429− })
430− .await
430+ Some(self.notify::<lsp::notification::DidChangeTextDocument>(
431+ lsp::DidChangeTextDocumentParams {
432+ text_document,
433+ content_changes: changes,
434+ },
435+ ))
431436 }
432437
433438 pub async fn text_document_did_close(
helix-lsp/src/lib.rs+8−10
@@ -18,6 +18,8 @@ use std::{collections::HashMap, sync::Arc};
1818
1919use serde::{Deserialize, Serialize};
2020
21+use tokio_stream::wrappers::UnboundedReceiverStream;
22+
2123#[derive(Error, Debug)]
2224pub enum Error {
2325 #[error("protocol error: {0}")]
@@ -163,12 +165,11 @@ pub use jsonrpc::Call;
163165type LanguageId = String;
164166
165167use crate::select_all::SelectAll;
166−use smol::channel::Receiver;
167168
168169pub struct Registry {
169170 inner: HashMap<LanguageId, Option<Arc<Client>>>,
170171
171− pub incoming: SelectAll<Receiver<Call>>,
172+ pub incoming: SelectAll<UnboundedReceiverStream<Call>>,
172173}
173174
174175impl Default for Registry {
@@ -185,11 +186,7 @@ impl Registry {
185186 }
186187 }
187188
188− pub fn get(
189− &mut self,
190− language_config: &LanguageConfiguration,
191− ex: &smol::Executor,
192− ) -> Option<Arc<Client>> {
189+ pub fn get(&mut self, language_config: &LanguageConfiguration) -> Option<Arc<Client>> {
193190 // TODO: propagate the error
194191 if let Some(config) = &language_config.language_server {
195192 // avoid borrow issues
@@ -203,12 +200,13 @@ impl Registry {
203200
204201 // initialize a new client
205202 let (mut client, incoming) =
206− Client::start(&ex, &config.command, &config.args).ok()?;
203+ Client::start(&config.command, &config.args).ok()?;
207204
208205 // TODO: run this async without blocking
209− smol::block_on(client.initialize()).unwrap();
206+ let rt = tokio::runtime::Handle::current();
207+ rt.block_on(client.initialize()).unwrap();
210208
211− s_incoming.push(incoming);
209+ s_incoming.push(UnboundedReceiverStream::new(incoming));
212210
213211 Some(Arc::new(client))
214212 })
helix-lsp/src/select_all.rs+1−1
@@ -6,10 +6,10 @@ use core::{
66 pin::Pin,
77};
88
9−use smol::{ready, stream::Stream};
109use std::task::{Context, Poll};
1110
1211use futures_util::stream::{FusedStream, FuturesUnordered, StreamExt, StreamFuture};
12+use futures_util::{ready, stream::Stream};
1313
1414/// An unbounded set of streams
1515///
helix-lsp/src/transport.rs+15−19
@@ -10,15 +10,13 @@ type Result<T> = core::result::Result<T, Error>;
1010use jsonrpc_core as jsonrpc;
1111use serde_json::Value;
1212
13−use smol::prelude::*;
14−
15−use smol::{
16− channel::{Receiver, Sender},
17− io::{BufReader, BufWriter},
13+use tokio::{
14+ io::{AsyncBufRead, AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader, BufWriter},
1815 process::{ChildStderr, ChildStdin, ChildStdout},
19− Executor,
16+ sync::mpsc::{unbounded_channel, Sender, UnboundedReceiver, UnboundedSender},
2017};
2118
19+#[derive(Debug)]
2220pub enum Payload {
2321 Request {
2422 chan: Sender<Result<Value>>,
@@ -41,8 +39,8 @@ enum Message {
4139}
4240
4341pub struct Transport {
44− incoming: Sender<jsonrpc::Call>,
45− outgoing: Receiver<Payload>,
42+ incoming: UnboundedSender<jsonrpc::Call>,
43+ outgoing: UnboundedReceiver<Payload>,
4644
4745 pending_requests: HashMap<jsonrpc::Id, Sender<Result<Value>>>,
4846 headers: HashMap<String, String>,
@@ -54,13 +52,12 @@ pub struct Transport {
5452
5553impl Transport {
5654 pub fn start(
57− ex: &Executor,
5855 reader: BufReader<ChildStdout>,
5956 writer: BufWriter<ChildStdin>,
6057 stderr: BufReader<ChildStderr>,
61− ) -> (Receiver<jsonrpc::Call>, Sender<Payload>) {
62− let (incoming, rx) = smol::channel::unbounded();
63− let (tx, outgoing) = smol::channel::unbounded();
58+ ) -> (UnboundedReceiver<jsonrpc::Call>, UnboundedSender<Payload>) {
59+ let (incoming, rx) = unbounded_channel();
60+ let (tx, outgoing) = unbounded_channel();
6461
6562 let transport = Self {
6663 reader,
@@ -72,7 +69,7 @@ impl Transport {
7269 headers: HashMap::default(),
7370 };
7471
75− ex.spawn(transport.duplex()).detach();
72+ tokio::spawn(transport.duplex());
7673
7774 (rx, tx)
7875 }
@@ -168,7 +165,7 @@ impl Transport {
168165 match msg {
169166 Message::Output(output) => self.recv_response(output).await?,
170167 Message::Call(call) => {
171− self.incoming.send(call).await?;
168+ self.incoming.send(call).unwrap();
172169 // let notification = Notification::parse(&method, params);
173170 }
174171 };
@@ -204,11 +201,10 @@ impl Transport {
204201 }
205202
206203 pub async fn duplex(mut self) {
207− use futures_util::{select, FutureExt};
208204 loop {
209− select! {
205+ tokio::select! {
210206 // client -> server
211− msg = self.outgoing.next().fuse() => {
207+ msg = self.outgoing.recv() => {
212208 if msg.is_none() {
213209 break;
214210 }
@@ -217,7 +213,7 @@ impl Transport {
217213 self.send_payload(msg).await.unwrap();
218214 }
219215 // server <- client
220− msg = Self::recv(&mut self.reader, &mut self.headers).fuse() => {
216+ msg = Self::recv(&mut self.reader, &mut self.headers) => {
221217 if msg.is_err() {
222218 error!("err: <- {:?}", msg);
223219 break;
@@ -226,7 +222,7 @@ impl Transport {
226222
227223 self.recv_msg(msg).await.unwrap();
228224 }
229− _msg = Self::err(&mut self.stderr).fuse() => {}
225+ _msg = Self::err(&mut self.stderr) => {}
230226 }
231227 }
232228 }
helix-term/Cargo.toml+1−2
@@ -19,8 +19,7 @@ helix-lsp = { path = "../helix-lsp"}
1919anyhow = "1"
2020once_cell = "1.4"
2121
22−smol = "1"
23−smol-timeout = "0.6"
22+tokio = { version = "1", features = ["full"] }
2423num_cpus = "1"
2524tui = { version = "0.15", default-features = false, features = ["crossterm"] }
2625crossterm = { version = "0.19", features = ["event-stream"] }
helix-term/src/application.rs+4−10
@@ -7,14 +7,13 @@ use crate::{compositor::Compositor, ui};
77use log::{error, info};
88
99use std::{
10+ future::Future,
1011 io::{self, stdout, Stdout, Write},
1112 path::PathBuf,
1213 sync::Arc,
1314 time::Duration,
1415};
1516
16−use smol::prelude::*;
17−
1817use anyhow::Error;
1918
2019use crossterm::{
@@ -39,16 +38,15 @@ pub struct Application {
3938 compositor: Compositor,
4039 editor: Editor,
4140
42− executor: &'static smol::Executor<'static>,
4341 callbacks: LspCallbacks,
4442}
4543
4644impl Application {
47− pub fn new(mut args: Args, executor: &'static smol::Executor<'static>) -> Result<Self, Error> {
45+ pub fn new(mut args: Args) -> Result<Self, Error> {
4846 use helix_view::editor::Action;
4947 let mut compositor = Compositor::new()?;
5048 let size = compositor.size();
51− let mut editor = Editor::new(executor, size);
49+ let mut editor = Editor::new(size);
5250
5351 if let Ok(files) = args.values_of_t::<PathBuf>("files") {
5452 for file in files {
@@ -64,7 +62,6 @@ impl Application {
6462 compositor,
6563 editor,
6664
67− executor,
6865 callbacks: FuturesUnordered::new(),
6966 };
7067
@@ -72,14 +69,12 @@ impl Application {
7269 }
7370
7471 fn render(&mut self) {
75− let executor = &self.executor;
7672 let editor = &mut self.editor;
7773 let compositor = &mut self.compositor;
7874 let callbacks = &mut self.callbacks;
7975
8076 let mut cx = crate::compositor::Context {
8177 editor,
82− executor,
8378 callbacks,
8479 scroll: None,
8580 };
@@ -97,7 +92,7 @@ impl Application {
9792 break;
9893 }
9994
100− use futures_util::{select, FutureExt};
95+ use futures_util::{select, FutureExt, StreamExt};
10196 select! {
10297 event = reader.next().fuse() => {
10398 self.handle_terminal_events(event)
@@ -125,7 +120,6 @@ impl Application {
125120 pub fn handle_terminal_events(&mut self, event: Option<Result<Event, crossterm::ErrorKind>>) {
126121 let mut cx = crate::compositor::Context {
127122 editor: &mut self.editor,
128− executor: self.executor,
129123 callbacks: &mut self.callbacks,
130124 scroll: None,
131125 };
helix-term/src/commands.rs+25−17
@@ -108,6 +108,16 @@ impl<'a> Context<'a> {
108108/// state (usually by creating and applying a transaction).
109109pub type Command = fn(cx: &mut Context);
110110
111+#[inline]
112+fn block_on<T>(future: impl Future<Output = T>) -> T {
113+ use tokio::runtime::Runtime;
114+ // let rt = Runtime::new().unwrap();
115+ let rt = tokio::runtime::Handle::current();
116+ // let local = LocalSet::new();
117+ // local.block_on(&rt, future)
118+ rt.block_on(future)
119+}
120+
111121pub fn move_char_left(cx: &mut Context) {
112122 let count = cx.count;
113123 let (view, doc) = cx.current();
@@ -861,7 +871,6 @@ pub fn command_mode(cx: &mut Context) {
861871 match *parts.as_slice() {
862872 ["q"] | ["quit"] => {
863873 editor.close(editor.view().id);
864− // editor.should_close = true,
865874 }
866875 ["o", path] | ["open", path] => {
867876 use helix_view::editor::Action;
@@ -871,7 +880,7 @@ pub fn command_mode(cx: &mut Context) {
871880 // TODO: non-blocking via save() command
872881 let id = editor.view().doc;
873882 let doc = &mut editor.documents[id];
874− smol::block_on(doc.save());
883+ block_on(doc.save());
875884 }
876885
877886 _ => (),
@@ -1175,8 +1184,7 @@ pub fn goto_definition(cx: &mut Context) {
11751184 let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
11761185
11771186 // TODO: handle fails
1178− let res =
1179− smol::block_on(language_server.goto_definition(doc.identifier(), pos)).unwrap_or_default();
1187+ let res = block_on(language_server.goto_definition(doc.identifier(), pos)).unwrap_or_default();
11801188 _goto(cx, res, offset_encoding);
11811189}
11821190
@@ -1192,8 +1200,8 @@ pub fn goto_type_definition(cx: &mut Context) {
11921200 let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
11931201
11941202 // TODO: handle fails
1195− let res = smol::block_on(language_server.goto_type_definition(doc.identifier(), pos))
1196− .unwrap_or_default();
1203+ let res =
1204+ block_on(language_server.goto_type_definition(doc.identifier(), pos)).unwrap_or_default();
11971205 _goto(cx, res, offset_encoding);
11981206}
11991207
@@ -1209,8 +1217,8 @@ pub fn goto_implementation(cx: &mut Context) {
12091217 let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
12101218
12111219 // TODO: handle fails
1212− let res = smol::block_on(language_server.goto_implementation(doc.identifier(), pos))
1213− .unwrap_or_default();
1220+ let res =
1221+ block_on(language_server.goto_implementation(doc.identifier(), pos)).unwrap_or_default();
12141222 _goto(cx, res, offset_encoding);
12151223}
12161224
@@ -1226,8 +1234,7 @@ pub fn goto_reference(cx: &mut Context) {
12261234 let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
12271235
12281236 // TODO: handle fails
1229− let res =
1230− smol::block_on(language_server.goto_reference(doc.identifier(), pos)).unwrap_or_default();
1237+ let res = block_on(language_server.goto_reference(doc.identifier(), pos)).unwrap_or_default();
12311238 _goto(cx, res, offset_encoding);
12321239}
12331240
@@ -1247,7 +1254,7 @@ pub fn signature_help(cx: &mut Context) {
12471254
12481255 // TODO: handle fails
12491256
1250− let res = smol::block_on(language_server.text_document_signature_help(doc.identifier(), pos))
1257+ let res = block_on(language_server.text_document_signature_help(doc.identifier(), pos))
12511258 .unwrap_or_default();
12521259
12531260 if let Some(signature_help) = res {
@@ -1636,7 +1643,7 @@ pub fn format_selections(cx: &mut Context) {
16361643 };
16371644 // TODO: handle fails
16381645 // TODO: concurrent map
1639− let edits = smol::block_on(language_server.text_document_range_formatting(
1646+ let edits = block_on(language_server.text_document_range_formatting(
16401647 doc.identifier(),
16411648 range,
16421649 lsp::FormattingOptions::default(),
@@ -1726,7 +1733,8 @@ pub fn save(cx: &mut Context) {
17261733 // Spawns an async task to actually do the saving. This way we prevent blocking.
17271734
17281735 // TODO: handle save errors somehow?
1729− cx.editor.executor.spawn(cx.doc().save()).detach();
1736+ // TODO: don't block
1737+ block_on(cx.doc().save());
17301738}
17311739
17321740pub fn completion(cx: &mut Context) {
@@ -1782,7 +1790,7 @@ pub fn completion(cx: &mut Context) {
17821790 );
17831791
17841792 // TODO: handle fails
1785− let res = smol::block_on(language_server.completion(doc.identifier(), pos)).unwrap();
1793+ let res = block_on(language_server.completion(doc.identifier(), pos)).unwrap();
17861794
17871795 let trigger_offset = doc.selection(view.id).cursor();
17881796
@@ -1839,8 +1847,8 @@ pub fn hover(cx: &mut Context) {
18391847 );
18401848
18411849 // TODO: handle fails
1842− let res = smol::block_on(language_server.text_document_hover(doc.identifier(), pos))
1843− .unwrap_or_default();
1850+ let res =
1851+ block_on(language_server.text_document_hover(doc.identifier(), pos)).unwrap_or_default();
18441852
18451853 if let Some(hover) = res {
18461854 // hover.contents / .range <- used for visualizing
@@ -1963,7 +1971,7 @@ pub fn space_mode(cx: &mut Context) {
19631971 'w' => {
19641972 // save current buffer
19651973 let doc = cx.doc();
1966− smol::block_on(doc.save());
1974+ block_on(doc.save());
19671975 }
19681976 'c' => {
19691977 // close current split
helix-term/src/compositor.rs−2
@@ -4,7 +4,6 @@
44
55use crossterm::event::Event;
66use helix_core::Position;
7−use smol::Executor;
87use tui::{buffer::Buffer as Surface, layout::Rect};
98
109pub type Callback = Box<dyn FnOnce(&mut Compositor, &mut Editor)>;
@@ -29,7 +28,6 @@ use crate::application::LspCallbacks;
2928
3029pub struct Context<'a> {
3130 pub editor: &'a mut Editor,
32− pub executor: &'static smol::Executor<'static>,
3331 pub scroll: Option<usize>,
3432 pub callbacks: &'a mut LspCallbacks,
3533}
helix-term/src/main.rs+6−8
@@ -14,8 +14,6 @@ use std::path::PathBuf;
1414
1515use anyhow::Error;
1616
17−static EX: smol::Executor = smol::Executor::new();
18−
1917fn setup_logging(verbosity: u64) -> Result<(), fern::InitError> {
2018 let mut base_config = fern::Dispatch::new();
2119
@@ -88,12 +86,12 @@ fn main() {
8886 Loader::new(config)
8987 });
9088
91− for _ in 0..num_cpus::get() {
92− std::thread::spawn(move || smol::block_on(EX.run(smol::future::pending::<()>())));
93− }
89+ let runtime = tokio::runtime::Runtime::new().unwrap();
9490
95− let mut app = Application::new(args, &EX).unwrap();
91+ // TODO: use the thread local executor to spawn the application task separately from the work pool
92+ runtime.block_on(async move {
93+ let mut app = Application::new(args).unwrap();
9694
97− // we use the thread local executor to spawn the application task separately from the work pool
98− smol::block_on(app.run());
95+ app.run().await;
96+ });
9997}
helix-term/src/ui/editor.rs+1−2
@@ -207,7 +207,7 @@ impl EditorView {
207207 });
208208
209209 let style = if is_diagnostic {
210− style.clone().add_modifier(Modifier::UNDERLINED)
210+ style.add_modifier(Modifier::UNDERLINED)
211211 } else {
212212 style
213213 };
@@ -569,7 +569,6 @@ impl Component for EditorView {
569569 let mut cx = Context {
570570 editor: cxt.editor,
571571 callbacks: cxt.callbacks,
572− executor: cx.executor,
573572 scroll: None,
574573 };
575574 let res = completion.handle_event(event, &mut cx);
helix-view/Cargo.toml+1−1
@@ -21,7 +21,7 @@ crossterm = { version = "0.19", features = ["event-stream"], optional = true }
2121once_cell = "1.4"
2222url = "2"
2323
24−smol = "1"
24+tokio = { version = "1", features = ["full"] }
2525futures-util = "0.3"
2626
2727slotmap = "1"
helix-view/src/document.rs+4−2
@@ -134,7 +134,7 @@ impl Document {
134134 self.last_saved_revision = self.history.current_revision();
135135
136136 async move {
137− use smol::{fs::File, prelude::*};
137+ use tokio::{fs::File, io::AsyncWriteExt};
138138 let mut file = File::create(path).await?;
139139
140140 // write all the rope chunks to file
@@ -232,7 +232,9 @@ impl Document {
232232 transaction.changes(),
233233 );
234234
235− smol::block_on(notify).expect("failed to emit textDocument/didChange");
235+ if let Some(notify) = notify {
236+ tokio::spawn(notify);
237+ } //.expect("failed to emit textDocument/didChange");
236238 }
237239 }
238240 success
helix-view/src/editor.rs+8−8
@@ -13,7 +13,6 @@ pub struct Editor {
1313 pub count: Option<usize>,
1414 pub theme: Theme,
1515 pub language_servers: helix_lsp::Registry,
16− pub executor: &'static smol::Executor<'static>,
1716}
1817
1918#[derive(Copy, Clone)]
@@ -24,7 +23,7 @@ pub enum Action {
2423}
2524
2625impl Editor {
27− pub fn new(executor: &'static smol::Executor<'static>, mut area: tui::layout::Rect) -> Self {
26+ pub fn new(mut area: tui::layout::Rect) -> Self {
2827 use helix_core::config_dir;
2928 let config = std::fs::read(config_dir().join("theme.toml"));
3029 // load $HOME/.config/helix/theme.toml, fallback to default config
@@ -44,7 +43,6 @@ impl Editor {
4443 count: None,
4544 theme,
4645 language_servers,
47− executor,
4846 }
4947 }
5048
@@ -122,7 +120,7 @@ impl Editor {
122120 let language_server = doc
123121 .language
124122 .as_ref()
125− .and_then(|language| self.language_servers.get(language, self.executor));
123+ .and_then(|language| self.language_servers.get(language));
126124
127125 if let Some(language_server) = language_server {
128126 doc.set_language_server(Some(language_server.clone()));
@@ -133,7 +131,8 @@ impl Editor {
133131 .map(ToOwned::to_owned)
134132 .unwrap_or_default();
135133
136− smol::block_on(language_server.text_document_did_open(
134+ let rt = tokio::runtime::Handle::current();
135+ rt.block_on(language_server.text_document_did_open(
137136 doc.url().unwrap(),
138137 doc.version(),
139138 doc.text(),
@@ -154,17 +153,18 @@ impl Editor {
154153 let view = self.tree.get(self.tree.focus);
155154 // get around borrowck issues
156155 let language_servers = &mut self.language_servers;
157− let executor = self.executor;
158156
159157 let doc = &self.documents[view.doc];
160158
161159 let language_server = doc
162160 .language
163161 .as_ref()
164− .and_then(|language| language_servers.get(language, executor));
162+ .and_then(|language| language_servers.get(language));
165163
166164 if let Some(language_server) = language_server {
167− smol::block_on(language_server.text_document_did_close(doc.identifier())).unwrap();
165+ let rt = tokio::runtime::Handle::current();
166+ rt.block_on(language_server.text_document_did_close(doc.identifier()))
167+ .unwrap();
168168 }
169169
170170 // remove selection