Handle multiple cargo check quick fix spans

This commit is contained in:
Brandon
2021-12-04 20:59:26 -08:00
parent de05c3d406
commit 0d1910c6fb
3 changed files with 32 additions and 23 deletions

View File

@@ -29,7 +29,8 @@ pub(crate) struct DiagnosticCollection {
#[derive(Debug, Clone)]
pub(crate) struct Fix {
pub(crate) range: lsp_types::Range,
// Fixes may be triggerable from multiple ranges.
pub(crate) ranges: Vec<lsp_types::Range>,
pub(crate) action: lsp_ext::CodeAction,
}
@@ -43,7 +44,7 @@ impl DiagnosticCollection {
&mut self,
file_id: FileId,
diagnostic: lsp_types::Diagnostic,
fix: Option<lsp_ext::CodeAction>,
fix: Option<Fix>,
) {
let diagnostics = self.check.entry(file_id).or_default();
for existing_diagnostic in diagnostics.iter() {
@@ -53,10 +54,7 @@ impl DiagnosticCollection {
}
let check_fixes = Arc::make_mut(&mut self.check_fixes);
check_fixes
.entry(file_id)
.or_default()
.extend(fix.into_iter().map(|action| Fix { range: diagnostic.range, action }));
check_fixes.entry(file_id).or_default().extend(fix);
diagnostics.push(diagnostic);
self.changes.insert(file_id);
}