|
1 | 1 | //! Handles the `Enter` key press. At the momently, this only continues
|
2 | 2 | //! comments, but should handle indent some time in the future as well.
|
3 | 3 |
|
4 |
| -use std::sync::Arc; |
5 |
| - |
| 4 | +use ide_db::base_db::{FilePosition, SourceDatabase}; |
6 | 5 | use ide_db::RootDatabase;
|
7 |
| -use ide_db::{ |
8 |
| - base_db::{FilePosition, SourceDatabase}, |
9 |
| - line_index::LineIndex, |
10 |
| - LineIndexDatabase, |
11 |
| -}; |
12 | 6 | use syntax::{
|
13 | 7 | algo::find_node_at_offset,
|
14 | 8 | ast::{self, edit::IndentLevel, AstToken},
|
@@ -55,7 +49,7 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<Text
|
55 | 49 | if token.kind() == L_CURLY {
|
56 | 50 | // Typing enter after the `{` of a block expression, where the `}` is on the same line
|
57 | 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 | 54 | return Some(edit);
|
61 | 55 | }
|
@@ -103,18 +97,10 @@ fn on_enter_in_comment(
|
103 | 97 | Some(edit)
|
104 | 98 | }
|
105 | 99 |
|
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> { |
111 | 101 | let contents = block_contents(&block)?;
|
112 | 102 |
|
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') { |
118 | 104 | return None;
|
119 | 105 | }
|
120 | 106 |
|
|
0 commit comments