From 745892fbddea56040139108277e728b53fd8fc11 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Thu, 28 May 2020 03:03:21 +0000 Subject: CTAN sync 202005280303 --- support/texlab/src/test/server.rs | 87 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 support/texlab/src/test/server.rs (limited to 'support/texlab/src/test/server.rs') diff --git a/support/texlab/src/test/server.rs b/support/texlab/src/test/server.rs new file mode 100644 index 0000000000..77bed68c07 --- /dev/null +++ b/support/texlab/src/test/server.rs @@ -0,0 +1,87 @@ +use crate::protocol::*; +use aovec::Aovec; +use async_trait::async_trait; +use chashmap::CHashMap; +use futures::lock::Mutex; +use jsonrpc::server::{Middleware, Result}; +use jsonrpc_derive::{jsonrpc_method, jsonrpc_server}; + +pub struct TestLatexLspServer { + pub options: Mutex, + pub show_message_buf: Aovec, + pub register_capability_buf: Aovec, + pub diagnostics_by_uri: CHashMap>, + pub progress_buf: Aovec, + pub work_done_progress_create_buf: Aovec, + pub log_message_buf: Aovec, +} + +#[jsonrpc_server] +impl TestLatexLspServer { + pub fn new(options: Options) -> Self { + let base = 16; + Self { + options: Mutex::new(options), + show_message_buf: Aovec::new(base), + register_capability_buf: Aovec::new(base), + diagnostics_by_uri: CHashMap::new(), + progress_buf: Aovec::new(base), + work_done_progress_create_buf: Aovec::new(base), + log_message_buf: Aovec::new(base), + } + } + + #[jsonrpc_method("workspace/configuration", kind = "request")] + pub async fn configuration(&self, params: ConfigurationParams) -> Result { + let options = self.options.lock().await; + if params.items[0].section.as_ref().unwrap() == "latex" { + Ok(serde_json::to_value(vec![options.latex.clone().unwrap_or_default()]).unwrap()) + } else { + Ok(serde_json::to_value(vec![options.bibtex.clone().unwrap_or_default()]).unwrap()) + } + } + + #[jsonrpc_method("window/showMessage", kind = "notification")] + pub async fn show_message(&self, params: ShowMessageParams) { + self.show_message_buf.push(params); + } + + #[jsonrpc_method("client/registerCapability", kind = "request")] + pub async fn register_capability(&self, params: RegistrationParams) -> Result<()> { + self.register_capability_buf.push(params); + Ok(()) + } + + #[jsonrpc_method("textDocument/publishDiagnostics", kind = "notification")] + pub async fn publish_diagnostics(&self, params: PublishDiagnosticsParams) { + let _ = self + .diagnostics_by_uri + .insert(params.uri.into(), params.diagnostics); + } + + #[jsonrpc_method("$/progress", kind = "notification")] + pub async fn progress(&self, params: ProgressParams) { + self.progress_buf.push(params); + } + + #[jsonrpc_method("window/workDoneProgress/create", kind = "request")] + pub async fn work_done_progress_create( + &self, + params: WorkDoneProgressCreateParams, + ) -> Result<()> { + self.work_done_progress_create_buf.push(params); + Ok(()) + } + + #[jsonrpc_method("window/logMessage", kind = "notification")] + pub async fn log_message(&self, params: LogMessageParams) { + self.log_message_buf.push(params); + } +} + +#[async_trait] +impl Middleware for TestLatexLspServer { + async fn before_message(&self) {} + + async fn after_message(&self) {} +} -- cgit v1.2.3