|
15 | 15 |
|
16 | 16 | mod on_enter;
|
17 | 17 |
|
| 18 | +use std::iter; |
| 19 | + |
18 | 20 | use ide_db::{base_db::SourceDatabase, FilePosition, RootDatabase};
|
19 | 21 | use span::{Edition, EditionedFileId};
|
20 | 22 | use syntax::{
|
@@ -120,7 +122,8 @@ fn on_opening_delimiter_typed(
|
120 | 122 | '(' => (
|
121 | 123 | ')',
|
122 | 124 | SyntaxKind::L_PAREN,
|
123 |
| - &[ast::Expr::can_cast, ast::Pat::can_cast, ast::Type::can_cast] as &[FilterFn], |
| 125 | + &[ast::Expr::can_cast as FilterFn, ast::Pat::can_cast, ast::Type::can_cast] |
| 126 | + as &[FilterFn], |
124 | 127 | ),
|
125 | 128 | '<' => ('>', SyntaxKind::L_ANGLE, &[ast::Type::can_cast as FilterFn] as &[FilterFn]),
|
126 | 129 | _ => return None,
|
@@ -208,7 +211,18 @@ fn on_delimited_node_typed(
|
208 | 211 | /// this works when adding `let =`.
|
209 | 212 | // FIXME: use a snippet completion instead of this hack here.
|
210 | 213 | fn on_eq_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
|
211 |
| - if !stdx::always!(file.syntax().text().char_at(offset) == Some('=')) { |
| 214 | + let text = file.syntax().text(); |
| 215 | + if !stdx::always!(text.char_at(offset) == Some('=')) { |
| 216 | + return None; |
| 217 | + } |
| 218 | + |
| 219 | + let has_newline = iter::successors(Some(offset), |&offset| Some(offset + TextSize::new(1))) |
| 220 | + .filter_map(|offset| text.char_at(offset)) |
| 221 | + .find(|&c| !c.is_whitespace() || c == '\n') |
| 222 | + == Some('n'); |
| 223 | + // don't attempt to add `;` if there is a newline after the `=`, the intent is likely to write |
| 224 | + // out the expression afterwards! |
| 225 | + if has_newline { |
212 | 226 | return None;
|
213 | 227 | }
|
214 | 228 |
|
@@ -466,6 +480,15 @@ fn foo() {
|
466 | 480 | let foo =$0
|
467 | 481 | let bar = 1;
|
468 | 482 | }
|
| 483 | +", |
| 484 | + ); |
| 485 | + type_char_noop( |
| 486 | + '=', |
| 487 | + r" |
| 488 | +fn foo() { |
| 489 | + let foo =$0 |
| 490 | + 1 + 1 |
| 491 | +} |
469 | 492 | ",
|
470 | 493 | );
|
471 | 494 | }
|
|
0 commit comments