diff options
author | IceSentry <[email protected]> | 2020-04-13 18:59:30 +0100 |
---|---|---|
committer | IceSentry <[email protected]> | 2020-04-13 18:59:30 +0100 |
commit | ed0eedb1dda9ae2a46735bb469aeaf5cf8a28601 (patch) | |
tree | 22e314355935ba5467afe7932fbe342cbc14f6f9 /crates/ra_assists/src/handlers | |
parent | 2e279ca031a52e90cd19dff513ee9d5b80cee8aa (diff) |
Fix PR
Diffstat (limited to 'crates/ra_assists/src/handlers')
-rw-r--r-- | crates/ra_assists/src/handlers/merge_imports.rs | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/crates/ra_assists/src/handlers/merge_imports.rs b/crates/ra_assists/src/handlers/merge_imports.rs index b3101f3ab..ef0ce0586 100644 --- a/crates/ra_assists/src/handlers/merge_imports.rs +++ b/crates/ra_assists/src/handlers/merge_imports.rs | |||
@@ -1,9 +1,9 @@ | |||
1 | use std::iter::successors; | 1 | use std::iter::successors; |
2 | 2 | ||
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | algo::{neighbor, SyntaxRewriter}, | 4 | algo::{neighbor, skip_trivia_token, SyntaxRewriter}, |
5 | ast::{self, edit::AstNodeEdit, make}, | 5 | ast::{self, edit::AstNodeEdit, make}, |
6 | AstNode, Direction, InsertPosition, NodeOrToken, SyntaxElement, T, | 6 | AstNode, Direction, InsertPosition, SyntaxElement, T, |
7 | }; | 7 | }; |
8 | 8 | ||
9 | use crate::{Assist, AssistCtx, AssistId}; | 9 | use crate::{Assist, AssistCtx, AssistId}; |
@@ -72,18 +72,12 @@ fn try_merge_trees(old: &ast::UseTree, new: &ast::UseTree) -> Option<ast::UseTre | |||
72 | let lhs = old.split_prefix(&lhs_prefix); | 72 | let lhs = old.split_prefix(&lhs_prefix); |
73 | let rhs = new.split_prefix(&rhs_prefix); | 73 | let rhs = new.split_prefix(&rhs_prefix); |
74 | 74 | ||
75 | let mut should_insert_comma = true; | 75 | let should_insert_comma = lhs |
76 | 76 | .use_tree_list()? | |
77 | lhs.syntax() | 77 | .r_curly_token() |
78 | .last_child() | 78 | .and_then(|it| skip_trivia_token(it.prev_token()?, Direction::Prev)) |
79 | .and_then(|child| child.children().last()) | 79 | .map(|it| it.kind() != T![,]) |
80 | .and_then(|last| last.next_sibling_or_token()) | 80 | .unwrap_or(true); |
81 | .map(|next_sibling| { | ||
82 | // FIXME: there's probably a better way to check if it's a COMMA | ||
83 | if let NodeOrToken::Token(maybe_comma) = next_sibling { | ||
84 | should_insert_comma = maybe_comma.to_string() != ","; | ||
85 | } | ||
86 | }); | ||
87 | 81 | ||
88 | let mut to_insert: Vec<SyntaxElement> = Vec::new(); | 82 | let mut to_insert: Vec<SyntaxElement> = Vec::new(); |
89 | if should_insert_comma { | 83 | if should_insert_comma { |