diff options
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 89fcb6f17..2cbd7e4f0 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, |
@@ -145,11 +152,16 @@ impl<T> RangeInfo<T> { | |||
145 | #[derive(Debug)] | 152 | #[derive(Debug)] |
146 | pub struct AnalysisHost { | 153 | pub struct AnalysisHost { |
147 | db: RootDatabase, | 154 | db: RootDatabase, |
155 | config: AnalysisConfig, | ||
148 | } | 156 | } |
149 | 157 | ||
150 | impl AnalysisHost { | 158 | impl AnalysisHost { |
151 | pub fn new(lru_capacity: Option<usize>) -> AnalysisHost { | 159 | pub fn new(lru_capacity: Option<usize>) -> Self { |
152 | AnalysisHost { db: RootDatabase::new(lru_capacity) } | 160 | Self::with_config(lru_capacity, AnalysisConfig::default()) |
161 | } | ||
162 | |||
163 | pub fn with_config(lru_capacity: Option<usize>, config: AnalysisConfig) -> Self { | ||
164 | AnalysisHost { db: RootDatabase::new(lru_capacity), config } | ||
153 | } | 165 | } |
154 | 166 | ||
155 | pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) { | 167 | pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) { |
@@ -159,7 +171,7 @@ impl AnalysisHost { | |||
159 | /// Returns a snapshot of the current state, which you can query for | 171 | /// Returns a snapshot of the current state, which you can query for |
160 | /// semantic information. | 172 | /// semantic information. |
161 | pub fn analysis(&self) -> Analysis { | 173 | pub fn analysis(&self) -> Analysis { |
162 | Analysis { db: self.db.snapshot() } | 174 | Analysis { db: self.db.snapshot(), config: self.config.clone() } |
163 | } | 175 | } |
164 | 176 | ||
165 | /// Applies changes to the current state of the world. If there are | 177 | /// Applies changes to the current state of the world. If there are |
@@ -203,6 +215,7 @@ impl Default for AnalysisHost { | |||
203 | #[derive(Debug)] | 215 | #[derive(Debug)] |
204 | pub struct Analysis { | 216 | pub struct Analysis { |
205 | db: salsa::Snapshot<RootDatabase>, | 217 | db: salsa::Snapshot<RootDatabase>, |
218 | config: AnalysisConfig, | ||
206 | } | 219 | } |
207 | 220 | ||
208 | // As a general design guideline, `Analysis` API are intended to be independent | 221 | // As a general design guideline, `Analysis` API are intended to be independent |
@@ -498,7 +511,7 @@ impl Analysis { | |||
498 | file_id: FileId, | 511 | file_id: FileId, |
499 | enable_experimental: bool, | 512 | enable_experimental: bool, |
500 | ) -> Cancelable<Vec<Diagnostic>> { | 513 | ) -> Cancelable<Vec<Diagnostic>> { |
501 | self.with_db(|db| diagnostics::diagnostics(db, file_id, enable_experimental)) | 514 | self.with_db(|db| diagnostics::diagnostics(db, file_id, enable_experimental, &self.config)) |
502 | } | 515 | } |
503 | 516 | ||
504 | /// Returns the edit required to rename reference at the position to the new | 517 | /// Returns the edit required to rename reference at the position to the new |
@@ -524,6 +537,11 @@ impl Analysis { | |||
524 | }) | 537 | }) |
525 | } | 538 | } |
526 | 539 | ||
540 | /// Sets the provided config. | ||
541 | pub fn set_config(&mut self, config: AnalysisConfig) { | ||
542 | self.config = config; | ||
543 | } | ||
544 | |||
527 | /// Performs an operation on that may be Canceled. | 545 | /// Performs an operation on that may be Canceled. |
528 | fn with_db<F: FnOnce(&RootDatabase) -> T + std::panic::UnwindSafe, T>( | 546 | fn with_db<F: FnOnce(&RootDatabase) -> T + std::panic::UnwindSafe, T>( |
529 | &self, | 547 | &self, |