mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 23:25:03 +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,
|
Loading,
|
||||||
Ready,
|
Ready,
|
||||||
Invalid,
|
Invalid,
|
||||||
|
NeedsReload,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Status {
|
impl Default for Status {
|
||||||
|
|
|
@ -111,6 +111,35 @@ impl GlobalState {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(mut self, inbox: Receiver<lsp_server::Message>) -> Result<()> {
|
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();
|
self.reload();
|
||||||
|
|
||||||
while let Some(event) = self.next_event(&inbox) {
|
while let Some(event) = self.next_event(&inbox) {
|
||||||
|
@ -281,6 +310,7 @@ impl GlobalState {
|
||||||
Status::Loading => lsp_ext::Status::Loading,
|
Status::Loading => lsp_ext::Status::Loading,
|
||||||
Status::Ready => lsp_ext::Status::Ready,
|
Status::Ready => lsp_ext::Status::Ready,
|
||||||
Status::Invalid => lsp_ext::Status::Invalid,
|
Status::Invalid => lsp_ext::Status::Invalid,
|
||||||
|
Status::NeedsReload => lsp_ext::Status::NeedsReload,
|
||||||
};
|
};
|
||||||
self.send_notification::<lsp_ext::StatusNotification>(lsp_status);
|
self.send_notification::<lsp_ext::StatusNotification>(lsp_status);
|
||||||
}
|
}
|
||||||
|
@ -395,10 +425,16 @@ impl GlobalState {
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
})?
|
})?
|
||||||
.on::<lsp_types::notification::DidSaveTextDocument>(|this, _params| {
|
.on::<lsp_types::notification::DidSaveTextDocument>(|this, params| {
|
||||||
if let Some(flycheck) = &this.flycheck {
|
if let Some(flycheck) = &this.flycheck {
|
||||||
flycheck.handle.update();
|
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(())
|
Ok(())
|
||||||
})?
|
})?
|
||||||
.on::<lsp_types::notification::DidChangeConfiguration>(|this, _params| {
|
.on::<lsp_types::notification::DidChangeConfiguration>(|this, _params| {
|
||||||
|
|
|
@ -78,7 +78,7 @@ impl GlobalState {
|
||||||
.collect(),
|
.collect(),
|
||||||
};
|
};
|
||||||
let registration = lsp_types::Registration {
|
let registration = lsp_types::Registration {
|
||||||
id: "file-watcher".to_string(),
|
id: "workspace/didChangeWatchedFiles".to_string(),
|
||||||
method: "workspace/didChangeWatchedFiles".to_string(),
|
method: "workspace/didChangeWatchedFiles".to_string(),
|
||||||
register_options: Some(serde_json::to_value(registration_options).unwrap()),
|
register_options: Some(serde_json::to_value(registration_options).unwrap()),
|
||||||
};
|
};
|
||||||
|
|
|
@ -176,12 +176,19 @@ impl Server {
|
||||||
while let Some(msg) = self.recv() {
|
while let Some(msg) = self.recv() {
|
||||||
match msg {
|
match msg {
|
||||||
Message::Request(req) => {
|
Message::Request(req) => {
|
||||||
if req.method != "window/workDoneProgress/create"
|
if req.method == "window/workDoneProgress/create" {
|
||||||
&& !(req.method == "client/registerCapability"
|
continue;
|
||||||
&& req.params.to_string().contains("workspace/didChangeWatchedFiles"))
|
|
||||||
{
|
|
||||||
panic!("unexpected request: {:?}", req)
|
|
||||||
}
|
}
|
||||||
|
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::Notification(_) => (),
|
||||||
Message::Response(res) => {
|
Message::Response(res) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue