mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
show message in client's UI if workspace fails to load
This commit is contained in:
parent
e7241274ef
commit
73b892aaa3
3 changed files with 32 additions and 8 deletions
|
@ -15,6 +15,24 @@ pub enum RawMessage {
|
||||||
Response(RawResponse),
|
Response(RawResponse),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<RawRequest> for RawMessage {
|
||||||
|
fn from(raw: RawRequest) -> RawMessage {
|
||||||
|
RawMessage::Request(raw)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<RawNotification> for RawMessage {
|
||||||
|
fn from(raw: RawNotification) -> RawMessage {
|
||||||
|
RawMessage::Notification(raw)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<RawResponse> for RawMessage {
|
||||||
|
fn from(raw: RawResponse) -> RawMessage {
|
||||||
|
RawMessage::Response(raw)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct RawRequest {
|
pub struct RawRequest {
|
||||||
pub id: u64,
|
pub id: u64,
|
||||||
|
|
|
@ -63,6 +63,11 @@ pub fn main_loop(
|
||||||
Ok(ws) => vec![ws],
|
Ok(ws) => vec![ws],
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("loading workspace failed: {}", e);
|
log::error!("loading workspace failed: {}", e);
|
||||||
|
let msg = RawNotification::new::<req::ShowMessage>(&req::ShowMessageParams {
|
||||||
|
typ: req::MessageType::Error,
|
||||||
|
message: format!("rust-analyzer failed to load workspace: {}", e),
|
||||||
|
});
|
||||||
|
msg_sender.send(msg.into()).unwrap();
|
||||||
Vec::new()
|
Vec::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,7 +204,7 @@ fn main_loop_inner(
|
||||||
Ok((id, ())) => {
|
Ok((id, ())) => {
|
||||||
state.collect_garbage();
|
state.collect_garbage();
|
||||||
let resp = RawResponse::ok::<req::CollectGarbage>(id, &());
|
let resp = RawResponse::ok::<req::CollectGarbage>(id, &());
|
||||||
msg_sender.send(RawMessage::Response(resp)).unwrap()
|
msg_sender.send(resp.into()).unwrap()
|
||||||
}
|
}
|
||||||
Err(req) => {
|
Err(req) => {
|
||||||
match on_request(state, pending_requests, pool, &task_sender, req)? {
|
match on_request(state, pending_requests, pool, &task_sender, req)? {
|
||||||
|
@ -211,7 +216,7 @@ fn main_loop_inner(
|
||||||
ErrorCode::MethodNotFound as i32,
|
ErrorCode::MethodNotFound as i32,
|
||||||
"unknown request".to_string(),
|
"unknown request".to_string(),
|
||||||
);
|
);
|
||||||
msg_sender.send(RawMessage::Response(resp)).unwrap()
|
msg_sender.send(resp.into()).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,11 +265,11 @@ fn on_task(task: Task, msg_sender: &Sender<RawMessage>, pending_requests: &mut F
|
||||||
match task {
|
match task {
|
||||||
Task::Respond(response) => {
|
Task::Respond(response) => {
|
||||||
if pending_requests.remove(&response.id) {
|
if pending_requests.remove(&response.id) {
|
||||||
msg_sender.send(RawMessage::Response(response)).unwrap();
|
msg_sender.send(response.into()).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Task::Notify(n) => {
|
Task::Notify(n) => {
|
||||||
msg_sender.send(RawMessage::Notification(n)).unwrap();
|
msg_sender.send(n.into()).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -336,7 +341,7 @@ fn on_notification(
|
||||||
ErrorCode::RequestCanceled as i32,
|
ErrorCode::RequestCanceled as i32,
|
||||||
"canceled by client".to_string(),
|
"canceled by client".to_string(),
|
||||||
);
|
);
|
||||||
msg_sender.send(RawMessage::Response(response)).unwrap()
|
msg_sender.send(response.into()).unwrap()
|
||||||
}
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -375,7 +380,7 @@ fn on_notification(
|
||||||
}
|
}
|
||||||
let params = req::PublishDiagnosticsParams { uri, diagnostics: Vec::new() };
|
let params = req::PublishDiagnosticsParams { uri, diagnostics: Vec::new() };
|
||||||
let not = RawNotification::new::<req::PublishDiagnostics>(¶ms);
|
let not = RawNotification::new::<req::PublishDiagnostics>(¶ms);
|
||||||
msg_sender.send(RawMessage::Notification(not)).unwrap();
|
msg_sender.send(not.into()).unwrap();
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
Err(not) => not,
|
Err(not) => not,
|
||||||
|
@ -501,7 +506,7 @@ fn feedback(intrnal_mode: bool, msg: &str, sender: &Sender<RawMessage>) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let not = RawNotification::new::<req::InternalFeedback>(&msg.to_string());
|
let not = RawNotification::new::<req::InternalFeedback>(&msg.to_string());
|
||||||
sender.send(RawMessage::Notification(not)).unwrap();
|
sender.send(not.into()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_canceled(e: &failure::Error) -> bool {
|
fn is_canceled(e: &failure::Error) -> bool {
|
||||||
|
|
|
@ -8,7 +8,8 @@ pub use lsp_types::{
|
||||||
CompletionParams, CompletionResponse, DocumentOnTypeFormattingParams, DocumentSymbolParams,
|
CompletionParams, CompletionResponse, DocumentOnTypeFormattingParams, DocumentSymbolParams,
|
||||||
DocumentSymbolResponse, ExecuteCommandParams, Hover, InitializeResult,
|
DocumentSymbolResponse, ExecuteCommandParams, Hover, InitializeResult,
|
||||||
PublishDiagnosticsParams, ReferenceParams, SignatureHelp, TextDocumentEdit,
|
PublishDiagnosticsParams, ReferenceParams, SignatureHelp, TextDocumentEdit,
|
||||||
TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams
|
TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams,
|
||||||
|
MessageType, ShowMessageParams,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub enum AnalyzerStatus {}
|
pub enum AnalyzerStatus {}
|
||||||
|
|
Loading…
Reference in a new issue