mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
add "one" import granularity
This commit is contained in:
parent
9d9b34354d
commit
57d4b5bb0f
4 changed files with 243 additions and 60 deletions
|
@ -1,6 +1,6 @@
|
|||
//! Structural editing for ast.
|
||||
|
||||
use std::iter::{empty, successors};
|
||||
use std::iter::{empty, once, successors};
|
||||
|
||||
use parser::{SyntaxKind, T};
|
||||
|
||||
|
@ -530,6 +530,25 @@ impl ast::UseTree {
|
|||
Some(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Wraps the use tree in use tree list with no top level path (if it isn't already).
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// `foo::bar` -> `{foo::bar}`
|
||||
///
|
||||
/// `{foo::bar}` -> `{foo::bar}`
|
||||
pub fn wrap_in_tree_list(&self) {
|
||||
if self.path().is_none() {
|
||||
return;
|
||||
}
|
||||
let subtree = self.clone_subtree().clone_for_update();
|
||||
ted::remove_all_iter(self.syntax().children_with_tokens());
|
||||
ted::append_child(
|
||||
self.syntax(),
|
||||
make::use_tree_list(once(subtree)).clone_for_update().syntax(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::UseTreeList {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue