diff options
author | Igor Aleksanov <[email protected]> | 2020-08-07 12:25:55 +0100 |
---|---|---|
committer | Igor Aleksanov <[email protected]> | 2020-08-07 12:25:55 +0100 |
commit | 90857ff8b08d73945598bac12a841559e86402b1 (patch) | |
tree | 8e98c8d7a1b50d55dbbbf788cda94b11eb3e3395 /crates/ra_ide/src/lib.rs | |
parent | c463d217a1e001abe6a812f309d93527e28a70c6 (diff) |
Add an AnalysisConfig structure and use it to configure diagnostics run
Diffstat (limited to 'crates/ra_ide/src/lib.rs')
-rw-r--r-- | crates/ra_ide/src/lib.rs | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 0fede0d87..3822b9409 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -45,7 +45,7 @@ mod syntax_highlighting; | |||
45 | mod syntax_tree; | 45 | mod syntax_tree; |
46 | mod typing; | 46 | mod typing; |
47 | 47 | ||
48 | use std::sync::Arc; | 48 | use std::{collections::HashSet, sync::Arc}; |
49 | 49 | ||
50 | use ra_cfg::CfgOptions; | 50 | use ra_cfg::CfgOptions; |
51 | use ra_db::{ | 51 | use ra_db::{ |
@@ -100,8 +100,15 @@ pub use ra_text_edit::{Indel, TextEdit}; | |||
100 | 100 | ||
101 | pub type Cancelable<T> = Result<T, Canceled>; | 101 | pub type Cancelable<T> = Result<T, Canceled>; |
102 | 102 | ||
103 | /// Configuration parameters for the analysis run. | ||
104 | #[derive(Debug, Default, Clone)] | ||
105 | pub struct AnalysisConfig { | ||
106 | pub disabled_diagnostics: HashSet<String>, | ||
107 | } | ||
108 | |||
103 | #[derive(Debug)] | 109 | #[derive(Debug)] |
104 | pub struct Diagnostic { | 110 | pub struct Diagnostic { |
111 | pub name: Option<String>, | ||
105 | pub message: String, | 112 | pub message: String, |
106 | pub range: TextRange, | 113 | pub range: TextRange, |
107 | pub severity: Severity, | 114 | pub severity: Severity, |
@@ -139,11 +146,16 @@ impl<T> RangeInfo<T> { | |||
139 | #[derive(Debug)] | 146 | #[derive(Debug)] |
140 | pub struct AnalysisHost { | 147 | pub struct AnalysisHost { |
141 | db: RootDatabase, | 148 | db: RootDatabase, |
149 | config: AnalysisConfig, | ||
142 | } | 150 | } |
143 | 151 | ||
144 | impl AnalysisHost { | 152 | impl AnalysisHost { |
145 | pub fn new(lru_capacity: Option<usize>) -> AnalysisHost { | 153 | pub fn new(lru_capacity: Option<usize>) -> Self { |
146 | AnalysisHost { db: RootDatabase::new(lru_capacity) } | 154 | Self::with_config(lru_capacity, AnalysisConfig::default()) |
155 | } | ||
156 | |||
157 | pub fn with_config(lru_capacity: Option<usize>, config: AnalysisConfig) -> Self { | ||
158 | AnalysisHost { db: RootDatabase::new(lru_capacity), config } | ||
147 | } | 159 | } |
148 | 160 | ||
149 | pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) { | 161 | pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) { |
@@ -153,7 +165,7 @@ impl AnalysisHost { | |||
153 | /// Returns a snapshot of the current state, which you can query for | 165 | /// Returns a snapshot of the current state, which you can query for |
154 | /// semantic information. | 166 | /// semantic information. |
155 | pub fn analysis(&self) -> Analysis { | 167 | pub fn analysis(&self) -> Analysis { |
156 | Analysis { db: self.db.snapshot() } | 168 | Analysis { db: self.db.snapshot(), config: self.config.clone() } |
157 | } | 169 | } |
158 | 170 | ||
159 | /// Applies changes to the current state of the world. If there are | 171 | /// Applies changes to the current state of the world. If there are |
@@ -197,6 +209,7 @@ impl Default for AnalysisHost { | |||
197 | #[derive(Debug)] | 209 | #[derive(Debug)] |
198 | pub struct Analysis { | 210 | pub struct Analysis { |
199 | db: salsa::Snapshot<RootDatabase>, | 211 | db: salsa::Snapshot<RootDatabase>, |
212 | config: AnalysisConfig, | ||
200 | } | 213 | } |
201 | 214 | ||
202 | // As a general design guideline, `Analysis` API are intended to be independent | 215 | // As a general design guideline, `Analysis` API are intended to be independent |
@@ -492,7 +505,7 @@ impl Analysis { | |||
492 | file_id: FileId, | 505 | file_id: FileId, |
493 | enable_experimental: bool, | 506 | enable_experimental: bool, |
494 | ) -> Cancelable<Vec<Diagnostic>> { | 507 | ) -> Cancelable<Vec<Diagnostic>> { |
495 | self.with_db(|db| diagnostics::diagnostics(db, file_id, enable_experimental)) | 508 | self.with_db(|db| diagnostics::diagnostics(db, file_id, enable_experimental, &self.config)) |
496 | } | 509 | } |
497 | 510 | ||
498 | /// Returns the edit required to rename reference at the position to the new | 511 | /// Returns the edit required to rename reference at the position to the new |
@@ -518,6 +531,11 @@ impl Analysis { | |||
518 | }) | 531 | }) |
519 | } | 532 | } |
520 | 533 | ||
534 | /// Sets the provided config. | ||
535 | pub fn set_config(&mut self, config: AnalysisConfig) { | ||
536 | self.config = config; | ||
537 | } | ||
538 | |||
521 | /// Performs an operation on that may be Canceled. | 539 | /// Performs an operation on that may be Canceled. |
522 | fn with_db<F: FnOnce(&RootDatabase) -> T + std::panic::UnwindSafe, T>( | 540 | fn with_db<F: FnOnce(&RootDatabase) -> T + std::panic::UnwindSafe, T>( |
523 | &self, | 541 | &self, |