diff options
-rw-r--r-- | Cargo.lock | 4 | ||||
-rw-r--r-- | crates/ra_flycheck/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_def/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_hir_ty/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_ide/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/bin/args.rs | 39 | ||||
-rw-r--r-- | crates/rust-analyzer/src/bin/main.rs | 4 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli.rs | 8 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/diagnostics.rs | 74 | ||||
-rw-r--r-- | editors/code/package-lock.json | 36 | ||||
-rw-r--r-- | editors/code/package.json | 4 |
12 files changed, 153 insertions, 30 deletions
diff --git a/Cargo.lock b/Cargo.lock index 975c1aef8..18d6c9d6a 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -495,9 +495,9 @@ dependencies = [ | |||
495 | 495 | ||
496 | [[package]] | 496 | [[package]] |
497 | name = "insta" | 497 | name = "insta" |
498 | version = "0.15.0" | 498 | version = "0.16.0" |
499 | source = "registry+https://github.com/rust-lang/crates.io-index" | 499 | source = "registry+https://github.com/rust-lang/crates.io-index" |
500 | checksum = "8de3f029212a3fe78a6090f1f2b993877ca245a9ded863f3fcbd6eae084fc1ed" | 500 | checksum = "8386e795fb3927131ea4cede203c529a333652eb6dc4ff29616b832b27e9b096" |
501 | dependencies = [ | 501 | dependencies = [ |
502 | "console", | 502 | "console", |
503 | "difference", | 503 | "difference", |
diff --git a/crates/ra_flycheck/Cargo.toml b/crates/ra_flycheck/Cargo.toml index c9a9ddc12..76e5cada4 100644 --- a/crates/ra_flycheck/Cargo.toml +++ b/crates/ra_flycheck/Cargo.toml | |||
@@ -13,4 +13,4 @@ serde_json = "1.0.48" | |||
13 | jod-thread = "0.1.1" | 13 | jod-thread = "0.1.1" |
14 | 14 | ||
15 | [dev-dependencies] | 15 | [dev-dependencies] |
16 | insta = "0.15.0" | 16 | insta = "0.16.0" |
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 9baebf643..3801fce23 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -25,7 +25,7 @@ use hir_ty::{ | |||
25 | autoderef, display::HirFormatter, expr::ExprValidator, method_resolution, ApplicationTy, | 25 | autoderef, display::HirFormatter, expr::ExprValidator, method_resolution, ApplicationTy, |
26 | Canonical, InEnvironment, Substs, TraitEnvironment, Ty, TyDefId, TypeCtor, | 26 | Canonical, InEnvironment, Substs, TraitEnvironment, Ty, TyDefId, TypeCtor, |
27 | }; | 27 | }; |
28 | use ra_db::{CrateId, Edition, FileId}; | 28 | use ra_db::{CrateId, CrateName, Edition, FileId}; |
29 | use ra_prof::profile; | 29 | use ra_prof::profile; |
30 | use ra_syntax::{ | 30 | use ra_syntax::{ |
31 | ast::{self, AttrsOwner, NameOwner}, | 31 | ast::{self, AttrsOwner, NameOwner}, |
@@ -91,6 +91,10 @@ impl Crate { | |||
91 | db.crate_graph()[self.id].edition | 91 | db.crate_graph()[self.id].edition |
92 | } | 92 | } |
93 | 93 | ||
94 | pub fn display_name(self, db: &dyn HirDatabase) -> Option<CrateName> { | ||
95 | db.crate_graph()[self.id].display_name.as_ref().cloned() | ||
96 | } | ||
97 | |||
94 | pub fn all(db: &dyn HirDatabase) -> Vec<Crate> { | 98 | pub fn all(db: &dyn HirDatabase) -> Vec<Crate> { |
95 | db.crate_graph().iter().map(|id| Crate { id }).collect() | 99 | db.crate_graph().iter().map(|id| Crate { id }).collect() |
96 | } | 100 | } |
diff --git a/crates/ra_hir_def/Cargo.toml b/crates/ra_hir_def/Cargo.toml index 56e791e3e..b85358308 100644 --- a/crates/ra_hir_def/Cargo.toml +++ b/crates/ra_hir_def/Cargo.toml | |||
@@ -28,4 +28,4 @@ ra_cfg = { path = "../ra_cfg" } | |||
28 | tt = { path = "../ra_tt", package = "ra_tt" } | 28 | tt = { path = "../ra_tt", package = "ra_tt" } |
29 | 29 | ||
30 | [dev-dependencies] | 30 | [dev-dependencies] |
31 | insta = "0.15.0" | 31 | insta = "0.16.0" |
diff --git a/crates/ra_hir_ty/Cargo.toml b/crates/ra_hir_ty/Cargo.toml index 59efc1c31..cbaf50dd5 100644 --- a/crates/ra_hir_ty/Cargo.toml +++ b/crates/ra_hir_ty/Cargo.toml | |||
@@ -31,4 +31,4 @@ chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "039fc90 | |||
31 | chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "039fc904a05f8cb3d0c682c9a57a63dda7a35356" } | 31 | chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "039fc904a05f8cb3d0c682c9a57a63dda7a35356" } |
32 | 32 | ||
33 | [dev-dependencies] | 33 | [dev-dependencies] |
34 | insta = "0.15.0" | 34 | insta = "0.16.0" |
diff --git a/crates/ra_ide/Cargo.toml b/crates/ra_ide/Cargo.toml index b4a29b81b..05c940605 100644 --- a/crates/ra_ide/Cargo.toml +++ b/crates/ra_ide/Cargo.toml | |||
@@ -35,4 +35,4 @@ ra_assists = { path = "../ra_assists" } | |||
35 | hir = { path = "../ra_hir", package = "ra_hir" } | 35 | hir = { path = "../ra_hir", package = "ra_hir" } |
36 | 36 | ||
37 | [dev-dependencies] | 37 | [dev-dependencies] |
38 | insta = "0.15.0" | 38 | insta = "0.16.0" |
diff --git a/crates/rust-analyzer/src/bin/args.rs b/crates/rust-analyzer/src/bin/args.rs index 3cf394bb4..f5981588a 100644 --- a/crates/rust-analyzer/src/bin/args.rs +++ b/crates/rust-analyzer/src/bin/args.rs | |||
@@ -35,6 +35,13 @@ pub(crate) enum Command { | |||
35 | what: BenchWhat, | 35 | what: BenchWhat, |
36 | load_output_dirs: bool, | 36 | load_output_dirs: bool, |
37 | }, | 37 | }, |
38 | Diagnostics { | ||
39 | path: PathBuf, | ||
40 | load_output_dirs: bool, | ||
41 | /// Include files which are not modules. In rust-analyzer | ||
42 | /// this would include the parser test files. | ||
43 | all: bool, | ||
44 | }, | ||
38 | RunServer, | 45 | RunServer, |
39 | Version, | 46 | Version, |
40 | } | 47 | } |
@@ -209,6 +216,38 @@ ARGS: | |||
209 | let load_output_dirs = matches.contains("--load-output-dirs"); | 216 | let load_output_dirs = matches.contains("--load-output-dirs"); |
210 | Command::Bench { path, what, load_output_dirs } | 217 | Command::Bench { path, what, load_output_dirs } |
211 | } | 218 | } |
219 | "diagnostics" => { | ||
220 | if matches.contains(["-h", "--help"]) { | ||
221 | eprintln!( | ||
222 | "\ | ||
223 | ra-cli-diagnostics | ||
224 | |||
225 | USAGE: | ||
226 | rust-analyzer diagnostics [FLAGS] [PATH] | ||
227 | |||
228 | FLAGS: | ||
229 | -h, --help Prints help information | ||
230 | --load-output-dirs Load OUT_DIR values by running `cargo check` before analysis | ||
231 | --all Include all files rather than only modules | ||
232 | |||
233 | ARGS: | ||
234 | <PATH>" | ||
235 | ); | ||
236 | return Ok(Err(HelpPrinted)); | ||
237 | } | ||
238 | |||
239 | let load_output_dirs = matches.contains("--load-output-dirs"); | ||
240 | let all = matches.contains("--all"); | ||
241 | let path = { | ||
242 | let mut trailing = matches.free()?; | ||
243 | if trailing.len() != 1 { | ||
244 | bail!("Invalid flags"); | ||
245 | } | ||
246 | trailing.pop().unwrap().into() | ||
247 | }; | ||
248 | |||
249 | Command::Diagnostics { path, load_output_dirs, all } | ||
250 | } | ||
212 | _ => { | 251 | _ => { |
213 | eprintln!( | 252 | eprintln!( |
214 | "\ | 253 | "\ |
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index 608f4f67b..7cfc44f01 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs | |||
@@ -39,6 +39,10 @@ fn main() -> Result<()> { | |||
39 | cli::analysis_bench(args.verbosity, path.as_ref(), what, load_output_dirs)? | 39 | cli::analysis_bench(args.verbosity, path.as_ref(), what, load_output_dirs)? |
40 | } | 40 | } |
41 | 41 | ||
42 | args::Command::Diagnostics { path, load_output_dirs, all } => { | ||
43 | cli::diagnostics(path.as_ref(), load_output_dirs, all)? | ||
44 | } | ||
45 | |||
42 | args::Command::RunServer => run_server()?, | 46 | args::Command::RunServer => run_server()?, |
43 | args::Command::Version => println!("rust-analyzer {}", env!("REV")), | 47 | args::Command::Version => println!("rust-analyzer {}", env!("REV")), |
44 | } | 48 | } |
diff --git a/crates/rust-analyzer/src/cli.rs b/crates/rust-analyzer/src/cli.rs index c9738d101..a865a7c7e 100644 --- a/crates/rust-analyzer/src/cli.rs +++ b/crates/rust-analyzer/src/cli.rs | |||
@@ -3,6 +3,7 @@ | |||
3 | mod load_cargo; | 3 | mod load_cargo; |
4 | mod analysis_stats; | 4 | mod analysis_stats; |
5 | mod analysis_bench; | 5 | mod analysis_bench; |
6 | mod diagnostics; | ||
6 | mod progress_report; | 7 | mod progress_report; |
7 | 8 | ||
8 | use std::io::Read; | 9 | use std::io::Read; |
@@ -12,6 +13,10 @@ use ra_ide::{file_structure, Analysis}; | |||
12 | use ra_prof::profile; | 13 | use ra_prof::profile; |
13 | use ra_syntax::{AstNode, SourceFile}; | 14 | use ra_syntax::{AstNode, SourceFile}; |
14 | 15 | ||
16 | pub use analysis_bench::{analysis_bench, BenchWhat, Position}; | ||
17 | pub use analysis_stats::analysis_stats; | ||
18 | pub use diagnostics::diagnostics; | ||
19 | |||
15 | #[derive(Clone, Copy)] | 20 | #[derive(Clone, Copy)] |
16 | pub enum Verbosity { | 21 | pub enum Verbosity { |
17 | Spammy, | 22 | Spammy, |
@@ -60,9 +65,6 @@ pub fn highlight(rainbow: bool) -> Result<()> { | |||
60 | Ok(()) | 65 | Ok(()) |
61 | } | 66 | } |
62 | 67 | ||
63 | pub use analysis_bench::{analysis_bench, BenchWhat, Position}; | ||
64 | pub use analysis_stats::analysis_stats; | ||
65 | |||
66 | fn file() -> Result<SourceFile> { | 68 | fn file() -> Result<SourceFile> { |
67 | let text = read_stdin()?; | 69 | let text = read_stdin()?; |
68 | Ok(SourceFile::parse(&text).tree()) | 70 | Ok(SourceFile::parse(&text).tree()) |
diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs new file mode 100644 index 000000000..92664b415 --- /dev/null +++ b/crates/rust-analyzer/src/cli/diagnostics.rs | |||
@@ -0,0 +1,74 @@ | |||
1 | //! Analyze all modules in a project for diagnostics. Exits with a non-zero status | ||
2 | //! code if any errors are found. | ||
3 | |||
4 | use anyhow::anyhow; | ||
5 | use ra_db::SourceDatabaseExt; | ||
6 | use ra_ide::Severity; | ||
7 | use std::{collections::HashSet, path::Path}; | ||
8 | |||
9 | use crate::cli::{load_cargo::load_cargo, Result}; | ||
10 | use hir::Semantics; | ||
11 | |||
12 | pub fn diagnostics(path: &Path, load_output_dirs: bool, all: bool) -> Result<()> { | ||
13 | let (host, roots) = load_cargo(path, load_output_dirs)?; | ||
14 | let db = host.raw_database(); | ||
15 | let analysis = host.analysis(); | ||
16 | let semantics = Semantics::new(db); | ||
17 | let members = roots | ||
18 | .into_iter() | ||
19 | .filter_map(|(source_root_id, project_root)| { | ||
20 | // filter out dependencies | ||
21 | if project_root.is_member() { | ||
22 | Some(source_root_id) | ||
23 | } else { | ||
24 | None | ||
25 | } | ||
26 | }) | ||
27 | .collect::<HashSet<_>>(); | ||
28 | |||
29 | let mut found_error = false; | ||
30 | let mut visited_files = HashSet::new(); | ||
31 | for source_root_id in members { | ||
32 | for file_id in db.source_root(source_root_id).walk() { | ||
33 | // Filter out files which are not actually modules (unless `--all` flag is | ||
34 | // passed). In the rust-analyzer repository this filters out the parser test files. | ||
35 | if semantics.to_module_def(file_id).is_some() || all { | ||
36 | if !visited_files.contains(&file_id) { | ||
37 | let crate_name = if let Some(module) = semantics.to_module_def(file_id) { | ||
38 | if let Some(name) = module.krate().display_name(db) { | ||
39 | format!("{}", name) | ||
40 | } else { | ||
41 | String::from("unknown") | ||
42 | } | ||
43 | } else { | ||
44 | String::from("unknown") | ||
45 | }; | ||
46 | println!( | ||
47 | "processing crate: {}, module: {}", | ||
48 | crate_name, | ||
49 | db.file_relative_path(file_id) | ||
50 | ); | ||
51 | for diagnostic in analysis.diagnostics(file_id).unwrap() { | ||
52 | if matches!(diagnostic.severity, Severity::Error) { | ||
53 | found_error = true; | ||
54 | } | ||
55 | |||
56 | println!("{:?}", diagnostic); | ||
57 | } | ||
58 | |||
59 | visited_files.insert(file_id); | ||
60 | } | ||
61 | } | ||
62 | } | ||
63 | } | ||
64 | |||
65 | println!(); | ||
66 | println!("diagnostic scan complete"); | ||
67 | |||
68 | if found_error { | ||
69 | println!(); | ||
70 | Err(anyhow!("diagnostic error detected")) | ||
71 | } else { | ||
72 | Ok(()) | ||
73 | } | ||
74 | } | ||
diff --git a/editors/code/package-lock.json b/editors/code/package-lock.json index eb4f299a1..e11cffd68 100644 --- a/editors/code/package-lock.json +++ b/editors/code/package-lock.json | |||
@@ -109,9 +109,9 @@ | |||
109 | } | 109 | } |
110 | }, | 110 | }, |
111 | "@types/vscode": { | 111 | "@types/vscode": { |
112 | "version": "1.43.0", | 112 | "version": "1.44.0", |
113 | "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.43.0.tgz", | 113 | "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.44.0.tgz", |
114 | "integrity": "sha512-kIaR9qzd80rJOxePKpCB/mdy00mz8Apt2QA5Y6rdrKFn13QNFNeP3Hzmsf37Bwh/3cS7QjtAeGSK7wSqAU0sYQ==", | 114 | "integrity": "sha512-WJZtZlinE3meRdH+I7wTsIhpz/GLhqEQwmPGeh4s1irWLwMzCeTV8WZ+pgPTwrDXoafVUWwo1LiZ9HJVHFlJSQ==", |
115 | "dev": true | 115 | "dev": true |
116 | }, | 116 | }, |
117 | "@typescript-eslint/eslint-plugin": { | 117 | "@typescript-eslint/eslint-plugin": { |
@@ -1776,32 +1776,32 @@ | |||
1776 | } | 1776 | } |
1777 | }, | 1777 | }, |
1778 | "vscode-jsonrpc": { | 1778 | "vscode-jsonrpc": { |
1779 | "version": "5.0.1", | 1779 | "version": "5.1.0-next.1", |
1780 | "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-5.0.1.tgz", | 1780 | "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-5.1.0-next.1.tgz", |
1781 | "integrity": "sha512-JvONPptw3GAQGXlVV2utDcHx0BiY34FupW/kI6mZ5x06ER5DdPG/tXWMVHjTNULF5uKPOUUD0SaXg5QaubJL0A==" | 1781 | "integrity": "sha512-mwLDojZkbmpizSJSmp690oa9FB9jig18SIDGZeBCvFc2/LYSRvMm/WwWtMBJuJ1MfFh7rZXfQige4Uje5Z9NzA==" |
1782 | }, | 1782 | }, |
1783 | "vscode-languageclient": { | 1783 | "vscode-languageclient": { |
1784 | "version": "6.1.3", | 1784 | "version": "7.0.0-next.1", |
1785 | "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-6.1.3.tgz", | 1785 | "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-7.0.0-next.1.tgz", |
1786 | "integrity": "sha512-YciJxk08iU5LmWu7j5dUt9/1OLjokKET6rME3cI4BRpiF6HZlusm2ZwPt0MYJ0lV5y43sZsQHhyon2xBg4ZJVA==", | 1786 | "integrity": "sha512-JrjCUhLpQZxQ5VpWpilOHDMhVsn0fdN5jBh1uFNhSr5c2loJvRdr9Km2EuSQOFfOQsBKx0+xvY8PbsypNEcJ6w==", |
1787 | "requires": { | 1787 | "requires": { |
1788 | "semver": "^6.3.0", | 1788 | "semver": "^6.3.0", |
1789 | "vscode-languageserver-protocol": "^3.15.3" | 1789 | "vscode-languageserver-protocol": "3.16.0-next.2" |
1790 | } | 1790 | } |
1791 | }, | 1791 | }, |
1792 | "vscode-languageserver-protocol": { | 1792 | "vscode-languageserver-protocol": { |
1793 | "version": "3.15.3", | 1793 | "version": "3.16.0-next.2", |
1794 | "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.15.3.tgz", | 1794 | "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.16.0-next.2.tgz", |
1795 | "integrity": "sha512-zrMuwHOAQRhjDSnflWdJG+O2ztMWss8GqUUB8dXLR/FPenwkiBNkMIJJYfSN6sgskvsF0rHAoBowNQfbyZnnvw==", | 1795 | "integrity": "sha512-atmkGT/W6tF0cx4SaWFYtFs2UeSeC28RPiap9myv2YZTaTCFvTBEPNWrU5QRKfkyM0tbgtGo6T3UCQ8tkDpjzA==", |
1796 | "requires": { | 1796 | "requires": { |
1797 | "vscode-jsonrpc": "^5.0.1", | 1797 | "vscode-jsonrpc": "5.1.0-next.1", |
1798 | "vscode-languageserver-types": "3.15.1" | 1798 | "vscode-languageserver-types": "3.16.0-next.1" |
1799 | } | 1799 | } |
1800 | }, | 1800 | }, |
1801 | "vscode-languageserver-types": { | 1801 | "vscode-languageserver-types": { |
1802 | "version": "3.15.1", | 1802 | "version": "3.16.0-next.1", |
1803 | "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.15.1.tgz", | 1803 | "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0-next.1.tgz", |
1804 | "integrity": "sha512-+a9MPUQrNGRrGU630OGbYVQ+11iOIovjCkqxajPa9w57Sd5ruK8WQNsslzpa0x/QJqC8kRc2DUxWjIFwoNm4ZQ==" | 1804 | "integrity": "sha512-tZFUSbyjUcrh+qQf13ALX4QDdOfDX0cVaBFgy7ktJ0VwS7AW/yRKgGPSxVqqP9OCMNPdqP57O5q47w2pEwfaUg==" |
1805 | }, | 1805 | }, |
1806 | "which": { | 1806 | "which": { |
1807 | "version": "1.3.1", | 1807 | "version": "1.3.1", |
diff --git a/editors/code/package.json b/editors/code/package.json index 0bf7b6ae6..33bd66b40 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -34,14 +34,14 @@ | |||
34 | "dependencies": { | 34 | "dependencies": { |
35 | "jsonc-parser": "^2.2.1", | 35 | "jsonc-parser": "^2.2.1", |
36 | "node-fetch": "^2.6.0", | 36 | "node-fetch": "^2.6.0", |
37 | "vscode-languageclient": "6.1.3" | 37 | "vscode-languageclient": "7.0.0-next.1" |
38 | }, | 38 | }, |
39 | "devDependencies": { | 39 | "devDependencies": { |
40 | "@rollup/plugin-commonjs": "^11.0.2", | 40 | "@rollup/plugin-commonjs": "^11.0.2", |
41 | "@rollup/plugin-node-resolve": "^7.1.1", | 41 | "@rollup/plugin-node-resolve": "^7.1.1", |
42 | "@types/node": "^12.12.34", | 42 | "@types/node": "^12.12.34", |
43 | "@types/node-fetch": "^2.5.5", | 43 | "@types/node-fetch": "^2.5.5", |
44 | "@types/vscode": "^1.43.0", | 44 | "@types/vscode": "^1.44.0", |
45 | "@typescript-eslint/eslint-plugin": "^2.27.0", | 45 | "@typescript-eslint/eslint-plugin": "^2.27.0", |
46 | "@typescript-eslint/parser": "^2.27.0", | 46 | "@typescript-eslint/parser": "^2.27.0", |
47 | "eslint": "^6.8.0", | 47 | "eslint": "^6.8.0", |