diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ide/src/lib.rs | 28 | ||||
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 38 |
2 files changed, 43 insertions, 23 deletions
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 { | |||
531 | self.with_db(|db| diagnostics::diagnostics(db, config, file_id)) | 531 | self.with_db(|db| diagnostics::diagnostics(db, config, file_id)) |
532 | } | 532 | } |
533 | 533 | ||
534 | /// Convenience function to return assists + quick fixes for diagnostics | ||
535 | pub fn assists_with_fixes( | ||
536 | &self, | ||
537 | assist_config: &AssistConfig, | ||
538 | diagnostics_config: &DiagnosticsConfig, | ||
539 | resolve: bool, | ||
540 | frange: FileRange, | ||
541 | ) -> Cancelable<Vec<Assist>> { | ||
542 | let include_fixes = match &assist_config.allowed { | ||
543 | Some(it) => it.iter().any(|&it| it == AssistKind::None || it == AssistKind::QuickFix), | ||
544 | None => true, | ||
545 | }; | ||
546 | |||
547 | self.with_db(|db| { | ||
548 | let mut res = Assist::get(db, assist_config, resolve, frange); | ||
549 | ssr::add_ssr_assist(db, &mut res, resolve, frange); | ||
550 | |||
551 | if include_fixes { | ||
552 | res.extend( | ||
553 | diagnostics::diagnostics(db, diagnostics_config, frange.file_id) | ||
554 | .into_iter() | ||
555 | .filter_map(|it| it.fix), | ||
556 | ); | ||
557 | } | ||
558 | res | ||
559 | }) | ||
560 | } | ||
561 | |||
534 | /// Returns the edit required to rename reference at the position to the new | 562 | /// Returns the edit required to rename reference at the position to the new |
535 | /// name. | 563 | /// name. |
536 | pub fn rename( | 564 | pub fn rename( |
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 85c70373a..85cc8602e 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs | |||
@@ -8,8 +8,8 @@ use std::{ | |||
8 | }; | 8 | }; |
9 | 9 | ||
10 | use ide::{ | 10 | use ide::{ |
11 | AnnotationConfig, AssistKind, FileId, FilePosition, FileRange, HoverAction, HoverGotoTypeData, | 11 | AnnotationConfig, FileId, FilePosition, FileRange, HoverAction, HoverGotoTypeData, Query, |
12 | Query, RangeInfo, Runnable, RunnableKind, SearchScope, SourceChange, TextEdit, | 12 | RangeInfo, Runnable, RunnableKind, SearchScope, SourceChange, TextEdit, |
13 | }; | 13 | }; |
14 | use ide_db::SymbolKind; | 14 | use ide_db::SymbolKind; |
15 | use itertools::Itertools; | 15 | use itertools::Itertools; |
@@ -1003,27 +1003,13 @@ pub(crate) fn handle_code_action( | |||
1003 | 1003 | ||
1004 | let mut res: Vec<lsp_ext::CodeAction> = Vec::new(); | 1004 | let mut res: Vec<lsp_ext::CodeAction> = Vec::new(); |
1005 | 1005 | ||
1006 | let include_quick_fixes = match &assists_config.allowed { | ||
1007 | Some(v) => v.iter().any(|it| it == &AssistKind::None || it == &AssistKind::QuickFix), | ||
1008 | None => true, | ||
1009 | }; | ||
1010 | let code_action_resolve_cap = snap.config.code_action_resolve(); | 1006 | let code_action_resolve_cap = snap.config.code_action_resolve(); |
1011 | 1007 | let assists = snap.analysis.assists_with_fixes( | |
1012 | let mut assists = Vec::new(); | 1008 | &assists_config, |
1013 | 1009 | &snap.config.diagnostics(), | |
1014 | // Fixes from native diagnostics. | 1010 | !code_action_resolve_cap, |
1015 | if include_quick_fixes { | 1011 | frange, |
1016 | let diagnostics = snap.analysis.diagnostics(&snap.config.diagnostics(), frange.file_id)?; | 1012 | )?; |
1017 | assists.extend( | ||
1018 | diagnostics | ||
1019 | .into_iter() | ||
1020 | .filter_map(|d| d.fix) | ||
1021 | .filter(|fix| fix.target.intersect(frange.range).is_some()), | ||
1022 | ) | ||
1023 | } | ||
1024 | |||
1025 | // Assists proper. | ||
1026 | assists.extend(snap.analysis.assists(&assists_config, !code_action_resolve_cap, frange)?); | ||
1027 | for (index, assist) in assists.into_iter().enumerate() { | 1013 | for (index, assist) in assists.into_iter().enumerate() { |
1028 | let resolve_data = | 1014 | let resolve_data = |
1029 | if code_action_resolve_cap { Some((index, params.clone())) } else { None }; | 1015 | if code_action_resolve_cap { Some((index, params.clone())) } else { None }; |
@@ -1066,7 +1052,13 @@ pub(crate) fn handle_code_action_resolve( | |||
1066 | .only | 1052 | .only |
1067 | .map(|it| it.into_iter().filter_map(from_proto::assist_kind).collect()); | 1053 | .map(|it| it.into_iter().filter_map(from_proto::assist_kind).collect()); |
1068 | 1054 | ||
1069 | let assists = snap.analysis.assists(&assists_config, true, frange)?; | 1055 | let assists = snap.analysis.assists_with_fixes( |
1056 | &assists_config, | ||
1057 | &snap.config.diagnostics(), | ||
1058 | true, | ||
1059 | frange, | ||
1060 | )?; | ||
1061 | |||
1070 | let (id, index) = split_once(¶ms.id, ':').unwrap(); | 1062 | let (id, index) = split_once(¶ms.id, ':').unwrap(); |
1071 | let index = index.parse::<usize>().unwrap(); | 1063 | let index = index.parse::<usize>().unwrap(); |
1072 | let assist = &assists[index]; | 1064 | let assist = &assists[index]; |