aboutsummaryrefslogtreecommitdiff
path: root/crates/libeditor/src/code_actions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libeditor/src/code_actions.rs')
-rw-r--r--crates/libeditor/src/code_actions.rs32
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 @@
1use {TextUnit, EditBuilder, Edit}; 1use {TextUnit, EditBuilder, Edit};
2use libsyntax2::{ 2use 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
61pub 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
61fn non_trivia_sibling(node: SyntaxNodeRef, direction: Direction) -> Option<SyntaxNodeRef> { 91fn non_trivia_sibling(node: SyntaxNodeRef, direction: Direction) -> Option<SyntaxNodeRef> {
62 siblings(node, direction) 92 siblings(node, direction)
63 .skip(1) 93 .skip(1)