mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Indicate when project needs a reload
This commit is contained in:
parent
3ef7676076
commit
4f26a3734e
4 changed files with 51 additions and 7 deletions
|
@ -32,6 +32,7 @@ pub(crate) enum Status {
|
|||
Loading,
|
||||
Ready,
|
||||
Invalid,
|
||||
NeedsReload,
|
||||
}
|
||||
|
||||
impl Default for Status {
|
||||
|
|
|
@ -111,6 +111,35 @@ impl GlobalState {
|
|||
}
|
||||
|
||||
fn run(mut self, inbox: Receiver<lsp_server::Message>) -> Result<()> {
|
||||
let registration_options = lsp_types::TextDocumentRegistrationOptions {
|
||||
document_selector: Some(vec![
|
||||
lsp_types::DocumentFilter {
|
||||
language: None,
|
||||
scheme: None,
|
||||
pattern: Some("**/*.rs".into()),
|
||||
},
|
||||
lsp_types::DocumentFilter {
|
||||
language: None,
|
||||
scheme: None,
|
||||
pattern: Some("**/Cargo.toml".into()),
|
||||
},
|
||||
lsp_types::DocumentFilter {
|
||||
language: None,
|
||||
scheme: None,
|
||||
pattern: Some("**/Cargo.lock".into()),
|
||||
},
|
||||
]),
|
||||
};
|
||||
let registration = lsp_types::Registration {
|
||||
id: "textDocument/didSave".to_string(),
|
||||
method: "textDocument/didSave".to_string(),
|
||||
register_options: Some(serde_json::to_value(registration_options).unwrap()),
|
||||
};
|
||||
self.send_request::<lsp_types::request::RegisterCapability>(
|
||||
lsp_types::RegistrationParams { registrations: vec![registration] },
|
||||
|_, _| (),
|
||||
);
|
||||
|
||||
self.reload();
|
||||
|
||||
while let Some(event) = self.next_event(&inbox) {
|
||||
|
@ -281,6 +310,7 @@ impl GlobalState {
|
|||
Status::Loading => lsp_ext::Status::Loading,
|
||||
Status::Ready => lsp_ext::Status::Ready,
|
||||
Status::Invalid => lsp_ext::Status::Invalid,
|
||||
Status::NeedsReload => lsp_ext::Status::NeedsReload,
|
||||
};
|
||||
self.send_notification::<lsp_ext::StatusNotification>(lsp_status);
|
||||
}
|
||||
|
@ -395,10 +425,16 @@ impl GlobalState {
|
|||
);
|
||||
Ok(())
|
||||
})?
|
||||
.on::<lsp_types::notification::DidSaveTextDocument>(|this, _params| {
|
||||
.on::<lsp_types::notification::DidSaveTextDocument>(|this, params| {
|
||||
if let Some(flycheck) = &this.flycheck {
|
||||
flycheck.handle.update();
|
||||
}
|
||||
let uri = params.text_document.uri.as_str();
|
||||
if uri.ends_with("Cargo.toml") || uri.ends_with("Cargo.lock") {
|
||||
if matches!(this.status, Status::Ready | Status::Invalid) {
|
||||
this.transition(Status::NeedsReload);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})?
|
||||
.on::<lsp_types::notification::DidChangeConfiguration>(|this, _params| {
|
||||
|
|
|
@ -78,7 +78,7 @@ impl GlobalState {
|
|||
.collect(),
|
||||
};
|
||||
let registration = lsp_types::Registration {
|
||||
id: "file-watcher".to_string(),
|
||||
id: "workspace/didChangeWatchedFiles".to_string(),
|
||||
method: "workspace/didChangeWatchedFiles".to_string(),
|
||||
register_options: Some(serde_json::to_value(registration_options).unwrap()),
|
||||
};
|
||||
|
|
|
@ -176,12 +176,19 @@ impl Server {
|
|||
while let Some(msg) = self.recv() {
|
||||
match msg {
|
||||
Message::Request(req) => {
|
||||
if req.method != "window/workDoneProgress/create"
|
||||
&& !(req.method == "client/registerCapability"
|
||||
&& req.params.to_string().contains("workspace/didChangeWatchedFiles"))
|
||||
{
|
||||
panic!("unexpected request: {:?}", req)
|
||||
if req.method == "window/workDoneProgress/create" {
|
||||
continue;
|
||||
}
|
||||
if req.method == "client/registerCapability" {
|
||||
let params = req.params.to_string();
|
||||
if ["workspace/didChangeWatchedFiles", "textDocument/didSave"]
|
||||
.iter()
|
||||
.any(|&it| params.contains(it))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
panic!("unexpected request: {:?}", req)
|
||||
}
|
||||
Message::Notification(_) => (),
|
||||
Message::Response(res) => {
|
||||
|
|
Loading…
Reference in a new issue