Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose more errors from rust-analyzer on invalid Cargo.toml contents #8356

Merged
merged 8 commits into from
Mar 2, 2024
28 changes: 28 additions & 0 deletions crates/lsp/src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,34 @@ struct Error {
message: String,
}

/// 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)]
pub enum ServerStatus {}
zephaniahong marked this conversation as resolved.
Show resolved Hide resolved

/// Other(String) variant to handle unknown values due to this still being experimental
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub enum ServerHealthStatus {
Ok,
Warning,
Error,
Other(String),
}

#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ServerStatusParams {
pub health: ServerHealthStatus,
pub message: Option<String>,
}

impl lsp_types::notification::Notification for ServerStatus {
type Params = ServerStatusParams;
const METHOD: &'static str = "experimental/serverStatus";
}

impl LanguageServer {
/// Starts a language server process.
pub fn new(
Expand Down
46 changes: 45 additions & 1 deletion crates/project/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use log::error;
use lsp::{
DiagnosticSeverity, DiagnosticTag, DidChangeWatchedFilesRegistrationOptions,
DocumentHighlightKind, LanguageServer, LanguageServerBinary, LanguageServerId,
MessageActionItem, OneOf,
MessageActionItem, OneOf, ServerHealthStatus, ServerStatus,
};
use lsp_command::*;
use node_runtime::NodeRuntime;
Expand Down Expand Up @@ -3201,6 +3201,50 @@ impl Project {
let disk_based_diagnostics_progress_token =
adapter.disk_based_diagnostics_progress_token.clone();

language_server
.on_notification::<ServerStatus, _>({
let this = this.clone();
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(Event::LanguageServerPrompt(request));
})
.ok();
}
ServerHealthStatus::Other(status) => {
log::info!(
"Unknown server health: {status}\n{formatted_message}"
)
}
SomeoneToIgnore marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
})
.detach();

language_server
.on_notification::<lsp::notification::Progress, _>(move |params, mut cx| {
if let Some(this) = this.upgrade() {
Expand Down
1 change: 1 addition & 0 deletions crates/workspace/src/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ impl Render for LanguageServerPrompt {
.id("language_server_prompt_notification")
.elevation_3(cx)
.items_start()
.justify_between()
SomeoneToIgnore marked this conversation as resolved.
Show resolved Hide resolved
.p_2()
.gap_2()
.w_full()
Expand Down
Loading