From d31634940dbe0b301fb9a99cbd4b8288c78f0e96 Mon Sep 17 00:00:00 2001 From: Dave Lage Date: Sat, 15 Aug 2020 16:37:44 -0400 Subject: Fix typo in comment --- crates/ide/src/inlay_hints.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ide/src') diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index 002adf915..596bc872d 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs @@ -43,7 +43,7 @@ pub struct InlayHint { // rust-analyzer shows additional information inline with the source code. // Editors usually render this using read-only virtual text snippets interspersed with code. // -// rust-analyzer shows hits for +// rust-analyzer shows hints for // // * types of local variables // * names of function arguments -- cgit v1.2.3 From b56cfcca10994ec2bf1878f222afdb375459f8d3 Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Tue, 18 Aug 2020 13:32:29 +0300 Subject: Make disabled diagnostics an argument of corresponding function --- crates/ide/src/diagnostics.rs | 36 ++++++++++++++++-------------------- crates/ide/src/lib.rs | 20 ++++++-------------- 2 files changed, 22 insertions(+), 34 deletions(-) (limited to 'crates/ide/src') diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index a54df37db..606a6064b 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs @@ -4,7 +4,7 @@ //! macro-expanded files, but we need to present them to the users in terms of //! original files. So we need to map the ranges. -use std::cell::RefCell; +use std::{cell::RefCell, collections::HashSet}; use base_db::SourceDatabase; use hir::{diagnostics::DiagnosticSinkBuilder, Semantics}; @@ -16,7 +16,7 @@ use syntax::{ }; use text_edit::TextEdit; -use crate::{AnalysisConfig, Diagnostic, FileId, Fix, SourceFileEdit}; +use crate::{Diagnostic, FileId, Fix, SourceFileEdit}; mod diagnostics_with_fix; use diagnostics_with_fix::DiagnosticWithFix; @@ -31,7 +31,7 @@ pub(crate) fn diagnostics( db: &RootDatabase, file_id: FileId, enable_experimental: bool, - analysis_config: &AnalysisConfig, + disabled_diagnostics: Option>, ) -> Vec { let _p = profile::span("diagnostics"); let sema = Semantics::new(db); @@ -68,10 +68,9 @@ pub(crate) fn diagnostics( // Only collect experimental diagnostics when they're enabled. .filter(|diag| !diag.is_experimental() || enable_experimental); - if !analysis_config.disabled_diagnostics.is_empty() { + if let Some(disabled_diagnostics) = disabled_diagnostics { // Do not collect disabled diagnostics. - sink_builder = - sink_builder.filter(|diag| !analysis_config.disabled_diagnostics.contains(diag.name())); + sink_builder = sink_builder.filter(move |diag| !disabled_diagnostics.contains(diag.name())); } // Finalize the `DiagnosticSink` building process. @@ -192,10 +191,7 @@ mod tests { use stdx::trim_indent; use test_utils::assert_eq_text; - use crate::{ - mock_analysis::{analysis_and_position, single_file, MockAnalysis}, - AnalysisConfig, - }; + use crate::mock_analysis::{analysis_and_position, single_file, MockAnalysis}; use expect::{expect, Expect}; /// Takes a multi-file input fixture with annotated cursor positions, @@ -207,7 +203,8 @@ mod tests { let after = trim_indent(ra_fixture_after); let (analysis, file_position) = analysis_and_position(ra_fixture_before); - let diagnostic = analysis.diagnostics(file_position.file_id, true).unwrap().pop().unwrap(); + let diagnostic = + analysis.diagnostics(file_position.file_id, true, None).unwrap().pop().unwrap(); let mut fix = diagnostic.fix.unwrap(); let edit = fix.source_change.source_file_edits.pop().unwrap().edit; let target_file_contents = analysis.file_text(file_position.file_id).unwrap(); @@ -233,7 +230,7 @@ mod tests { let ra_fixture_after = &trim_indent(ra_fixture_after); let (analysis, file_pos) = analysis_and_position(ra_fixture_before); let current_file_id = file_pos.file_id; - let diagnostic = analysis.diagnostics(current_file_id, true).unwrap().pop().unwrap(); + let diagnostic = analysis.diagnostics(current_file_id, true, None).unwrap().pop().unwrap(); let mut fix = diagnostic.fix.unwrap(); let edit = fix.source_change.source_file_edits.pop().unwrap(); let changed_file_id = edit.file_id; @@ -254,7 +251,7 @@ mod tests { let analysis = mock.analysis(); let diagnostics = files .into_iter() - .flat_map(|file_id| analysis.diagnostics(file_id, true).unwrap()) + .flat_map(|file_id| analysis.diagnostics(file_id, true, None).unwrap()) .collect::>(); assert_eq!(diagnostics.len(), 0, "unexpected diagnostics:\n{:#?}", diagnostics); } @@ -267,13 +264,14 @@ mod tests { let mock = MockAnalysis::with_files(ra_fixture); let files = mock.files().map(|(it, _)| it).collect::>(); - let mut analysis = mock.analysis(); - analysis.set_config(AnalysisConfig { disabled_diagnostics: disabled_diagnostics.clone() }); + let analysis = mock.analysis(); let diagnostics = files .clone() .into_iter() - .flat_map(|file_id| analysis.diagnostics(file_id, true).unwrap()) + .flat_map(|file_id| { + analysis.diagnostics(file_id, true, Some(disabled_diagnostics.clone())).unwrap() + }) .collect::>(); // First, we have to check that diagnostic is not emitted when it's added to the disabled diagnostics list. @@ -288,11 +286,9 @@ mod tests { // This is required for tests to not become outdated if e.g. diagnostics name changes: // without this additional run the test will pass simply because a diagnostic with an old name // will no longer exist. - analysis.set_config(AnalysisConfig { disabled_diagnostics: Default::default() }); - let diagnostics = files .into_iter() - .flat_map(|file_id| analysis.diagnostics(file_id, true).unwrap()) + .flat_map(|file_id| analysis.diagnostics(file_id, true, None).unwrap()) .collect::>(); assert!( @@ -306,7 +302,7 @@ mod tests { fn check_expect(ra_fixture: &str, expect: Expect) { let (analysis, file_id) = single_file(ra_fixture); - let diagnostics = analysis.diagnostics(file_id, true).unwrap(); + let diagnostics = analysis.diagnostics(file_id, true, None).unwrap(); expect.assert_debug_eq(&diagnostics) } diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index b762c994e..a19a379c6 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -151,16 +151,11 @@ impl RangeInfo { #[derive(Debug)] pub struct AnalysisHost { db: RootDatabase, - config: AnalysisConfig, } impl AnalysisHost { pub fn new(lru_capacity: Option) -> Self { - Self::with_config(lru_capacity, AnalysisConfig::default()) - } - - pub fn with_config(lru_capacity: Option, config: AnalysisConfig) -> Self { - AnalysisHost { db: RootDatabase::new(lru_capacity), config } + AnalysisHost { db: RootDatabase::new(lru_capacity) } } pub fn update_lru_capacity(&mut self, lru_capacity: Option) { @@ -170,7 +165,7 @@ impl AnalysisHost { /// Returns a snapshot of the current state, which you can query for /// semantic information. pub fn analysis(&self) -> Analysis { - Analysis { db: self.db.snapshot(), config: self.config.clone() } + Analysis { db: self.db.snapshot() } } /// Applies changes to the current state of the world. If there are @@ -214,7 +209,6 @@ impl Default for AnalysisHost { #[derive(Debug)] pub struct Analysis { db: salsa::Snapshot, - config: AnalysisConfig, } // As a general design guideline, `Analysis` API are intended to be independent @@ -509,8 +503,11 @@ impl Analysis { &self, file_id: FileId, enable_experimental: bool, + disabled_diagnostics: Option>, ) -> Cancelable> { - self.with_db(|db| diagnostics::diagnostics(db, file_id, enable_experimental, &self.config)) + self.with_db(|db| { + diagnostics::diagnostics(db, file_id, enable_experimental, disabled_diagnostics) + }) } /// Returns the edit required to rename reference at the position to the new @@ -539,11 +536,6 @@ impl Analysis { }) } - /// Sets the provided config. - pub fn set_config(&mut self, config: AnalysisConfig) { - self.config = config; - } - /// Performs an operation on that may be Canceled. fn with_db(&self, f: F) -> Cancelable where -- cgit v1.2.3 From 34847c8d96ddf98c40117ebacaecec38b9b758fc Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Tue, 18 Aug 2020 13:35:36 +0300 Subject: Move analysis config structure to the config.rs --- crates/ide/src/lib.rs | 6 ------ 1 file changed, 6 deletions(-) (limited to 'crates/ide/src') diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index a19a379c6..4b797f374 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -99,12 +99,6 @@ pub use text_edit::{Indel, TextEdit}; pub type Cancelable = Result; -/// Configuration parameters for the analysis run. -#[derive(Debug, Default, Clone)] -pub struct AnalysisConfig { - pub disabled_diagnostics: HashSet, -} - #[derive(Debug)] pub struct Diagnostic { pub name: Option, -- cgit v1.2.3