aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/flycheck/src/lib.rs1
-rw-r--r--crates/ra_project_model/src/project_json.rs6
-rw-r--r--crates/rust-analyzer/src/config.rs2
-rw-r--r--crates/rust-analyzer/src/global_state.rs2
-rw-r--r--crates/rust-analyzer/src/lsp_ext.rs6
-rw-r--r--crates/rust-analyzer/src/main_loop.rs14
-rw-r--r--crates/rust-analyzer/src/reload.rs5
-rw-r--r--docs/dev/lsp-extensions.md8
-rw-r--r--editors/code/package.json8
-rw-r--r--editors/code/src/commands.ts4
-rw-r--r--editors/code/src/lsp_ext.ts2
-rw-r--r--editors/code/src/main.ts2
12 files changed, 33 insertions, 27 deletions
diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs
index 1023d3040..844b093d4 100644
--- a/crates/flycheck/src/lib.rs
+++ b/crates/flycheck/src/lib.rs
@@ -132,6 +132,7 @@ impl FlycheckActor {
132 self.cancel_check_process(); 132 self.cancel_check_process();
133 133
134 let mut command = self.check_command(); 134 let mut command = self.check_command();
135 log::info!("restart flycheck {:?}", command);
135 command.stdout(Stdio::piped()).stderr(Stdio::null()).stdin(Stdio::null()); 136 command.stdout(Stdio::piped()).stderr(Stdio::null()).stdin(Stdio::null());
136 if let Ok(child) = command.spawn().map(JodChild) { 137 if let Ok(child) = command.spawn().map(JodChild) {
137 self.cargo_handle = Some(CargoHandle::spawn(child)); 138 self.cargo_handle = Some(CargoHandle::spawn(child));
diff --git a/crates/ra_project_model/src/project_json.rs b/crates/ra_project_model/src/project_json.rs
index 9fe1e2dcb..b0fe09333 100644
--- a/crates/ra_project_model/src/project_json.rs
+++ b/crates/ra_project_model/src/project_json.rs
@@ -10,7 +10,7 @@ use serde::{de, Deserialize};
10use stdx::split_delim; 10use stdx::split_delim;
11 11
12/// Roots and crates that compose this Rust project. 12/// Roots and crates that compose this Rust project.
13#[derive(Clone, Debug)] 13#[derive(Clone, Debug, Eq, PartialEq)]
14pub struct ProjectJson { 14pub struct ProjectJson {
15 pub(crate) roots: Vec<Root>, 15 pub(crate) roots: Vec<Root>,
16 pub(crate) crates: Vec<Crate>, 16 pub(crate) crates: Vec<Crate>,
@@ -18,14 +18,14 @@ pub struct ProjectJson {
18 18
19/// A root points to the directory which contains Rust crates. rust-analyzer watches all files in 19/// A root points to the directory which contains Rust crates. rust-analyzer watches all files in
20/// all roots. Roots might be nested. 20/// all roots. Roots might be nested.
21#[derive(Clone, Debug)] 21#[derive(Clone, Debug, Eq, PartialEq)]
22pub struct Root { 22pub struct Root {
23 pub(crate) path: AbsPathBuf, 23 pub(crate) path: AbsPathBuf,
24} 24}
25 25
26/// A crate points to the root module of a crate and lists the dependencies of the crate. This is 26/// A crate points to the root module of a crate and lists the dependencies of the crate. This is
27/// useful in creating the crate graph. 27/// useful in creating the crate graph.
28#[derive(Clone, Debug)] 28#[derive(Clone, Debug, Eq, PartialEq)]
29pub struct Crate { 29pub struct Crate {
30 pub(crate) root_module: AbsPathBuf, 30 pub(crate) root_module: AbsPathBuf,
31 pub(crate) edition: Edition, 31 pub(crate) edition: Edition,
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 6b17ce18b..6c311648a 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -44,7 +44,7 @@ pub struct Config {
44 pub root_path: AbsPathBuf, 44 pub root_path: AbsPathBuf,
45} 45}
46 46
47#[derive(Debug, Clone)] 47#[derive(Debug, Clone, Eq, PartialEq)]
48pub enum LinkedProject { 48pub enum LinkedProject {
49 ProjectManifest(ProjectManifest), 49 ProjectManifest(ProjectManifest),
50 InlineJsonProject(ProjectJson), 50 InlineJsonProject(ProjectJson),
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs
index b8aa1e5b5..b7b4edf66 100644
--- a/crates/rust-analyzer/src/global_state.rs
+++ b/crates/rust-analyzer/src/global_state.rs
@@ -27,7 +27,7 @@ use crate::{
27 Result, 27 Result,
28}; 28};
29 29
30#[derive(Eq, PartialEq)] 30#[derive(Eq, PartialEq, Copy, Clone)]
31pub(crate) enum Status { 31pub(crate) enum Status {
32 Loading, 32 Loading,
33 Ready, 33 Ready,
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs
index 1befe678c..82207bbb8 100644
--- a/crates/rust-analyzer/src/lsp_ext.rs
+++ b/crates/rust-analyzer/src/lsp_ext.rs
@@ -14,12 +14,12 @@ impl Request for AnalyzerStatus {
14 const METHOD: &'static str = "rust-analyzer/analyzerStatus"; 14 const METHOD: &'static str = "rust-analyzer/analyzerStatus";
15} 15}
16 16
17pub enum CollectGarbage {} 17pub enum ReloadWorkspace {}
18 18
19impl Request for CollectGarbage { 19impl Request for ReloadWorkspace {
20 type Params = (); 20 type Params = ();
21 type Result = (); 21 type Result = ();
22 const METHOD: &'static str = "rust-analyzer/collectGarbage"; 22 const METHOD: &'static str = "rust-analyzer/reloadWorkspace";
23} 23}
24 24
25pub enum SyntaxTree {} 25pub enum SyntaxTree {}
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 2ce1441b6..e03038b25 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -136,7 +136,7 @@ impl GlobalState {
136 log::info!("queued count = {}", queue_count); 136 log::info!("queued count = {}", queue_count);
137 } 137 }
138 138
139 let mut became_ready = false; 139 let prev_status = self.status;
140 match event { 140 match event {
141 Event::Lsp(msg) => match msg { 141 Event::Lsp(msg) => match msg {
142 lsp_server::Message::Request(req) => self.on_request(loop_start, req)?, 142 lsp_server::Message::Request(req) => self.on_request(loop_start, req)?,
@@ -168,15 +168,17 @@ impl GlobalState {
168 } 168 }
169 } 169 }
170 vfs::loader::Message::Progress { n_total, n_done } => { 170 vfs::loader::Message::Progress { n_total, n_done } => {
171 if n_total > 0 { 171 if n_total == 0 {
172 self.status = Status::Ready;
173 } else {
172 let state = if n_done == 0 { 174 let state = if n_done == 0 {
175 self.status = Status::Loading;
173 Progress::Begin 176 Progress::Begin
174 } else if n_done < n_total { 177 } else if n_done < n_total {
175 Progress::Report 178 Progress::Report
176 } else { 179 } else {
177 assert_eq!(n_done, n_total); 180 assert_eq!(n_done, n_total);
178 self.status = Status::Ready; 181 self.status = Status::Ready;
179 became_ready = true;
180 Progress::End 182 Progress::End
181 }; 183 };
182 self.report_progress( 184 self.report_progress(
@@ -233,13 +235,13 @@ impl GlobalState {
233 } 235 }
234 236
235 let state_changed = self.process_changes(); 237 let state_changed = self.process_changes();
236 if became_ready { 238 if prev_status == Status::Loading && self.status == Status::Ready {
237 if let Some(flycheck) = &self.flycheck { 239 if let Some(flycheck) = &self.flycheck {
238 flycheck.handle.update(); 240 flycheck.handle.update();
239 } 241 }
240 } 242 }
241 243
242 if self.status == Status::Ready && (state_changed || became_ready) { 244 if self.status == Status::Ready && (state_changed || prev_status == Status::Loading) {
243 let subscriptions = self 245 let subscriptions = self
244 .mem_docs 246 .mem_docs
245 .iter() 247 .iter()
@@ -276,7 +278,7 @@ impl GlobalState {
276 self.register_request(&req, request_received); 278 self.register_request(&req, request_received);
277 279
278 RequestDispatcher { req: Some(req), global_state: self } 280 RequestDispatcher { req: Some(req), global_state: self }
279 .on_sync::<lsp_ext::CollectGarbage>(|s, ()| Ok(s.analysis_host.collect_garbage()))? 281 .on_sync::<lsp_ext::ReloadWorkspace>(|s, ()| Ok(s.reload()))?
280 .on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))? 282 .on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))?
281 .on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))? 283 .on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))?
282 .on_sync::<lsp_types::request::Shutdown>(|_, ()| Ok(()))? 284 .on_sync::<lsp_types::request::Shutdown>(|_, ()| Ok(()))?
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index ec71f8b29..0c1fd1b8b 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -19,11 +19,14 @@ impl GlobalState {
19 if self.config.lru_capacity != old_config.lru_capacity { 19 if self.config.lru_capacity != old_config.lru_capacity {
20 self.analysis_host.update_lru_capacity(old_config.lru_capacity); 20 self.analysis_host.update_lru_capacity(old_config.lru_capacity);
21 } 21 }
22 if self.config.flycheck != old_config.flycheck { 22 if self.config.linked_projects != old_config.linked_projects {
23 self.reload()
24 } else if self.config.flycheck != old_config.flycheck {
23 self.reload_flycheck(); 25 self.reload_flycheck();
24 } 26 }
25 } 27 }
26 pub(crate) fn reload(&mut self) { 28 pub(crate) fn reload(&mut self) {
29 log::info!("reloading projects: {:?}", self.config.linked_projects);
27 let workspaces = { 30 let workspaces = {
28 if self.config.linked_projects.is_empty() 31 if self.config.linked_projects.is_empty()
29 && self.config.notifications.cargo_toml_not_found 32 && self.config.notifications.cargo_toml_not_found
diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md
index a0847dad3..c0afb16d3 100644
--- a/docs/dev/lsp-extensions.md
+++ b/docs/dev/lsp-extensions.md
@@ -389,15 +389,15 @@ rust-analyzer supports only one `kind`, `"cargo"`. The `args` for `"cargo"` look
389 389
390Returns internal status message, mostly for debugging purposes. 390Returns internal status message, mostly for debugging purposes.
391 391
392## Collect Garbage 392## Reload Workspace
393 393
394**Method:** `rust-analyzer/collectGarbage` 394**Method:** `rust-analyzer/reloadWorkspace`
395 395
396**Request:** `null` 396**Request:** `null`
397 397
398**Response:** `null` 398**Response:** `null`
399 399
400Frees some caches. For internal use, and is mostly broken at the moment. 400Reloads project information (that is, re-executes `cargo metadata`).
401 401
402## Syntax Tree 402## Syntax Tree
403 403
@@ -504,4 +504,4 @@ Such actions on the client side are appended to a hover bottom as command links:
504 | TITLE _Action1_ | _Action2_ | <- second group 504 | TITLE _Action1_ | _Action2_ | <- second group
505 +-----------------------------+ 505 +-----------------------------+
506 ... 506 ...
507``` \ No newline at end of file 507```
diff --git a/editors/code/package.json b/editors/code/package.json
index fcb101fc6..af0a5c851 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -61,7 +61,7 @@
61 "activationEvents": [ 61 "activationEvents": [
62 "onLanguage:rust", 62 "onLanguage:rust",
63 "onCommand:rust-analyzer.analyzerStatus", 63 "onCommand:rust-analyzer.analyzerStatus",
64 "onCommand:rust-analyzer.collectGarbage", 64 "onCommand:rust-analyzer.reloadWorkspace",
65 "workspaceContains:**/Cargo.toml" 65 "workspaceContains:**/Cargo.toml"
66 ], 66 ],
67 "main": "./out/src/main", 67 "main": "./out/src/main",
@@ -143,8 +143,8 @@
143 "category": "Rust Analyzer" 143 "category": "Rust Analyzer"
144 }, 144 },
145 { 145 {
146 "command": "rust-analyzer.collectGarbage", 146 "command": "rust-analyzer.reloadWorkspace",
147 "title": "Run garbage collection", 147 "title": "Reload workspace",
148 "category": "Rust Analyzer" 148 "category": "Rust Analyzer"
149 }, 149 },
150 { 150 {
@@ -815,7 +815,7 @@
815 "when": "inRustProject" 815 "when": "inRustProject"
816 }, 816 },
817 { 817 {
818 "command": "rust-analyzer.collectGarbage", 818 "command": "rust-analyzer.reloadWorkspace",
819 "when": "inRustProject" 819 "when": "inRustProject"
820 }, 820 },
821 { 821 {
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index 0e78f5101..19a9c2a0d 100644
--- a/editors/code/src/commands.ts
+++ b/editors/code/src/commands.ts
@@ -330,8 +330,8 @@ export function expandMacro(ctx: Ctx): Cmd {
330 }; 330 };
331} 331}
332 332
333export function collectGarbage(ctx: Ctx): Cmd { 333export function reloadWorkspace(ctx: Ctx): Cmd {
334 return async () => ctx.client.sendRequest(ra.collectGarbage, null); 334 return async () => ctx.client.sendRequest(ra.reloadWorkspace, null);
335} 335}
336 336
337export function showReferences(ctx: Ctx): Cmd { 337export function showReferences(ctx: Ctx): Cmd {
diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts
index fdb99956b..981b6f40e 100644
--- a/editors/code/src/lsp_ext.ts
+++ b/editors/code/src/lsp_ext.ts
@@ -6,7 +6,7 @@ import * as lc from "vscode-languageclient";
6 6
7export const analyzerStatus = new lc.RequestType<null, string, void>("rust-analyzer/analyzerStatus"); 7export const analyzerStatus = new lc.RequestType<null, string, void>("rust-analyzer/analyzerStatus");
8 8
9export const collectGarbage = new lc.RequestType<null, null, void>("rust-analyzer/collectGarbage"); 9export const reloadWorkspace = new lc.RequestType<null, null, void>("rust-analyzer/reloadWorkspace");
10 10
11export interface SyntaxTreeParams { 11export interface SyntaxTreeParams {
12 textDocument: lc.TextDocumentIdentifier; 12 textDocument: lc.TextDocumentIdentifier;
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 5ceab8b44..2982b9cbf 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -88,7 +88,7 @@ export async function activate(context: vscode.ExtensionContext) {
88 }); 88 });
89 89
90 ctx.registerCommand('analyzerStatus', commands.analyzerStatus); 90 ctx.registerCommand('analyzerStatus', commands.analyzerStatus);
91 ctx.registerCommand('collectGarbage', commands.collectGarbage); 91 ctx.registerCommand('reloadWorkspace', commands.reloadWorkspace);
92 ctx.registerCommand('matchingBrace', commands.matchingBrace); 92 ctx.registerCommand('matchingBrace', commands.matchingBrace);
93 ctx.registerCommand('joinLines', commands.joinLines); 93 ctx.registerCommand('joinLines', commands.joinLines);
94 ctx.registerCommand('parentModule', commands.parentModule); 94 ctx.registerCommand('parentModule', commands.parentModule);