diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-11-03 17:34:59 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-11-03 17:34:59 +0000 |
commit | 060c8b2c96a0de4a131c4d780d2aac80afe13de8 (patch) | |
tree | 1c9c4d8b4134418dcf0dcfaf97d43c97d391f246 /crates/assists/src/handlers/replace_qualified_name_with_use.rs | |
parent | 5e622332774fbd57c12addd46b058c8feb2b08a6 (diff) | |
parent | cd349dbbc4a39342fd54e46fc9d70e3e649a2fda (diff) |
Merge #6287
6287: Don't replace entire module and file nodes when inserting imports r=matklad a=Veykril
This change minifies the resulting diff of import insertions by inserting or replacing the produced use tree directly through an `action` return value instead replacing the entire container node. This action has to be applied by the caller now. This unfortunately pulls the `AssistBuilder` into scope of `insert_use` back again but I tried to at least keep it away from the `insert_use` fn itself.
I'm open to more/better ideas regarding this :)
Fixes #6196
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/assists/src/handlers/replace_qualified_name_with_use.rs')
-rw-r--r-- | crates/assists/src/handlers/replace_qualified_name_with_use.rs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/crates/assists/src/handlers/replace_qualified_name_with_use.rs b/crates/assists/src/handlers/replace_qualified_name_with_use.rs index c50bc7604..d7e1d9580 100644 --- a/crates/assists/src/handlers/replace_qualified_name_with_use.rs +++ b/crates/assists/src/handlers/replace_qualified_name_with_use.rs | |||
@@ -45,10 +45,9 @@ pub(crate) fn replace_qualified_name_with_use( | |||
45 | // affected (that is, all paths inside the node we added the `use` to). | 45 | // affected (that is, all paths inside the node we added the `use` to). |
46 | let mut rewriter = SyntaxRewriter::default(); | 46 | let mut rewriter = SyntaxRewriter::default(); |
47 | shorten_paths(&mut rewriter, syntax.clone(), &path); | 47 | shorten_paths(&mut rewriter, syntax.clone(), &path); |
48 | let rewritten_syntax = rewriter.rewrite(&syntax); | 48 | if let Some(ref import_scope) = ImportScope::from(syntax.clone()) { |
49 | if let Some(ref import_scope) = ImportScope::from(rewritten_syntax) { | 49 | rewriter += insert_use(import_scope, path, ctx.config.insert_use.merge); |
50 | let new_syntax = insert_use(import_scope, path, ctx.config.insert_use.merge); | 50 | builder.rewrite(rewriter); |
51 | builder.replace(syntax.text_range(), new_syntax.to_string()) | ||
52 | } | 51 | } |
53 | }, | 52 | }, |
54 | ) | 53 | ) |