diff options
author | Aleksey Kladov <[email protected]> | 2018-08-17 20:00:13 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-17 20:00:13 +0100 |
commit | d3c90ded2b9a4f75e101fa3abc60cd3aebc439c9 (patch) | |
tree | 6d2388eb68605331a0dd090269372bc98dd038cd /crates/libeditor/src/code_actions.rs | |
parent | 70097504f78c4c41368a0b864a94df95fb9c27f7 (diff) |
Borrowed AST
Diffstat (limited to 'crates/libeditor/src/code_actions.rs')
-rw-r--r-- | crates/libeditor/src/code_actions.rs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/crates/libeditor/src/code_actions.rs b/crates/libeditor/src/code_actions.rs index bb6eb0d61..80c396337 100644 --- a/crates/libeditor/src/code_actions.rs +++ b/crates/libeditor/src/code_actions.rs | |||
@@ -1,8 +1,8 @@ | |||
1 | use {TextUnit, File, EditBuilder, Edit}; | 1 | use {TextUnit, EditBuilder, Edit}; |
2 | use libsyntax2::{ | 2 | use libsyntax2::{ |
3 | ast::{self, AstNode, AttrsOwner}, | 3 | ast::{self, AstNode, AttrsOwner, ParsedFile}, |
4 | SyntaxKind::COMMA, | 4 | SyntaxKind::COMMA, |
5 | SyntaxNodeRef, RefRoot, | 5 | SyntaxNodeRef, |
6 | algo::{ | 6 | algo::{ |
7 | Direction, siblings, | 7 | Direction, siblings, |
8 | find_leaf_at_offset, ancestors, | 8 | find_leaf_at_offset, ancestors, |
@@ -19,9 +19,8 @@ pub enum CursorPosition { | |||
19 | Offset(TextUnit), | 19 | Offset(TextUnit), |
20 | } | 20 | } |
21 | 21 | ||
22 | pub fn flip_comma<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> { | 22 | pub fn flip_comma<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> { |
23 | let syntax = file.syntax(); | 23 | let syntax = file.syntax(); |
24 | let syntax = syntax.as_ref(); | ||
25 | 24 | ||
26 | let comma = find_leaf_at_offset(syntax, offset).find(|leaf| leaf.kind() == COMMA)?; | 25 | let comma = find_leaf_at_offset(syntax, offset).find(|leaf| leaf.kind() == COMMA)?; |
27 | let left = non_trivia_sibling(comma, Direction::Backward)?; | 26 | let left = non_trivia_sibling(comma, Direction::Backward)?; |
@@ -37,8 +36,8 @@ pub fn flip_comma<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() | |||
37 | }) | 36 | }) |
38 | } | 37 | } |
39 | 38 | ||
40 | pub fn add_derive<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> { | 39 | pub fn add_derive<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> { |
41 | let nominal = find_node::<ast::NominalDef<_>>(file.syntax_ref(), offset)?; | 40 | let nominal = find_node::<ast::NominalDef>(file.syntax(), offset)?; |
42 | Some(move || { | 41 | Some(move || { |
43 | let derive_attr = nominal | 42 | let derive_attr = nominal |
44 | .attrs() | 43 | .attrs() |
@@ -70,7 +69,7 @@ fn non_trivia_sibling(node: SyntaxNodeRef, direction: Direction) -> Option<Synta | |||
70 | .find(|node| !node.kind().is_trivia()) | 69 | .find(|node| !node.kind().is_trivia()) |
71 | } | 70 | } |
72 | 71 | ||
73 | pub fn find_node<'a, N: AstNode<RefRoot<'a>>>(syntax: SyntaxNodeRef<'a>, offset: TextUnit) -> Option<N> { | 72 | pub fn find_node<'a, N: AstNode<'a>>(syntax: SyntaxNodeRef<'a>, offset: TextUnit) -> Option<N> { |
74 | let leaves = find_leaf_at_offset(syntax, offset); | 73 | let leaves = find_leaf_at_offset(syntax, offset); |
75 | let leaf = leaves.clone() | 74 | let leaf = leaves.clone() |
76 | .find(|leaf| !leaf.kind().is_trivia()) | 75 | .find(|leaf| !leaf.kind().is_trivia()) |