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 rust-analyzer lint errors from invalid Cargo.toml #61

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,6 @@ async fn spawn(

info!(server = ?key.server, args = ?key.args, cwd = ?key.workspace_root, "spawned langauge server");

let stderr = child.stderr.take().unwrap();
task::spawn(stderr_task(stderr).in_current_span());

let stdout = child.stdout.take().unwrap();
let mut reader = LspReader::new(BufReader::new(stdout), "server");

Expand All @@ -329,6 +326,9 @@ async fn spawn(
last_used: AtomicI64::new(utc_now()),
});

let stderr = child.stderr.take().unwrap();
task::spawn(stderr_task(instance.clone(), stderr).in_current_span());

task::spawn(stdout_task(instance.clone(), reader).in_current_span());
task::spawn(stdin_task(rx, writer).in_current_span());

Expand Down Expand Up @@ -387,8 +387,21 @@ async fn initialize_handshake(
Ok(result)
}

/// Send error notification to all clients
async fn send_error_notification(instance: Arc<Instance>, message: &str) {
let notify = Notification {
jsonrpc: Version,
method: "experimental/serverStatus".into(),
params: serde_json::json!({ "health": "error", "message": message }),
};
let clients = instance.clients.lock().await;
for client in clients.values() {
let _ = client.send_message(notify.clone().into()).await;
}
}

/// Read errors from langauge server stderr and log them
async fn stderr_task(stderr: ChildStderr) {
async fn stderr_task(instance: Arc<Instance>, stderr: ChildStderr) {
let mut stderr = BufReader::new(stderr);
let mut buffer = String::new();

Expand All @@ -402,6 +415,9 @@ async fn stderr_task(stderr: ChildStderr) {
}
Ok(_) => {
let line = buffer.trim_end(); // remove trailing '\n' or possibly '\r\n'

send_error_notification(instance.clone(), line).await;

error!(%line, "stderr");
}
Err(err) => {
Expand Down
Loading