use hir::Semantics;
use ide_db::{
base_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt},
- helpers::{insert_use::MergeBehavior, SnippetCap},
+ helpers::{
+ insert_use::{InsertUseConfig, MergeBehavior},
+ SnippetCap,
+ },
source_change::FileSystemEdit,
RootDatabase,
};
use syntax::TextRange;
use test_utils::{assert_eq_text, extract_offset, extract_range};
-use crate::{
- handlers::Handler, Assist, AssistConfig, AssistContext, AssistKind, Assists, InsertUseConfig,
-};
+use crate::{handlers::Handler, Assist, AssistConfig, AssistContext, AssistKind, Assists};
use stdx::{format_to, trim_indent};
pub(crate) const TEST_CONFIG: AssistConfig = AssistConfig {
let actual = {
let source_change = assist.source_change.unwrap();
let mut actual = before;
- if let Some(source_file_edit) = source_change.source_file_edits.edits.get(&file_id) {
+ if let Some(source_file_edit) = source_change.get_source_edit(file_id) {
source_file_edit.apply(&mut actual);
}
actual
&& source_change.file_system_edits.len() == 0;
let mut buf = String::new();
- for (file_id, edit) in source_change.source_file_edits.edits {
+ for (file_id, edit) in source_change.source_file_edits {
let mut text = db.file_text(file_id).as_ref().to_owned();
edit.apply(&mut text);
if !skip_header {
buf.push_str(&text);
}
- for file_system_edit in source_change.file_system_edits.clone() {
- match file_system_edit {
- FileSystemEdit::CreateFile { dst, initial_contents } => {
- let sr = db.file_source_root(dst.anchor);
- let sr = db.source_root(sr);
- let mut base = sr.path_for_file(&dst.anchor).unwrap().clone();
- base.pop();
- let created_file_path = format!("{}{}", base.to_string(), &dst.path[1..]);
- format_to!(buf, "//- {}\n", created_file_path);
- buf.push_str(&initial_contents);
- }
- _ => (),
+ for file_system_edit in source_change.file_system_edits {
+ if let FileSystemEdit::CreateFile { dst, initial_contents } = file_system_edit {
+ let sr = db.file_source_root(dst.anchor);
+ let sr = db.source_root(sr);
+ let mut base = sr.path_for_file(&dst.anchor).unwrap().clone();
+ base.pop();
+ let created_file_path = format!("{}{}", base.to_string(), &dst.path[1..]);
+ format_to!(buf, "//- {}\n", created_file_path);
+ buf.push_str(&initial_contents);
}
}
let mut assists = assists.iter();
assert_eq!(assists.next().expect("expected assist").label, "Change visibility to pub(crate)");
+ assert_eq!(assists.next().expect("expected assist").label, "Generate a getter method");
+ assert_eq!(assists.next().expect("expected assist").label, "Generate a mut getter method");
+ assert_eq!(assists.next().expect("expected assist").label, "Generate a setter method");
assert_eq!(assists.next().expect("expected assist").label, "Add `#[derive]`");
}