From 04b5fcfdb28f18f4d5279b43c2bb2b3f9c082313 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 13 Apr 2021 11:27:00 +0300 Subject: Ensure that listing&resolving code actions use the same set of actions --- crates/ide/src/lib.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'crates/ide/src/lib.rs') diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 0615b26d3..bbc0d5eec 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -531,6 +531,34 @@ impl Analysis { self.with_db(|db| diagnostics::diagnostics(db, config, file_id)) } + /// Convenience function to return assists + quick fixes for diagnostics + pub fn assists_with_fixes( + &self, + assist_config: &AssistConfig, + diagnostics_config: &DiagnosticsConfig, + resolve: bool, + frange: FileRange, + ) -> Cancelable> { + let include_fixes = match &assist_config.allowed { + Some(it) => it.iter().any(|&it| it == AssistKind::None || it == AssistKind::QuickFix), + None => true, + }; + + self.with_db(|db| { + let mut res = Assist::get(db, assist_config, resolve, frange); + ssr::add_ssr_assist(db, &mut res, resolve, frange); + + if include_fixes { + res.extend( + diagnostics::diagnostics(db, diagnostics_config, frange.file_id) + .into_iter() + .filter_map(|it| it.fix), + ); + } + res + }) + } + /// Returns the edit required to rename reference at the position to the new /// name. pub fn rename( -- cgit v1.2.3