aboutsummaryrefslogtreecommitdiff
path: root/crates/libeditor/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libeditor/src')
-rw-r--r--crates/libeditor/src/lib.rs2
-rw-r--r--crates/libeditor/src/typing.rs24
2 files changed, 23 insertions, 3 deletions
diff --git a/crates/libeditor/src/lib.rs b/crates/libeditor/src/lib.rs
index d39e56d81..34056b3c0 100644
--- a/crates/libeditor/src/lib.rs
+++ b/crates/libeditor/src/lib.rs
@@ -27,7 +27,7 @@ pub use self::{
27 ActionResult, 27 ActionResult,
28 flip_comma, add_derive, add_impl, 28 flip_comma, add_derive, add_impl,
29 }, 29 },
30 typing::join_lines, 30 typing::{join_lines, on_eq_typed},
31 completion::scope_completion, 31 completion::scope_completion,
32}; 32};
33 33
diff --git a/crates/libeditor/src/typing.rs b/crates/libeditor/src/typing.rs
index 060095f28..48a8d6bb0 100644
--- a/crates/libeditor/src/typing.rs
+++ b/crates/libeditor/src/typing.rs
@@ -7,11 +7,11 @@ use libsyntax2::{
7 walk::preorder, 7 walk::preorder,
8 find_covering_node, 8 find_covering_node,
9 }, 9 },
10 text_utils::intersect, 10 text_utils::{intersect, contains_offset_nonstrict},
11 SyntaxKind::*, 11 SyntaxKind::*,
12}; 12};
13 13
14use {ActionResult, EditBuilder}; 14use {ActionResult, EditBuilder, find_node_at_offset};
15 15
16pub fn join_lines(file: &File, range: TextRange) -> ActionResult { 16pub fn join_lines(file: &File, range: TextRange) -> ActionResult {
17 let range = if range.is_empty() { 17 let range = if range.is_empty() {
@@ -56,6 +56,26 @@ pub fn join_lines(file: &File, range: TextRange) -> ActionResult {
56 } 56 }
57} 57}
58 58
59pub fn on_eq_typed(file: &File, offset: TextUnit) -> Option<ActionResult> {
60 let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?;
61 if let_stmt.has_semi() {
62 return None;
63 }
64 if let Some(expr) = let_stmt.initializer() {
65 let expr_range = expr.syntax().range();
66 if contains_offset_nonstrict(expr_range, offset) && offset != expr_range.start() {
67 return None;
68 }
69 }
70 let offset = let_stmt.syntax().range().end();
71 let mut edit = EditBuilder::new();
72 edit.insert(offset, ";".to_string());
73 Some(ActionResult {
74 edit: edit.finish(),
75 cursor_position: None,
76 })
77}
78
59fn remove_newline( 79fn remove_newline(
60 edit: &mut EditBuilder, 80 edit: &mut EditBuilder,
61 node: SyntaxNodeRef, 81 node: SyntaxNodeRef,