Closes #13089 Here we use `experimental` to advertise our support for `inactiveRegions`. Note that clangd does not currently have a stable release that reads the `experimental` object (PR https://github.com/llvm/llvm-project/pull/116531), this can be tested with one of clangd's recent "unstable snapshots" in their [releases](https://github.com/clangd/clangd/releases). Release Notes: - Added support for clangd's `inactiveRegions` extension.  --------- Co-authored-by: Peter Tripp <peter@zed.dev> Co-authored-by: Kirill Bulatov <kirill@zed.dev>
84 lines
3.3 KiB
Rust
84 lines
3.3 KiB
Rust
use ::serde::{Deserialize, Serialize};
|
|
use gpui::{PromptLevel, WeakEntity};
|
|
use lsp::LanguageServer;
|
|
|
|
use crate::{LanguageServerPromptRequest, LspStore, LspStoreEvent};
|
|
|
|
pub const RUST_ANALYZER_NAME: &str = "rust-analyzer";
|
|
|
|
/// Experimental: Informs the end user about the state of the server
|
|
///
|
|
/// [Rust Analyzer Specification](https://github.com/rust-lang/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#server-status)
|
|
#[derive(Debug)]
|
|
enum ServerStatus {}
|
|
|
|
/// Other(String) variant to handle unknown values due to this still being experimental
|
|
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
|
|
#[serde(rename_all = "camelCase")]
|
|
enum ServerHealthStatus {
|
|
Ok,
|
|
Warning,
|
|
Error,
|
|
Other(String),
|
|
}
|
|
|
|
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
|
|
#[serde(rename_all = "camelCase")]
|
|
struct ServerStatusParams {
|
|
pub health: ServerHealthStatus,
|
|
pub message: Option<String>,
|
|
}
|
|
|
|
impl lsp::notification::Notification for ServerStatus {
|
|
type Params = ServerStatusParams;
|
|
const METHOD: &'static str = "experimental/serverStatus";
|
|
}
|
|
|
|
pub fn register_notifications(lsp_store: WeakEntity<LspStore>, language_server: &LanguageServer) {
|
|
let name = language_server.name();
|
|
let server_id = language_server.server_id();
|
|
|
|
let this = lsp_store;
|
|
|
|
language_server
|
|
.on_notification::<ServerStatus, _>({
|
|
let name = name.to_string();
|
|
move |params, mut cx| {
|
|
let this = this.clone();
|
|
let name = name.to_string();
|
|
if let Some(ref message) = params.message {
|
|
let message = message.trim();
|
|
if !message.is_empty() {
|
|
let formatted_message = format!(
|
|
"Language server {name} (id {server_id}) status update: {message}"
|
|
);
|
|
match params.health {
|
|
ServerHealthStatus::Ok => log::info!("{}", formatted_message),
|
|
ServerHealthStatus::Warning => log::warn!("{}", formatted_message),
|
|
ServerHealthStatus::Error => {
|
|
log::error!("{}", formatted_message);
|
|
let (tx, _rx) = smol::channel::bounded(1);
|
|
let request = LanguageServerPromptRequest {
|
|
level: PromptLevel::Critical,
|
|
message: params.message.unwrap_or_default(),
|
|
actions: Vec::new(),
|
|
response_channel: tx,
|
|
lsp_name: name.clone(),
|
|
};
|
|
let _ = this
|
|
.update(&mut cx, |_, cx| {
|
|
cx.emit(LspStoreEvent::LanguageServerPrompt(request));
|
|
})
|
|
.ok();
|
|
}
|
|
ServerHealthStatus::Other(status) => {
|
|
log::info!("Unknown server health: {status}\n{formatted_message}")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
.detach();
|
|
}
|