Skip to content

Commit bd78578

Browse files
bors[bot]matklad
andauthored
Merge #6801
6801: Minor, more orthogonal code r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 83aa6fb + 076945e commit bd78578

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

crates/completion/src/completions/unqualified_path.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,13 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
145145
})
146146
.filter(|(mod_path, _)| mod_path.len() > 1)
147147
.filter_map(|(import_path, definition)| {
148-
render_resolution_with_import(
149-
RenderContext::new(ctx),
150-
ImportEdit {
151-
import_path: import_path.clone(),
152-
import_scope: import_scope.clone(),
153-
merge_behavior: ctx.config.merge,
154-
},
155-
&definition,
156-
)
148+
let ie =
149+
ImportEdit { import_path: import_path.clone(), import_scope: import_scope.clone() };
150+
{
151+
let _p = profile::span("totextedit");
152+
ie.to_text_edit(ctx.config.merge);
153+
}
154+
render_resolution_with_import(RenderContext::new(ctx), ie, &definition)
157155
});
158156

159157
acc.add_all(possible_imports);

crates/completion/src/item.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,19 +271,18 @@ impl CompletionItem {
271271
pub struct ImportEdit {
272272
pub import_path: ModPath,
273273
pub import_scope: ImportScope,
274-
pub merge_behavior: Option<MergeBehavior>,
275274
}
276275

277276
impl ImportEdit {
278277
/// Attempts to insert the import to the given scope, producing a text edit.
279278
/// May return no edit in edge cases, such as scope already containing the import.
280-
pub fn to_text_edit(&self) -> Option<TextEdit> {
279+
pub fn to_text_edit(&self, merge_behavior: Option<MergeBehavior>) -> Option<TextEdit> {
281280
let _p = profile::span("ImportEdit::to_text_edit");
282281

283282
let rewriter = insert_use::insert_use(
284283
&self.import_scope,
285284
mod_path_to_ast(&self.import_path),
286-
self.merge_behavior,
285+
merge_behavior,
287286
);
288287
let old_ast = rewriter.rewrite_root()?;
289288
let mut import_insert = TextEdit::builder();

crates/completion/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,7 @@ pub fn resolve_completion_edits(
153153
})
154154
.find(|mod_path| mod_path.to_string() == full_import_path)?;
155155

156-
ImportEdit { import_path, import_scope, merge_behavior: config.merge }
157-
.to_text_edit()
158-
.map(|edit| vec![edit])
156+
ImportEdit { import_path, import_scope }.to_text_edit(config.merge).map(|edit| vec![edit])
159157
}
160158

161159
#[cfg(test)]

crates/completion/src/test_utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ pub(crate) fn check_edit_with_config(
9898
let mut actual = db.file_text(position.file_id).to_string();
9999

100100
let mut combined_edit = completion.text_edit().to_owned();
101-
if let Some(import_text_edit) = completion.import_to_add().and_then(|edit| edit.to_text_edit())
101+
if let Some(import_text_edit) =
102+
completion.import_to_add().and_then(|edit| edit.to_text_edit(config.merge))
102103
{
103104
combined_edit.union(import_text_edit).expect(
104105
"Failed to apply completion resolve changes: change ranges overlap, but should not",

0 commit comments

Comments
 (0)