on master help sign in
lsp: Make base request methods take &self instead of &mut self.
commitae8a9e5bac2cb4683015604bb5a431781717c991 authorBlaž Hrastnik <blaz@mxxn.io> dateThu 29 Oct 2020, 14:06 (6 years ago) parentcc6bdf8
5 files changed+72−67
Cargo.lock+45−39 helix-lsp/Cargo.toml+1−1 helix-lsp/src/client.rs+11−17 helix-term/src/application.rs+13−10 helix-view/src/commands.rs+2
Cargo.lock+45−39
@@ -29,9 +29,9 @@ checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544"
2929
3030[[package]]
3131name = "arrayvec"
32−version = "0.5.1"
32+version = "0.5.2"
3333source = "registry+https://github.com/rust-lang/crates.io-index"
34−checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
34+checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
3535
3636[[package]]
3737name = "async-channel"
@@ -118,7 +118,7 @@ checksum = "4c8cea09c1fb10a317d1b5af8024eeba256d6554763e85ecd90ff8df31c7bbda"
118118dependencies = [
119119 "async-io",
120120 "blocking",
121− "cfg-if",
121+ "cfg-if 0.1.10",
122122 "event-listener",
123123 "futures-lite",
124124 "once_cell",
@@ -208,6 +208,12 @@ version = "0.1.10"
208208source = "registry+https://github.com/rust-lang/crates.io-index"
209209checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
210210
211+[[package]]
212+name = "cfg-if"
213+version = "1.0.0"
214+source = "registry+https://github.com/rust-lang/crates.io-index"
215+checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
216+
211217[[package]]
212218name = "chrono"
213219version = "0.4.19"
@@ -267,15 +273,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
267273checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
268274dependencies = [
269275 "autocfg",
270− "cfg-if",
276+ "cfg-if 0.1.10",
271277 "lazy_static",
272278]
273279
274280[[package]]
275281name = "crossterm"
276−version = "0.18.0"
282+version = "0.18.1"
277283source = "registry+https://github.com/rust-lang/crates.io-index"
278−checksum = "c2fcdc3c9cf8ee446222e8ee8691a6d21b563b8fe1a64b1873080db7b5b23cf0"
284+checksum = "cef9149b29071d44c9fb98fd9c27fcf74405bbdb761889ad6a03f36be93b0b15"
279285dependencies = [
280286 "bitflags",
281287 "crossterm_winapi",
@@ -290,9 +296,9 @@ dependencies = [
290296
291297[[package]]
292298name = "crossterm_winapi"
293−version = "0.6.1"
299+version = "0.6.2"
294300source = "registry+https://github.com/rust-lang/crates.io-index"
295−checksum = "057b7146d02fb50175fd7dbe5158f6097f33d02831f43b4ee8ae4ddf67b68f5c"
301+checksum = "c2265c3f8e080075d9b6417aa72293fc71662f34b4af2612d8d1b074d29510db"
296302dependencies = [
297303 "winapi",
298304]
@@ -303,7 +309,7 @@ version = "2.0.2"
303309source = "registry+https://github.com/rust-lang/crates.io-index"
304310checksum = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3"
305311dependencies = [
306− "cfg-if",
312+ "cfg-if 0.1.10",
307313 "dirs-sys",
308314]
309315
@@ -360,15 +366,15 @@ checksum = "4c7e4c2612746b0df8fed4ce0c69156021b704c9aefa360311c04e6e9e002eed"
360366
361367[[package]]
362368name = "futures-core"
363−version = "0.3.6"
369+version = "0.3.7"
364370source = "registry+https://github.com/rust-lang/crates.io-index"
365−checksum = "d674eaa0056896d5ada519900dbf97ead2e46a7b6621e8160d79e2f2e1e2784b"
371+checksum = "18eaa56102984bed2c88ea39026cff3ce3b4c7f508ca970cedf2450ea10d4e46"
366372
367373[[package]]
368374name = "futures-io"
369−version = "0.3.6"
375+version = "0.3.7"
370376source = "registry+https://github.com/rust-lang/crates.io-index"
371−checksum = "5fc94b64bb39543b4e432f1790b6bf18e3ee3b74653c5449f63310e9a74b123c"
377+checksum = "6e1798854a4727ff944a7b12aa999f58ce7aa81db80d2dfaaf2ba06f065ddd2b"
372378
373379[[package]]
374380name = "futures-lite"
@@ -387,9 +393,9 @@ dependencies = [
387393
388394[[package]]
389395name = "futures-macro"
390−version = "0.3.6"
396+version = "0.3.7"
391397source = "registry+https://github.com/rust-lang/crates.io-index"
392−checksum = "f57ed14da4603b2554682e9f2ff3c65d7567b53188db96cb71538217fc64581b"
398+checksum = "e36fccf3fc58563b4a14d265027c627c3b665d7fed489427e88e7cc929559efe"
393399dependencies = [
394400 "proc-macro-hack",
395401 "proc-macro2",
@@ -399,18 +405,18 @@ dependencies = [
399405
400406[[package]]
401407name = "futures-task"
402−version = "0.3.6"
408+version = "0.3.7"
403409source = "registry+https://github.com/rust-lang/crates.io-index"
404−checksum = "4dd26820a9f3637f1302da8bceba3ff33adbe53464b54ca24d4e2d4f1db30f94"
410+checksum = "96d502af37186c4fef99453df03e374683f8a1eec9dcc1e66b3b82dc8278ce3c"
405411dependencies = [
406412 "once_cell",
407413]
408414
409415[[package]]
410416name = "futures-util"
411−version = "0.3.6"
417+version = "0.3.7"
412418source = "registry+https://github.com/rust-lang/crates.io-index"
413−checksum = "8a894a0acddba51a2d49a6f4263b1e64b8c579ece8af50fa86503d52cd1eea34"
419+checksum = "abcb44342f62e6f3e8ac427b8aa815f724fd705dfad060b18ac7866c15bb8e34"
414420dependencies = [
415421 "futures-core",
416422 "futures-macro",
@@ -428,7 +434,7 @@ version = "0.1.15"
428434source = "registry+https://github.com/rust-lang/crates.io-index"
429435checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6"
430436dependencies = [
431− "cfg-if",
437+ "cfg-if 0.1.10",
432438 "libc",
433439 "wasi 0.9.0+wasi-snapshot-preview1",
434440]
@@ -553,11 +559,11 @@ dependencies = [
553559
554560[[package]]
555561name = "instant"
556−version = "0.1.7"
562+version = "0.1.8"
557563source = "registry+https://github.com/rust-lang/crates.io-index"
558−checksum = "63312a18f7ea8760cdd0a7c5aac1a619752a246b833545e3e36d1f81f7cd9e66"
564+checksum = "cb1fc4429a33e1f80d41dc9fea4d108a88bec1de8053878898ae448a0b52f613"
559565dependencies = [
560− "cfg-if",
566+ "cfg-if 1.0.0",
561567]
562568
563569[[package]]
@@ -596,9 +602,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
596602
597603[[package]]
598604name = "libc"
599−version = "0.2.79"
605+version = "0.2.80"
600606source = "registry+https://github.com/rust-lang/crates.io-index"
601−checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743"
607+checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614"
602608
603609[[package]]
604610name = "lock_api"
@@ -615,14 +621,14 @@ version = "0.4.11"
615621source = "registry+https://github.com/rust-lang/crates.io-index"
616622checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
617623dependencies = [
618− "cfg-if",
624+ "cfg-if 0.1.10",
619625]
620626
621627[[package]]
622628name = "lsp-types"
623−version = "0.82.0"
629+version = "0.83.0"
624630source = "registry+https://github.com/rust-lang/crates.io-index"
625−checksum = "db895abb8527cf59e3de893ab2acf52cf904faeb65e60ea6f373e11fe86464e8"
631+checksum = "25e0bd4b95038f2c23bda332ba0ca684e8dda765db1f9bdb63dc4c3e01f3b456"
626632dependencies = [
627633 "base64",
628634 "bitflags",
@@ -691,9 +697,9 @@ checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
691697
692698[[package]]
693699name = "ntapi"
694−version = "0.3.4"
700+version = "0.3.6"
695701source = "registry+https://github.com/rust-lang/crates.io-index"
696−checksum = "7a31937dea023539c72ddae0e3571deadc1414b300483fa7aaec176168cfa9d2"
702+checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44"
697703dependencies = [
698704 "winapi",
699705]
@@ -762,7 +768,7 @@ version = "0.8.0"
762768source = "registry+https://github.com/rust-lang/crates.io-index"
763769checksum = "c361aa727dd08437f2f1447be8b59a33b0edd15e0fcee698f935613d9efbca9b"
764770dependencies = [
765− "cfg-if",
771+ "cfg-if 0.1.10",
766772 "cloudabi",
767773 "instant",
768774 "libc",
@@ -785,18 +791,18 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
785791
786792[[package]]
787793name = "pin-project"
788−version = "0.4.27"
794+version = "1.0.1"
789795source = "registry+https://github.com/rust-lang/crates.io-index"
790−checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15"
796+checksum = "ee41d838744f60d959d7074e3afb6b35c7456d0f61cad38a24e35e6553f73841"
791797dependencies = [
792798 "pin-project-internal",
793799]
794800
795801[[package]]
796802name = "pin-project-internal"
797−version = "0.4.27"
803+version = "1.0.1"
798804source = "registry+https://github.com/rust-lang/crates.io-index"
799−checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895"
805+checksum = "81a4ffa594b66bff340084d4081df649a7dc049ac8d7fc458d8e628bfbbb2f86"
800806dependencies = [
801807 "proc-macro2",
802808 "quote",
@@ -821,7 +827,7 @@ version = "2.0.2"
821827source = "registry+https://github.com/rust-lang/crates.io-index"
822828checksum = "a2a7bc6b2a29e632e45451c941832803a18cce6781db04de8a04696cdca8bde4"
823829dependencies = [
824− "cfg-if",
830+ "cfg-if 0.1.10",
825831 "libc",
826832 "log",
827833 "wepoll-sys",
@@ -1034,7 +1040,7 @@ version = "0.3.15"
10341040source = "registry+https://github.com/rust-lang/crates.io-index"
10351041checksum = "b1fa70dc5c8104ec096f4fe7ede7a221d35ae13dcd19ba1ad9a81d2cab9a1c44"
10361042dependencies = [
1037− "cfg-if",
1043+ "cfg-if 0.1.10",
10381044 "libc",
10391045 "redox_syscall",
10401046 "winapi",
@@ -1042,9 +1048,9 @@ dependencies = [
10421048
10431049[[package]]
10441050name = "syn"
1045−version = "1.0.46"
1051+version = "1.0.48"
10461052source = "registry+https://github.com/rust-lang/crates.io-index"
1047−checksum = "5ad5de3220ea04da322618ded2c42233d02baca219d6f160a3e9c87cda16c942"
1053+checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac"
10481054dependencies = [
10491055 "proc-macro2",
10501056 "quote",
helix-lsp/Cargo.toml+1−1
@@ -10,7 +10,7 @@ edition = "2018"
1010helix-core = { path = "../helix-core" }
1111helix-view = { path = "../helix-view" }
1212
13−lsp-types = { version = "0.82", features = ["proposed"] }
13+lsp-types = { version = "0.83", features = ["proposed"] }
1414smol = "1.2"
1515url = "2"
1616pathdiff = "0.2"
helix-lsp/src/client.rs+11−17
@@ -9,6 +9,7 @@ use helix_core::{ChangeSet, Transaction};
99use helix_view::Document;
1010
1111// use std::collections::HashMap;
12+use std::sync::atomic::{AtomicU64, Ordering};
1213
1314use jsonrpc_core as jsonrpc;
1415use lsp_types as lsp;
@@ -29,7 +30,7 @@ pub struct Client {
2930 outgoing: Sender<Payload>,
3031 pub incoming: Receiver<Call>,
3132
32− pub request_counter: u64,
33+ pub request_counter: AtomicU64,
3334
3435 capabilities: Option<lsp::ServerCapabilities>,
3536 // TODO: handle PublishDiagnostics Version
@@ -61,17 +62,16 @@ impl Client {
6162 outgoing,
6263 incoming,
6364
64− request_counter: 0,
65+ request_counter: AtomicU64::new(0),
6566
6667 capabilities: None,
6768 // diagnostics: HashMap::new(),
6869 }
6970 }
7071
71− fn next_request_id(&mut self) -> jsonrpc::Id {
72− let id = jsonrpc::Id::Num(self.request_counter);
73− self.request_counter += 1;
74− id
72+ fn next_request_id(&self) -> jsonrpc::Id {
73+ let id = self.request_counter.fetch_add(1, Ordering::Relaxed);
74+ jsonrpc::Id::Num(id)
7575 }
7676
7777 fn to_params(value: Value) -> Result<jsonrpc::Params> {
@@ -88,10 +88,7 @@ impl Client {
8888 }
8989
9090 /// Execute a RPC request on the language server.
91− pub async fn request<R: lsp::request::Request>(
92− &mut self,
93− params: R::Params,
94− ) -> Result<R::Result>
91+ pub async fn request<R: lsp::request::Request>(&self, params: R::Params) -> Result<R::Result>
9592 where
9693 R::Params: serde::Serialize,
9794 R::Result: core::fmt::Debug, // TODO: temporary
@@ -128,10 +125,7 @@ impl Client {
128125 }
129126
130127 /// Send a RPC notification to the language server.
131− pub async fn notify<R: lsp::notification::Notification>(
132− &mut self,
133− params: R::Params,
134− ) -> Result<()>
128+ pub async fn notify<R: lsp::notification::Notification>(&self, params: R::Params) -> Result<()>
135129 where
136130 R::Params: serde::Serialize,
137131 {
@@ -153,7 +147,7 @@ impl Client {
153147
154148 /// Reply to a language server RPC call.
155149 pub async fn reply(
156− &mut self,
150+ &self,
157151 id: jsonrpc::Id,
158152 result: core::result::Result<Value, jsonrpc::Error>,
159153 ) -> Result<()> {
@@ -212,11 +206,11 @@ impl Client {
212206 Ok(())
213207 }
214208
215− pub async fn shutdown(&mut self) -> Result<()> {
209+ pub async fn shutdown(&self) -> Result<()> {
216210 self.request::<lsp::request::Shutdown>(()).await
217211 }
218212
219− pub async fn exit(&mut self) -> Result<()> {
213+ pub async fn exit(&self) -> Result<()> {
220214 self.notify::<lsp::notification::Exit>(()).await
221215 }
222216
helix-term/src/application.rs+13−10
@@ -8,6 +8,8 @@ use helix_view::{
88 Document, Editor, Theme, View,
99};
1010
11+use log::{debug, info};
12+
1113use std::{
1214 borrow::Cow,
1315 io::{self, stdout, Stdout, Write},
@@ -46,7 +48,7 @@ pub struct Application<'a> {
4648
4749 keymap: Keymaps,
4850 executor: &'a smol::Executor<'a>,
49− lsp: helix_lsp::Client,
51+ language_server: helix_lsp::Client,
5052}
5153
5254struct Renderer {
@@ -370,7 +372,7 @@ impl<'a> Application<'a> {
370372 editor.open(file, terminal.size)?;
371373 }
372374
373− let lsp = helix_lsp::Client::start(&executor, "rust-analyzer", &[]);
375+ let language_server = helix_lsp::Client::start(&executor, "rust-analyzer", &[]);
374376
375377 let mut app = Self {
376378 editor,
@@ -381,7 +383,7 @@ impl<'a> Application<'a> {
381383 //
382384 keymap: keymap::default(),
383385 executor,
384− lsp,
386+ language_server,
385387 };
386388
387389 Ok(app)
@@ -415,11 +417,11 @@ impl<'a> Application<'a> {
415417 let mut reader = EventStream::new();
416418
417419 // initialize lsp
418− let res = self.lsp.initialize().await;
419− let res = self
420− .lsp
420+ self.language_server.initialize().await.unwrap();
421+ self.language_server
421422 .text_document_did_open(&self.editor.view().unwrap().doc)
422− .await;
423+ .await
424+ .unwrap();
423425
424426 self.render();
425427
@@ -433,8 +435,8 @@ impl<'a> Application<'a> {
433435 event = reader.next().fuse() => {
434436 self.handle_terminal_events(event).await
435437 }
436− call = self.lsp.incoming.next().fuse() => {
437− self.handle_lsp_message(call).await
438+ call = self.language_server.incoming.next().fuse() => {
439+ self.handle_language_server_message(call).await
438440 }
439441 }
440442 }
@@ -566,7 +568,7 @@ impl<'a> Application<'a> {
566568 };
567569 }
568570
569− pub async fn handle_lsp_message(&mut self, call: Option<helix_lsp::Call>) {
571+ pub async fn handle_language_server_message(&mut self, call: Option<helix_lsp::Call>) {
570572 use helix_lsp::{Call, Notification};
571573 match call {
572574 Some(Call::Notification(helix_lsp::jsonrpc::Notification {
@@ -605,6 +607,7 @@ impl<'a> Application<'a> {
605607
606608 view.doc.diagnostics = diagnostics;
607609
610+ // TODO: we want to process all the events in queue, then render. publishDiagnostic tends to send a whole bunch of events
608611 self.render();
609612 }
610613 }
helix-view/src/commands.rs+2
@@ -404,6 +404,8 @@ fn append_changes_to_history(view: &mut View) {
404404 let old_state = std::mem::replace(&mut view.doc.old_state, view.doc.state.clone());
405405 // TODO: take transaction by value?
406406 view.doc.history.commit_revision(&transaction, &old_state);
407+
408+ // TODO: notify LSP of changes
407409}
408410
409411pub fn normal_mode(view: &mut View, _count: usize) {