aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-04-07 00:26:22 +0100
committerJonas Schievink <[email protected]>2021-04-07 15:38:04 +0100
commitd75cacc601891eb89318b3c483b3fcfb0535f0f8 (patch)
tree9aecc5905eaf47a04e90819aa24c23766a100920
parent61e292fab1a5c5f3c97ace967268b6197a687ae1 (diff)
Use stdx::always
-rw-r--r--crates/ide/src/typing.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/crates/ide/src/typing.rs b/crates/ide/src/typing.rs
index b0234d7fd..c1bdc51b0 100644
--- a/crates/ide/src/typing.rs
+++ b/crates/ide/src/typing.rs
@@ -79,7 +79,7 @@ fn on_char_typed_inner(file: &SourceFile, offset: TextSize, char_typed: char) ->
79/// Inserts a closing `}` when the user types an opening `{`, wrapping an existing expression in a 79/// Inserts a closing `}` when the user types an opening `{`, wrapping an existing expression in a
80/// block. 80/// block.
81fn on_opening_brace_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> { 81fn on_opening_brace_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
82 assert_eq!(file.syntax().text().char_at(offset), Some('{')); 82 stdx::always!(file.syntax().text().char_at(offset) == Some('{'));
83 let brace_token = file.syntax().token_at_offset(offset).right_biased()?; 83 let brace_token = file.syntax().token_at_offset(offset).right_biased()?;
84 let block = ast::BlockExpr::cast(brace_token.parent()?)?; 84 let block = ast::BlockExpr::cast(brace_token.parent()?)?;
85 85
@@ -90,7 +90,7 @@ fn on_opening_brace_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdi
90 Some(ast::Stmt::ExprStmt(it)) => { 90 Some(ast::Stmt::ExprStmt(it)) => {
91 // Use the expression span to place `}` before the `;` 91 // Use the expression span to place `}` before the `;`
92 it.expr()?.syntax().text_range().end() 92 it.expr()?.syntax().text_range().end()
93 }, 93 }
94 None => block.tail_expr()?.syntax().text_range().end(), 94 None => block.tail_expr()?.syntax().text_range().end(),
95 _ => return None, 95 _ => return None,
96 } 96 }
@@ -103,7 +103,7 @@ fn on_opening_brace_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdi
103/// this works when adding `let =`. 103/// this works when adding `let =`.
104// FIXME: use a snippet completion instead of this hack here. 104// FIXME: use a snippet completion instead of this hack here.
105fn on_eq_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> { 105fn on_eq_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
106 assert_eq!(file.syntax().text().char_at(offset), Some('=')); 106 stdx::always!(file.syntax().text().char_at(offset) == Some('='));
107 let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?; 107 let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?;
108 if let_stmt.semicolon_token().is_some() { 108 if let_stmt.semicolon_token().is_some() {
109 return None; 109 return None;
@@ -125,7 +125,7 @@ fn on_eq_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
125 125
126/// Returns an edit which should be applied when a dot ('.') is typed on a blank line, indenting the line appropriately. 126/// Returns an edit which should be applied when a dot ('.') is typed on a blank line, indenting the line appropriately.
127fn on_dot_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> { 127fn on_dot_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
128 assert_eq!(file.syntax().text().char_at(offset), Some('.')); 128 stdx::always!(file.syntax().text().char_at(offset) == Some('.'));
129 let whitespace = 129 let whitespace =
130 file.syntax().token_at_offset(offset).left_biased().and_then(ast::Whitespace::cast)?; 130 file.syntax().token_at_offset(offset).left_biased().and_then(ast::Whitespace::cast)?;
131 131
@@ -154,7 +154,7 @@ fn on_dot_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
154/// Adds a space after an arrow when `fn foo() { ... }` is turned into `fn foo() -> { ... }` 154/// Adds a space after an arrow when `fn foo() { ... }` is turned into `fn foo() -> { ... }`
155fn on_arrow_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> { 155fn on_arrow_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
156 let file_text = file.syntax().text(); 156 let file_text = file.syntax().text();
157 assert_eq!(file_text.char_at(offset), Some('>')); 157 stdx::always!(file_text.char_at(offset) == Some('>'));
158 let after_arrow = offset + TextSize::of('>'); 158 let after_arrow = offset + TextSize::of('>');
159 if file_text.char_at(after_arrow) != Some('{') { 159 if file_text.char_at(after_arrow) != Some('{') {
160 return None; 160 return None;