diff options
Diffstat (limited to 'crates/ide/src/typing')
-rw-r--r-- | crates/ide/src/typing/on_enter.rs | 22 |
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 | ||
4 | use std::sync::Arc; | 4 | use ide_db::base_db::{FilePosition, SourceDatabase}; |
5 | |||
6 | use ide_db::RootDatabase; | 5 | use ide_db::RootDatabase; |
7 | use ide_db::{ | ||
8 | base_db::{FilePosition, SourceDatabase}, | ||
9 | line_index::LineIndex, | ||
10 | LineIndexDatabase, | ||
11 | }; | ||
12 | use syntax::{ | 6 | use 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 | ||
106 | fn on_enter_in_block( | 100 | fn 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 | ||