mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 07:04:22 +00:00
⬆️ rowan
This commit is contained in:
parent
545c21923e
commit
83a8430e0a
4 changed files with 21 additions and 22 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -1180,7 +1180,7 @@ dependencies = [
|
|||
"once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ra_parser 0.1.0",
|
||||
"ra_text_edit 0.1.0",
|
||||
"rowan 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rowan 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc_lexer 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smol_str 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1445,7 +1445,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "rowan"
|
||||
version = "0.6.3"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1993,7 +1993,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum relative-path 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bedde000f40f2921ce439ea165c9c53fd629bfa115140c72e22aceacb4a21954"
|
||||
"checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e"
|
||||
"checksum ron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ece421e0c4129b90e4a35b6f625e472e96c552136f5093a2f4fa2bbb75a62d5"
|
||||
"checksum rowan 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "fc3a6fb2a35518af7cab43ec4e21ca82eb086a8b3bb1739e426dc3923d459607"
|
||||
"checksum rowan 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d3a241900475bf2ba302061550ff50c82b45095ca95d23d1872345793fd42407"
|
||||
"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
|
||||
"checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8"
|
||||
"checksum rustc_lexer 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c86aae0c77166108c01305ee1a36a1e77289d7dc6ca0a3cd91ff4992de2d16a5"
|
||||
|
|
|
@ -12,7 +12,7 @@ doctest = false
|
|||
|
||||
[dependencies]
|
||||
itertools = "0.8.0"
|
||||
rowan = "0.6.1"
|
||||
rowan = "0.7.0"
|
||||
rustc_lexer = "0.1.0"
|
||||
rustc-hash = "1.0.1"
|
||||
arrayvec = "0.5.1"
|
||||
|
|
|
@ -134,23 +134,19 @@ pub fn insert_children(
|
|||
to_green_element(element)
|
||||
});
|
||||
|
||||
let old_children = parent.green().children();
|
||||
let mut old_children = parent.green().children().map(|it| match it {
|
||||
NodeOrToken::Token(it) => NodeOrToken::Token(it.clone()),
|
||||
NodeOrToken::Node(it) => NodeOrToken::Node(it.clone()),
|
||||
});
|
||||
|
||||
let new_children = match &position {
|
||||
InsertPosition::First => {
|
||||
to_insert.chain(old_children.iter().cloned()).collect::<Box<[_]>>()
|
||||
}
|
||||
InsertPosition::Last => old_children.iter().cloned().chain(to_insert).collect::<Box<[_]>>(),
|
||||
InsertPosition::First => to_insert.chain(old_children).collect::<Box<[_]>>(),
|
||||
InsertPosition::Last => old_children.chain(to_insert).collect::<Box<[_]>>(),
|
||||
InsertPosition::Before(anchor) | InsertPosition::After(anchor) => {
|
||||
let take_anchor = if let InsertPosition::After(_) = position { 1 } else { 0 };
|
||||
let split_at = position_of_child(parent, anchor.clone()) + take_anchor;
|
||||
let (before, after) = old_children.split_at(split_at);
|
||||
before
|
||||
.iter()
|
||||
.cloned()
|
||||
.chain(to_insert)
|
||||
.chain(after.iter().cloned())
|
||||
.collect::<Box<[_]>>()
|
||||
let before = old_children.by_ref().take(split_at).collect::<Vec<_>>();
|
||||
before.into_iter().chain(to_insert).chain(old_children).collect::<Box<[_]>>()
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -168,13 +164,16 @@ pub fn replace_children(
|
|||
) -> SyntaxNode {
|
||||
let start = position_of_child(parent, to_delete.start().clone());
|
||||
let end = position_of_child(parent, to_delete.end().clone());
|
||||
let old_children = parent.green().children();
|
||||
let mut old_children = parent.green().children().map(|it| match it {
|
||||
NodeOrToken::Token(it) => NodeOrToken::Token(it.clone()),
|
||||
NodeOrToken::Node(it) => NodeOrToken::Node(it.clone()),
|
||||
});
|
||||
|
||||
let new_children = old_children[..start]
|
||||
.iter()
|
||||
.cloned()
|
||||
let before = old_children.by_ref().take(start).collect::<Vec<_>>();
|
||||
let new_children = before
|
||||
.into_iter()
|
||||
.chain(to_insert.map(to_green_element))
|
||||
.chain(old_children[end + 1..].iter().cloned())
|
||||
.chain(old_children.skip(end + 1 - start))
|
||||
.collect::<Box<[_]>>();
|
||||
with_children(parent, new_children)
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ impl ast::NameRef {
|
|||
}
|
||||
|
||||
fn text_of_first_token(node: &SyntaxNode) -> &SmolStr {
|
||||
node.green().children().first().and_then(|it| it.as_token()).unwrap().text()
|
||||
node.green().children().next().and_then(|it| it.into_token()).unwrap().text()
|
||||
}
|
||||
|
||||
impl ast::Attr {
|
||||
|
|
Loading…
Reference in a new issue