diff options
Diffstat (limited to 'crates/libeditor/src/typing.rs')
-rw-r--r-- | crates/libeditor/src/typing.rs | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/crates/libeditor/src/typing.rs b/crates/libeditor/src/typing.rs index 5008b8d49..f888f3240 100644 --- a/crates/libeditor/src/typing.rs +++ b/crates/libeditor/src/typing.rs | |||
@@ -11,14 +11,14 @@ use libsyntax2::{ | |||
11 | SyntaxKind::*, | 11 | SyntaxKind::*, |
12 | }; | 12 | }; |
13 | 13 | ||
14 | use {ActionResult, EditBuilder, find_node_at_offset}; | 14 | use {LocalEdit, EditBuilder, find_node_at_offset}; |
15 | 15 | ||
16 | pub fn join_lines(file: &File, range: TextRange) -> ActionResult { | 16 | pub fn join_lines(file: &File, range: TextRange) -> LocalEdit { |
17 | let range = if range.is_empty() { | 17 | let range = if range.is_empty() { |
18 | let syntax = file.syntax(); | 18 | let syntax = file.syntax(); |
19 | let text = syntax.text().slice(range.start()..); | 19 | let text = syntax.text().slice(range.start()..); |
20 | let pos = match text.find('\n') { | 20 | let pos = match text.find('\n') { |
21 | None => return ActionResult { | 21 | None => return LocalEdit { |
22 | edit: EditBuilder::new().finish(), | 22 | edit: EditBuilder::new().finish(), |
23 | cursor_position: None | 23 | cursor_position: None |
24 | }, | 24 | }, |
@@ -50,13 +50,13 @@ pub fn join_lines(file: &File, range: TextRange) -> ActionResult { | |||
50 | } | 50 | } |
51 | eprintln!("{:?}", edit); | 51 | eprintln!("{:?}", edit); |
52 | 52 | ||
53 | ActionResult { | 53 | LocalEdit { |
54 | edit: edit.finish(), | 54 | edit: edit.finish(), |
55 | cursor_position: None, | 55 | cursor_position: None, |
56 | } | 56 | } |
57 | } | 57 | } |
58 | 58 | ||
59 | pub fn on_eq_typed(file: &File, offset: TextUnit) -> Option<ActionResult> { | 59 | pub fn on_eq_typed(file: &File, offset: TextUnit) -> Option<LocalEdit> { |
60 | let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?; | 60 | let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?; |
61 | if let_stmt.has_semi() { | 61 | if let_stmt.has_semi() { |
62 | return None; | 62 | return None; |
@@ -75,7 +75,7 @@ pub fn on_eq_typed(file: &File, offset: TextUnit) -> Option<ActionResult> { | |||
75 | let offset = let_stmt.syntax().range().end(); | 75 | let offset = let_stmt.syntax().range().end(); |
76 | let mut edit = EditBuilder::new(); | 76 | let mut edit = EditBuilder::new(); |
77 | edit.insert(offset, ";".to_string()); | 77 | edit.insert(offset, ";".to_string()); |
78 | Some(ActionResult { | 78 | Some(LocalEdit { |
79 | edit: edit.finish(), | 79 | edit: edit.finish(), |
80 | cursor_position: None, | 80 | cursor_position: None, |
81 | }) | 81 | }) |
@@ -277,7 +277,41 @@ fn foo() { | |||
277 | }", r" | 277 | }", r" |
278 | fn foo() { | 278 | fn foo() { |
279 | join(type_params.type_params().filter_map(|it| it.name()).map(|it| it.text())) | 279 | join(type_params.type_params().filter_map(|it| it.name()).map(|it| it.text())) |
280 | }") | 280 | }"); |
281 | |||
282 | do_check(r" | ||
283 | pub fn handle_find_matching_brace( | ||
284 | world: ServerWorld, | ||
285 | params: req::FindMatchingBraceParams, | ||
286 | ) -> Result<Vec<Position>> { | ||
287 | let file_id = params.text_document.try_conv_with(&world)?; | ||
288 | let file = world.analysis().file_syntax(file_id); | ||
289 | let line_index = world.analysis().file_line_index(file_id); | ||
290 | let res = params.offsets | ||
291 | .into_iter() | ||
292 | .map_conv_with(&line_index) | ||
293 | .map(|offset| <|>{ | ||
294 | world.analysis().matching_brace(&file, offset).unwrap_or(offset) | ||
295 | }<|>) | ||
296 | .map_conv_with(&line_index) | ||
297 | .collect(); | ||
298 | Ok(res) | ||
299 | }", r" | ||
300 | pub fn handle_find_matching_brace( | ||
301 | world: ServerWorld, | ||
302 | params: req::FindMatchingBraceParams, | ||
303 | ) -> Result<Vec<Position>> { | ||
304 | let file_id = params.text_document.try_conv_with(&world)?; | ||
305 | let file = world.analysis().file_syntax(file_id); | ||
306 | let line_index = world.analysis().file_line_index(file_id); | ||
307 | let res = params.offsets | ||
308 | .into_iter() | ||
309 | .map_conv_with(&line_index) | ||
310 | .map(|offset| world.analysis().matching_brace(&file, offset).unwrap_or(offset)) | ||
311 | .map_conv_with(&line_index) | ||
312 | .collect(); | ||
313 | Ok(res) | ||
314 | }"); | ||
281 | } | 315 | } |
282 | 316 | ||
283 | #[test] | 317 | #[test] |