Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-diagnostics/src/handlers/unresolved_field.rs')
-rw-r--r--crates/ide-diagnostics/src/handlers/unresolved_field.rs39
1 files changed, 18 insertions, 21 deletions
diff --git a/crates/ide-diagnostics/src/handlers/unresolved_field.rs b/crates/ide-diagnostics/src/handlers/unresolved_field.rs
index 6ab713a589..a4f4813cf5 100644
--- a/crates/ide-diagnostics/src/handlers/unresolved_field.rs
+++ b/crates/ide-diagnostics/src/handlers/unresolved_field.rs
@@ -1,25 +1,24 @@
use std::iter;
use either::Either;
-use hir::{db::ExpandDatabase, Adt, FileRange, HasSource, HirDisplay, InFile, Struct, Union};
+use hir::{Adt, FileRange, HasSource, HirDisplay, InFile, Struct, Union, db::ExpandDatabase};
use ide_db::text_edit::TextEdit;
use ide_db::{
- assists::{Assist, AssistId, AssistKind},
+ assists::{Assist, AssistId},
helpers::is_editable_crate,
label::Label,
source_change::{SourceChange, SourceChangeBuilder},
};
use syntax::{
- algo,
- ast::{self, edit::IndentLevel, make, FieldList, Name, Visibility},
- AstNode, AstPtr, Direction, SyntaxKind, TextSize,
+ AstNode, AstPtr, Direction, SyntaxKind, TextSize, algo,
+ ast::{self, FieldList, Name, Visibility, edit::IndentLevel, make},
};
use syntax::{
- ast::{edit::AstNodeEdit, Type},
SyntaxNode,
+ ast::{Type, edit::AstNodeEdit},
};
-use crate::{adjusted_display_range, Diagnostic, DiagnosticCode, DiagnosticsContext};
+use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext, adjusted_display_range};
// Diagnostic: unresolved-field
//
@@ -62,11 +61,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::UnresolvedField) -> Option<Vec<A
fixes.extend(method_fix(ctx, &d.expr));
}
fixes.extend(field_fix(ctx, d));
- if fixes.is_empty() {
- None
- } else {
- Some(fixes)
- }
+ if fixes.is_empty() { None } else { Some(fixes) }
}
// FIXME: Add Snippet Support
@@ -124,10 +119,10 @@ fn add_variant_to_union(
let (offset, record_field) =
record_field_layout(None, field_name, suggested_type, field_list, adt_syntax.value)?;
- let mut src_change_builder = SourceChangeBuilder::new(range.file_id);
+ let mut src_change_builder = SourceChangeBuilder::new(range.file_id.file_id(ctx.sema.db));
src_change_builder.insert(offset, record_field);
Some(Assist {
- id: AssistId("add-variant-to-union", AssistKind::QuickFix),
+ id: AssistId::quick_fix("add-variant-to-union"),
label: Label::new("Add field to union".to_owned()),
group: None,
target: error_range.range,
@@ -170,12 +165,13 @@ fn add_field_to_struct_fix(
struct_syntax.value,
)?;
- let mut src_change_builder = SourceChangeBuilder::new(struct_range.file_id);
+ let mut src_change_builder =
+ SourceChangeBuilder::new(struct_range.file_id.file_id(ctx.sema.db));
// FIXME: Allow for choosing a visibility modifier see https://github.com/rust-lang/rust-analyzer/issues/11563
src_change_builder.insert(offset, record_field);
Some(Assist {
- id: AssistId("add-field-to-record-struct", AssistKind::QuickFix),
+ id: AssistId::quick_fix("add-field-to-record-struct"),
label: Label::new("Add field to Record Struct".to_owned()),
group: None,
target: error_range.range,
@@ -185,7 +181,8 @@ fn add_field_to_struct_fix(
}
None => {
// Add a field list to the Unit Struct
- let mut src_change_builder = SourceChangeBuilder::new(struct_range.file_id);
+ let mut src_change_builder =
+ SourceChangeBuilder::new(struct_range.file_id.file_id(ctx.sema.db));
let field_name = match field_name.chars().next() {
// FIXME : See match arm below regarding tuple structs.
Some(ch) if ch.is_numeric() => return None,
@@ -211,7 +208,7 @@ fn add_field_to_struct_fix(
src_change_builder.replace(semi_colon.text_range(), record_field_list.to_string());
Some(Assist {
- id: AssistId("convert-unit-struct-to-record-struct", AssistKind::QuickFix),
+ id: AssistId::quick_fix("convert-unit-struct-to-record-struct"),
label: Label::new("Convert Unit Struct to Record Struct and add field".to_owned()),
group: None,
target: error_range.range,
@@ -270,12 +267,12 @@ fn method_fix(
let expr = expr_ptr.value.to_node(&root);
let FileRange { range, file_id } = ctx.sema.original_range_opt(expr.syntax())?;
Some(Assist {
- id: AssistId("expected-field-found-method-call-fix", AssistKind::QuickFix),
+ id: AssistId::quick_fix("expected-field-found-method-call-fix"),
label: Label::new("Use parentheses to call the method".to_owned()),
group: None,
target: range,
source_change: Some(SourceChange::from_text_edit(
- file_id,
+ file_id.file_id(ctx.sema.db),
TextEdit::insert(range.end(), "()".to_owned()),
)),
command: None,
@@ -285,11 +282,11 @@ fn method_fix(
mod tests {
use crate::{
+ DiagnosticsConfig,
tests::{
check_diagnostics, check_diagnostics_with_config, check_diagnostics_with_disabled,
check_fix, check_no_fix,
},
- DiagnosticsConfig,
};
#[test]