aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/typing
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-04-12 20:41:44 +0100
committerJonas Schievink <[email protected]>2021-04-12 20:41:44 +0100
commit89f015ead9ed947d81eecb6e7533f0b8e5f4ed54 (patch)
tree18e1ae1da42b12c2e2122f0aa22a9506cce7aca3 /crates/ide/src/typing
parentdd1832c01661e19b8fc4da1111c0263468144ef2 (diff)
Simplify multiline check
Diffstat (limited to 'crates/ide/src/typing')
-rw-r--r--crates/ide/src/typing/on_enter.rs22
1 files changed, 4 insertions, 18 deletions
diff --git a/crates/ide/src/typing/on_enter.rs b/crates/ide/src/typing/on_enter.rs
index 9a0696c6c..2a0d50098 100644
--- a/crates/ide/src/typing/on_enter.rs
+++ b/crates/ide/src/typing/on_enter.rs
@@ -1,14 +1,8 @@
1//! Handles the `Enter` key press. At the momently, this only continues 1//! Handles the `Enter` key press. At the momently, this only continues
2//! comments, but should handle indent some time in the future as well. 2//! comments, but should handle indent some time in the future as well.
3 3
4use std::sync::Arc; 4use ide_db::base_db::{FilePosition, SourceDatabase};
5
6use ide_db::RootDatabase; 5use ide_db::RootDatabase;
7use ide_db::{
8 base_db::{FilePosition, SourceDatabase},
9 line_index::LineIndex,
10 LineIndexDatabase,
11};
12use syntax::{ 6use syntax::{
13 algo::find_node_at_offset, 7 algo::find_node_at_offset,
14 ast::{self, edit::IndentLevel, AstToken}, 8 ast::{self, edit::IndentLevel, AstToken},
@@ -55,7 +49,7 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<Text
55 if token.kind() == L_CURLY { 49 if token.kind() == L_CURLY {
56 // Typing enter after the `{` of a block expression, where the `}` is on the same line 50 // Typing enter after the `{` of a block expression, where the `}` is on the same line
57 if let Some(edit) = find_node_at_offset(file.syntax(), position.offset - TextSize::of('{')) 51 if let Some(edit) = find_node_at_offset(file.syntax(), position.offset - TextSize::of('{'))
58 .and_then(|block| on_enter_in_block(db, block, position)) 52 .and_then(|block| on_enter_in_block(block, position))
59 { 53 {
60 return Some(edit); 54 return Some(edit);
61 } 55 }
@@ -103,18 +97,10 @@ fn on_enter_in_comment(
103 Some(edit) 97 Some(edit)
104} 98}
105 99
106fn on_enter_in_block( 100fn on_enter_in_block(block: ast::BlockExpr, position: FilePosition) -> Option<TextEdit> {
107 db: &RootDatabase,
108 block: ast::BlockExpr,
109 position: FilePosition,
110) -> Option<TextEdit> {
111 let contents = block_contents(&block)?; 101 let contents = block_contents(&block)?;
112 102
113 let line_index: Arc<LineIndex> = db.line_index(position.file_id); 103 if block.syntax().text().contains_char('\n') {
114 let (open, close) = (block.l_curly_token()?, block.r_curly_token()?);
115 let start = line_index.line_col(open.text_range().start()).line;
116 let end = line_index.line_col(close.text_range().end()).line;
117 if start != end {
118 return None; 104 return None;
119 } 105 }
120 106