Skip to content

Commit

Permalink
support rust-analyzer's notification "experimental/serverStatus". (la…
Browse files Browse the repository at this point in the history
  • Loading branch information
jm-observer authored Jul 25, 2024
1 parent fef57e8 commit 7d38307
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lapce-app/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ impl Doc {
}

/// Request semantic styles for the buffer from the LSP through the proxy.
fn get_semantic_styles(&self) {
pub fn get_semantic_styles(&self) {
if !self.loaded() {
return;
}
Expand Down
10 changes: 10 additions & 0 deletions lapce-app/src/window_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,16 @@ impl WindowTabData {
doc.init_diagnostics();
}
}
CoreNotification::ServerStatus { params } => {
if params.is_ok() {
// todo filter by language
self.main_split.docs.with_untracked(|x| {
for doc in x.values() {
doc.get_semantic_styles();
}
});
}
}
CoreNotification::TerminalProcessStopped { term_id } => {
let _ = self
.common
Expand Down
6 changes: 5 additions & 1 deletion lapce-proxy/src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use lsp_types::{
};
use parking_lot::Mutex;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_json::Value;
use serde_json::{Map, Value};
use tar::Archive;
use tracing::error;

Expand Down Expand Up @@ -1472,6 +1472,9 @@ pub fn remove_volt(
}

fn client_capabilities() -> ClientCapabilities {
// https://github.com/rust-lang/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#server-status
let mut experimental = Map::new();
experimental.insert("serverStatusNotification".into(), true.into());
ClientCapabilities {
text_document: Some(TextDocumentClientCapabilities {
synchronization: Some(TextDocumentSyncClientCapabilities {
Expand Down Expand Up @@ -1575,6 +1578,7 @@ fn client_capabilities() -> ClientCapabilities {
workspace_folders: Some(true),
..Default::default()
}),
experimental: Some(experimental.into()),
..Default::default()
}
}
6 changes: 6 additions & 0 deletions lapce-proxy/src/plugin/psp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use dyn_clone::DynClone;
use floem_editor_core::buffer::rope_text::{RopeText, RopeTextRef};
use jsonrpc_lite::{Id, JsonRpc, Params};
use lapce_core::{encoding::offset_utf16_to_utf8, rope_text_pos::RopeTextPosition};
use lapce_rpc::core::ServerStatusParams;
use lapce_rpc::{
core::CoreRpcHandler,
plugin::{PluginId, VoltID},
Expand Down Expand Up @@ -1075,6 +1076,11 @@ impl PluginHostHandler {
),
);
}
"experimental/serverStatus" => {
let param: ServerStatusParams =
serde_json::from_value(serde_json::to_value(params)?)?;
self.catalog_rpc.core_rpc.server_status(param);
}
_ => {
self.core_rpc.log(
lapce_rpc::core::LogLevel::Warn,
Expand Down
20 changes: 20 additions & 0 deletions lapce-rpc/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ pub enum CoreNotification {
PublishDiagnostics {
diagnostics: PublishDiagnosticsParams,
},
ServerStatus {
params: ServerStatusParams,
},
WorkDoneProgress {
progress: ProgressParams,
},
Expand Down Expand Up @@ -302,6 +305,10 @@ impl CoreRpcHandler {
self.notification(CoreNotification::PublishDiagnostics { diagnostics });
}

pub fn server_status(&self, params: ServerStatusParams) {
self.notification(CoreNotification::ServerStatus { params });
}

pub fn work_done_progress(&self, progress: ProgressParams) {
self.notification(CoreNotification::WorkDoneProgress { progress });
}
Expand Down Expand Up @@ -384,3 +391,16 @@ pub enum LogLevel {
Debug = 3,
Trace = 4,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ServerStatusParams {
health: String,
quiescent: bool,
message: Option<String>,
}

impl ServerStatusParams {
pub fn is_ok(&self) -> bool {
self.health.as_str() == "ok"
}
}

0 comments on commit 7d38307

Please sign in to comment.