diff options
author | Aleksey Kladov <[email protected]> | 2018-08-22 16:05:43 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-22 16:05:43 +0100 |
commit | 147578f0fe28dee9ba3bfe3ed8805ffe3a525611 (patch) | |
tree | 48d4abe5a2743f569e61745828ab35e275de4572 /crates/libeditor/src/code_actions.rs | |
parent | 69a524fbef067d9ee265fa93606c3ae743656c2a (diff) |
add impl initial
Diffstat (limited to 'crates/libeditor/src/code_actions.rs')
-rw-r--r-- | crates/libeditor/src/code_actions.rs | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/crates/libeditor/src/code_actions.rs b/crates/libeditor/src/code_actions.rs index 500d52c2a..1e20c0f48 100644 --- a/crates/libeditor/src/code_actions.rs +++ b/crates/libeditor/src/code_actions.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use {TextUnit, EditBuilder, Edit}; | 1 | use {TextUnit, EditBuilder, Edit}; |
2 | use libsyntax2::{ | 2 | use libsyntax2::{ |
3 | ast::{self, AstNode, AttrsOwner, ParsedFile}, | 3 | ast::{self, AstNode, AttrsOwner, TypeParamsOwner, NameOwner, ParsedFile}, |
4 | SyntaxKind::COMMA, | 4 | SyntaxKind::COMMA, |
5 | SyntaxNodeRef, | 5 | SyntaxNodeRef, |
6 | algo::{ | 6 | algo::{ |
@@ -58,6 +58,36 @@ pub fn add_derive<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option<impl FnO | |||
58 | }) | 58 | }) |
59 | } | 59 | } |
60 | 60 | ||
61 | pub fn add_impl<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> { | ||
62 | let nominal = find_node::<ast::NominalDef>(file.syntax(), offset)?; | ||
63 | let name = nominal.name()?; | ||
64 | |||
65 | Some(move || { | ||
66 | // let type_params = nominal.type_param_list(); | ||
67 | // let type_args = match type_params { | ||
68 | // None => String::new(), | ||
69 | // Some(params) => { | ||
70 | // let mut buf = String::new(); | ||
71 | // } | ||
72 | // }; | ||
73 | let mut edit = EditBuilder::new(); | ||
74 | let start_offset = nominal.syntax().range().end(); | ||
75 | edit.insert( | ||
76 | start_offset, | ||
77 | format!( | ||
78 | "\n\nimpl {} {{\n\n}}", | ||
79 | name.text(), | ||
80 | ) | ||
81 | ); | ||
82 | ActionResult { | ||
83 | edit: edit.finish(), | ||
84 | cursor_position: Some( | ||
85 | start_offset + TextUnit::of_str("\n\nimpl {\n") + name.syntax().range().len() | ||
86 | ), | ||
87 | } | ||
88 | }) | ||
89 | } | ||
90 | |||
61 | fn non_trivia_sibling(node: SyntaxNodeRef, direction: Direction) -> Option<SyntaxNodeRef> { | 91 | fn non_trivia_sibling(node: SyntaxNodeRef, direction: Direction) -> Option<SyntaxNodeRef> { |
62 | siblings(node, direction) | 92 | siblings(node, direction) |
63 | .skip(1) | 93 | .skip(1) |