diff options
Diffstat (limited to 'crates/ide/src/lib.rs')
-rw-r--r-- | crates/ide/src/lib.rs | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index eb6389529..b762c994e 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs | |||
@@ -44,7 +44,7 @@ mod syntax_highlighting; | |||
44 | mod syntax_tree; | 44 | mod syntax_tree; |
45 | mod typing; | 45 | mod typing; |
46 | 46 | ||
47 | use std::sync::Arc; | 47 | use std::{collections::HashSet, sync::Arc}; |
48 | 48 | ||
49 | use base_db::{ | 49 | use base_db::{ |
50 | salsa::{self, ParallelDatabase}, | 50 | salsa::{self, ParallelDatabase}, |
@@ -99,8 +99,15 @@ pub use text_edit::{Indel, TextEdit}; | |||
99 | 99 | ||
100 | pub type Cancelable<T> = Result<T, Canceled>; | 100 | pub type Cancelable<T> = Result<T, Canceled>; |
101 | 101 | ||
102 | /// Configuration parameters for the analysis run. | ||
103 | #[derive(Debug, Default, Clone)] | ||
104 | pub struct AnalysisConfig { | ||
105 | pub disabled_diagnostics: HashSet<String>, | ||
106 | } | ||
107 | |||
102 | #[derive(Debug)] | 108 | #[derive(Debug)] |
103 | pub struct Diagnostic { | 109 | pub struct Diagnostic { |
110 | pub name: Option<String>, | ||
104 | pub message: String, | 111 | pub message: String, |
105 | pub range: TextRange, | 112 | pub range: TextRange, |
106 | pub severity: Severity, | 113 | pub severity: Severity, |
@@ -144,11 +151,16 @@ impl<T> RangeInfo<T> { | |||
144 | #[derive(Debug)] | 151 | #[derive(Debug)] |
145 | pub struct AnalysisHost { | 152 | pub struct AnalysisHost { |
146 | db: RootDatabase, | 153 | db: RootDatabase, |
154 | config: AnalysisConfig, | ||
147 | } | 155 | } |
148 | 156 | ||
149 | impl AnalysisHost { | 157 | impl AnalysisHost { |
150 | pub fn new(lru_capacity: Option<usize>) -> AnalysisHost { | 158 | pub fn new(lru_capacity: Option<usize>) -> Self { |
151 | AnalysisHost { db: RootDatabase::new(lru_capacity) } | 159 | Self::with_config(lru_capacity, AnalysisConfig::default()) |
160 | } | ||
161 | |||
162 | pub fn with_config(lru_capacity: Option<usize>, config: AnalysisConfig) -> Self { | ||
163 | AnalysisHost { db: RootDatabase::new(lru_capacity), config } | ||
152 | } | 164 | } |
153 | 165 | ||
154 | pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) { | 166 | pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) { |
@@ -158,7 +170,7 @@ impl AnalysisHost { | |||
158 | /// Returns a snapshot of the current state, which you can query for | 170 | /// Returns a snapshot of the current state, which you can query for |
159 | /// semantic information. | 171 | /// semantic information. |
160 | pub fn analysis(&self) -> Analysis { | 172 | pub fn analysis(&self) -> Analysis { |
161 | Analysis { db: self.db.snapshot() } | 173 | Analysis { db: self.db.snapshot(), config: self.config.clone() } |
162 | } | 174 | } |
163 | 175 | ||
164 | /// Applies changes to the current state of the world. If there are | 176 | /// Applies changes to the current state of the world. If there are |
@@ -202,6 +214,7 @@ impl Default for AnalysisHost { | |||
202 | #[derive(Debug)] | 214 | #[derive(Debug)] |
203 | pub struct Analysis { | 215 | pub struct Analysis { |
204 | db: salsa::Snapshot<RootDatabase>, | 216 | db: salsa::Snapshot<RootDatabase>, |
217 | config: AnalysisConfig, | ||
205 | } | 218 | } |
206 | 219 | ||
207 | // As a general design guideline, `Analysis` API are intended to be independent | 220 | // As a general design guideline, `Analysis` API are intended to be independent |
@@ -497,7 +510,7 @@ impl Analysis { | |||
497 | file_id: FileId, | 510 | file_id: FileId, |
498 | enable_experimental: bool, | 511 | enable_experimental: bool, |
499 | ) -> Cancelable<Vec<Diagnostic>> { | 512 | ) -> Cancelable<Vec<Diagnostic>> { |
500 | self.with_db(|db| diagnostics::diagnostics(db, file_id, enable_experimental)) | 513 | self.with_db(|db| diagnostics::diagnostics(db, file_id, enable_experimental, &self.config)) |
501 | } | 514 | } |
502 | 515 | ||
503 | /// Returns the edit required to rename reference at the position to the new | 516 | /// Returns the edit required to rename reference at the position to the new |
@@ -526,6 +539,11 @@ impl Analysis { | |||
526 | }) | 539 | }) |
527 | } | 540 | } |
528 | 541 | ||
542 | /// Sets the provided config. | ||
543 | pub fn set_config(&mut self, config: AnalysisConfig) { | ||
544 | self.config = config; | ||
545 | } | ||
546 | |||
529 | /// Performs an operation on that may be Canceled. | 547 | /// Performs an operation on that may be Canceled. |
530 | fn with_db<F, T>(&self, f: F) -> Cancelable<T> | 548 | fn with_db<F, T>(&self, f: F) -> Cancelable<T> |
531 | where | 549 | where |