aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/lib.rs
diff options
context:
space:
mode:
authorIgor Aleksanov <[email protected]>2020-08-07 12:25:55 +0100
committerIgor Aleksanov <[email protected]>2020-08-07 12:25:55 +0100
commit90857ff8b08d73945598bac12a841559e86402b1 (patch)
tree8e98c8d7a1b50d55dbbbf788cda94b11eb3e3395 /crates/ra_ide/src/lib.rs
parentc463d217a1e001abe6a812f309d93527e28a70c6 (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.rs28
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;
45mod syntax_tree; 45mod syntax_tree;
46mod typing; 46mod typing;
47 47
48use std::sync::Arc; 48use std::{collections::HashSet, sync::Arc};
49 49
50use ra_cfg::CfgOptions; 50use ra_cfg::CfgOptions;
51use ra_db::{ 51use ra_db::{
@@ -100,8 +100,15 @@ pub use ra_text_edit::{Indel, TextEdit};
100 100
101pub type Cancelable<T> = Result<T, Canceled>; 101pub type Cancelable<T> = Result<T, Canceled>;
102 102
103/// Configuration parameters for the analysis run.
104#[derive(Debug, Default, Clone)]
105pub struct AnalysisConfig {
106 pub disabled_diagnostics: HashSet<String>,
107}
108
103#[derive(Debug)] 109#[derive(Debug)]
104pub struct Diagnostic { 110pub 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)]
140pub struct AnalysisHost { 147pub struct AnalysisHost {
141 db: RootDatabase, 148 db: RootDatabase,
149 config: AnalysisConfig,
142} 150}
143 151
144impl AnalysisHost { 152impl 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)]
198pub struct Analysis { 210pub 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,