mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-31 07:37:30 +00:00
Add partial selection for merge_imports
Example --- **Input**: ```rust use std::fmt::Error; $0use std::fmt::Display; use std::fmt::Debug; use std::fmt::Write; use$0 std::fmt::Result; ``` **Before this PR**: ```rust use std::fmt::Error; use std::fmt::{Debug, Display, Write}; use std::fmt::Result; ``` **After this PR**: ```rust use std::fmt::Error; use std::fmt::{Debug, Display, Result, Write}; ```
This commit is contained in:
parent
1f4e5e82ff
commit
45fb60e01b
1 changed files with 22 additions and 2 deletions
|
@ -49,8 +49,9 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio
|
|||
SyntaxElement::Node(n) => n,
|
||||
SyntaxElement::Token(t) => t.parent()?,
|
||||
};
|
||||
let mut selected_nodes =
|
||||
parent_node.children().filter(|it| selection_range.contains_range(it.text_range()));
|
||||
let mut selected_nodes = parent_node.children().filter(|it| {
|
||||
selection_range.intersect(it.text_range()).is_some_and(|it| !it.is_empty())
|
||||
});
|
||||
|
||||
let first_selected = selected_nodes.next()?;
|
||||
let edits = match_ast! {
|
||||
|
@ -677,6 +678,25 @@ use std::fmt::Result;
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_partial_selection_uses() {
|
||||
cov_mark::check!(merge_with_selected_use_item_neighbors);
|
||||
check_assist(
|
||||
merge_imports,
|
||||
r"
|
||||
use std::fmt::Error;
|
||||
$0use std::fmt::Display;
|
||||
use std::fmt::Debug;
|
||||
use std::fmt::Write;
|
||||
use$0 std::fmt::Result;
|
||||
",
|
||||
r"
|
||||
use std::fmt::Error;
|
||||
use std::fmt::{Debug, Display, Result, Write};
|
||||
",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_selection_use_trees() {
|
||||
cov_mark::check!(merge_with_selected_use_tree_neighbors);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue