From 56a73b497b8594331b8e0fdb2679bdf925ec1dc1 Mon Sep 17 00:00:00 2001 From: Peter Cardenas <16930781+PeterCardenas@users.noreply.github.com> Date: Sun, 4 May 2025 17:57:14 -0700 Subject: [PATCH] feat: add progress for initializing server --- crates/starpls/src/commands/server.rs | 18 ++++++++++++++++++ crates/starpls/src/server.rs | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/crates/starpls/src/commands/server.rs b/crates/starpls/src/commands/server.rs index 7dc07e9..539be6d 100644 --- a/crates/starpls/src/commands/server.rs +++ b/crates/starpls/src/commands/server.rs @@ -1,10 +1,13 @@ use clap::Args; use log::info; use lsp_server::Connection; +use lsp_types::notification::Notification; +use lsp_types::notification::Progress; use lsp_types::CompletionOptions; use lsp_types::DeclarationCapability; use lsp_types::HoverProviderCapability; use lsp_types::OneOf; +use lsp_types::ProgressParams; use lsp_types::ServerCapabilities; use lsp_types::SignatureHelpOptions; use lsp_types::TextDocumentSyncCapability; @@ -18,6 +21,8 @@ use crate::make_trigger_characters; const COMPLETION_TRIGGER_CHARACTERS: &[char] = &['.', '"', '\'', '/', ':', '@']; const SIGNATURE_HELP_TRIGGER_CHARACTERS: &[char] = &['(', ',', ')']; +pub(crate) const INITIALIZATION_TOKEN: &str = "Initializing"; + #[derive(Args, Default)] pub(crate) struct ServerCommand { /// Path to the Bazel binary. @@ -52,6 +57,19 @@ impl ServerCommand { // Create the transport over stdio. let (connection, io_threads) = Connection::stdio(); + let not = lsp_server::Notification::new( + Progress::METHOD.to_string(), + ProgressParams { + token: lsp_types::NumberOrString::String(INITIALIZATION_TOKEN.to_string()), + value: lsp_types::ProgressParamsValue::WorkDone( + lsp_types::WorkDoneProgress::Begin(lsp_types::WorkDoneProgressBegin { + title: "Initializing".to_string(), + ..Default::default() + }), + ), + }, + ); + connection.sender.send(not.into()).unwrap(); // Initialize the connection with server capabilities. For now, this consists // only of `TextDocumentSyncKind.Full`. diff --git a/crates/starpls/src/server.rs b/crates/starpls/src/server.rs index 64eefac..b8a8031 100644 --- a/crates/starpls/src/server.rs +++ b/crates/starpls/src/server.rs @@ -11,6 +11,9 @@ use log::error; use log::info; use lsp_server::Connection; use lsp_server::ReqQueue; +use lsp_types::notification::Notification; +use lsp_types::notification::Progress; +use lsp_types::ProgressParams; use parking_lot::RwLock; use rustc_hash::FxHashSet; use starpls_bazel::build_language::decode_rules; @@ -28,6 +31,7 @@ use starpls_ide::Change; use starpls_ide::InferenceOptions; use crate::bazel::BazelContext; +use crate::commands::server::INITIALIZATION_TOKEN; use crate::config::ServerConfig; use crate::debouncer::AnalysisDebouncer; use crate::diagnostics::DiagnosticsManager; @@ -189,6 +193,23 @@ impl Server { if has_bazel_init_err { server.send_error_message(BAZEL_INIT_ERR_MESSAGE); } + let initialization_msg = if has_bazel_init_err { + BAZEL_INIT_ERR_MESSAGE + } else { + "Initialization complete" + }; + let not = lsp_server::Notification::new( + Progress::METHOD.to_string(), + ProgressParams { + token: lsp_types::NumberOrString::String(INITIALIZATION_TOKEN.to_string()), + value: lsp_types::ProgressParamsValue::WorkDone(lsp_types::WorkDoneProgress::End( + lsp_types::WorkDoneProgressEnd { + message: Some(initialization_msg.to_string()), + }, + )), + }, + ); + server.connection.sender.send(not.into()).unwrap(); Ok(server) }