Skip to content

Commit 89f015e

Browse files
Simplify multiline check
1 parent dd1832c commit 89f015e

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

crates/ide/src/typing/on_enter.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
//! Handles the `Enter` key press. At the momently, this only continues
22
//! comments, but should handle indent some time in the future as well.
33
4-
use std::sync::Arc;
5-
4+
use ide_db::base_db::{FilePosition, SourceDatabase};
65
use ide_db::RootDatabase;
7-
use ide_db::{
8-
base_db::{FilePosition, SourceDatabase},
9-
line_index::LineIndex,
10-
LineIndexDatabase,
11-
};
126
use syntax::{
137
algo::find_node_at_offset,
148
ast::{self, edit::IndentLevel, AstToken},
@@ -55,7 +49,7 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<Text
5549
if token.kind() == L_CURLY {
5650
// Typing enter after the `{` of a block expression, where the `}` is on the same line
5751
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))
5953
{
6054
return Some(edit);
6155
}
@@ -103,18 +97,10 @@ fn on_enter_in_comment(
10397
Some(edit)
10498
}
10599

106-
fn on_enter_in_block(
107-
db: &RootDatabase,
108-
block: ast::BlockExpr,
109-
position: FilePosition,
110-
) -> Option<TextEdit> {
100+
fn on_enter_in_block(block: ast::BlockExpr, position: FilePosition) -> Option<TextEdit> {
111101
let contents = block_contents(&block)?;
112102

113-
let line_index: Arc<LineIndex> = db.line_index(position.file_id);
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 {
103+
if block.syntax().text().contains_char('\n') {
118104
return None;
119105
}
120106

0 commit comments

Comments
 (0)