aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_editor/src/code_actions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_editor/src/code_actions.rs')
-rw-r--r--crates/ra_editor/src/code_actions.rs19
1 files changed, 14 insertions, 5 deletions
diff --git a/crates/ra_editor/src/code_actions.rs b/crates/ra_editor/src/code_actions.rs
index ef6df0d53..0139b19d3 100644
--- a/crates/ra_editor/src/code_actions.rs
+++ b/crates/ra_editor/src/code_actions.rs
@@ -3,7 +3,7 @@ use join_to_string::join;
3use ra_syntax::{ 3use ra_syntax::{
4 algo::{find_covering_node, find_leaf_at_offset}, 4 algo::{find_covering_node, find_leaf_at_offset},
5 ast::{self, AstNode, AttrsOwner, NameOwner, TypeParamsOwner}, 5 ast::{self, AstNode, AttrsOwner, NameOwner, TypeParamsOwner},
6 Direction, File, 6 Direction, SourceFileNode,
7 SyntaxKind::{COMMA, WHITESPACE}, 7 SyntaxKind::{COMMA, WHITESPACE},
8 SyntaxNodeRef, TextRange, TextUnit, 8 SyntaxNodeRef, TextRange, TextUnit,
9}; 9};
@@ -16,7 +16,10 @@ pub struct LocalEdit {
16 pub cursor_position: Option<TextUnit>, 16 pub cursor_position: Option<TextUnit>,
17} 17}
18 18
19pub fn flip_comma<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> LocalEdit + 'a> { 19pub fn flip_comma<'a>(
20 file: &'a SourceFileNode,
21 offset: TextUnit,
22) -> Option<impl FnOnce() -> LocalEdit + 'a> {
20 let syntax = file.syntax(); 23 let syntax = file.syntax();
21 24
22 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)?;
@@ -33,7 +36,10 @@ pub fn flip_comma<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce()
33 }) 36 })
34} 37}
35 38
36pub fn add_derive<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> LocalEdit + 'a> { 39pub fn add_derive<'a>(
40 file: &'a SourceFileNode,
41 offset: TextUnit,
42) -> Option<impl FnOnce() -> LocalEdit + 'a> {
37 let nominal = find_node_at_offset::<ast::NominalDef>(file.syntax(), offset)?; 43 let nominal = find_node_at_offset::<ast::NominalDef>(file.syntax(), offset)?;
38 Some(move || { 44 Some(move || {
39 let derive_attr = nominal 45 let derive_attr = nominal
@@ -58,7 +64,10 @@ pub fn add_derive<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce()
58 }) 64 })
59} 65}
60 66
61pub fn add_impl<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> LocalEdit + 'a> { 67pub fn add_impl<'a>(
68 file: &'a SourceFileNode,
69 offset: TextUnit,
70) -> Option<impl FnOnce() -> LocalEdit + 'a> {
62 let nominal = find_node_at_offset::<ast::NominalDef>(file.syntax(), offset)?; 71 let nominal = find_node_at_offset::<ast::NominalDef>(file.syntax(), offset)?;
63 let name = nominal.name()?; 72 let name = nominal.name()?;
64 73
@@ -98,7 +107,7 @@ pub fn add_impl<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() ->
98} 107}
99 108
100pub fn introduce_variable<'a>( 109pub fn introduce_variable<'a>(
101 file: &'a File, 110 file: &'a SourceFileNode,
102 range: TextRange, 111 range: TextRange,
103) -> Option<impl FnOnce() -> LocalEdit + 'a> { 112) -> Option<impl FnOnce() -> LocalEdit + 'a> {
104 let node = find_covering_node(file.syntax(), range); 113 let node = find_covering_node(file.syntax(), range);