From ae8a9e5bac2cb4683015604bb5a431781717c991 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Thu, 29 Oct 2020 14:06:33 +0900 Subject: lsp: Make base request methods take &self instead of &mut self. --- helix-lsp/src/client.rs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'helix-lsp/src') diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 3c2c1ce0..1583bfb8 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -9,6 +9,7 @@ use helix_core::{ChangeSet, Transaction}; use helix_view::Document; // use std::collections::HashMap; +use std::sync::atomic::{AtomicU64, Ordering}; use jsonrpc_core as jsonrpc; use lsp_types as lsp; @@ -29,7 +30,7 @@ pub struct Client { outgoing: Sender, pub incoming: Receiver, - pub request_counter: u64, + pub request_counter: AtomicU64, capabilities: Option, // TODO: handle PublishDiagnostics Version @@ -61,17 +62,16 @@ impl Client { outgoing, incoming, - request_counter: 0, + request_counter: AtomicU64::new(0), capabilities: None, // diagnostics: HashMap::new(), } } - fn next_request_id(&mut self) -> jsonrpc::Id { - let id = jsonrpc::Id::Num(self.request_counter); - self.request_counter += 1; - id + fn next_request_id(&self) -> jsonrpc::Id { + let id = self.request_counter.fetch_add(1, Ordering::Relaxed); + jsonrpc::Id::Num(id) } fn to_params(value: Value) -> Result { @@ -88,10 +88,7 @@ impl Client { } /// Execute a RPC request on the language server. - pub async fn request( - &mut self, - params: R::Params, - ) -> Result + pub async fn request(&self, params: R::Params) -> Result where R::Params: serde::Serialize, R::Result: core::fmt::Debug, // TODO: temporary @@ -128,10 +125,7 @@ impl Client { } /// Send a RPC notification to the language server. - pub async fn notify( - &mut self, - params: R::Params, - ) -> Result<()> + pub async fn notify(&self, params: R::Params) -> Result<()> where R::Params: serde::Serialize, { @@ -153,7 +147,7 @@ impl Client { /// Reply to a language server RPC call. pub async fn reply( - &mut self, + &self, id: jsonrpc::Id, result: core::result::Result, ) -> Result<()> { @@ -212,11 +206,11 @@ impl Client { Ok(()) } - pub async fn shutdown(&mut self) -> Result<()> { + pub async fn shutdown(&self) -> Result<()> { self.request::(()).await } - pub async fn exit(&mut self) -> Result<()> { + pub async fn exit(&self) -> Result<()> { self.notify::(()).await } -- cgit v1.2.3-70-g09d2