@@ -58,9 +58,13 @@ pub(crate) fn on_char_typed(
5858 position : FilePosition ,
5959 char_typed : char ,
6060) -> Option < SourceChange > {
61- assert ! ( TRIGGER_CHARS . contains( char_typed) ) ;
61+ if !stdx:: always!( TRIGGER_CHARS . contains( char_typed) ) {
62+ return None ;
63+ }
6264 let file = & db. parse ( position. file_id ) ;
63- assert_eq ! ( file. tree( ) . syntax( ) . text( ) . char_at( position. offset) , Some ( char_typed) ) ;
65+ if !stdx:: always!( file. tree( ) . syntax( ) . text( ) . char_at( position. offset) == Some ( char_typed) ) {
66+ return None ;
67+ }
6468 let edit = on_char_typed_inner ( file, position. offset , char_typed) ?;
6569 Some ( SourceChange :: from_text_edit ( position. file_id , edit) )
6670}
@@ -70,7 +74,9 @@ fn on_char_typed_inner(
7074 offset : TextSize ,
7175 char_typed : char ,
7276) -> Option < TextEdit > {
73- assert ! ( TRIGGER_CHARS . contains( char_typed) ) ;
77+ if !stdx:: always!( TRIGGER_CHARS . contains( char_typed) ) {
78+ return None ;
79+ }
7480 match char_typed {
7581 '.' => on_dot_typed ( & file. tree ( ) , offset) ,
7682 '=' => on_eq_typed ( & file. tree ( ) , offset) ,
@@ -83,7 +89,9 @@ fn on_char_typed_inner(
8389/// Inserts a closing `}` when the user types an opening `{`, wrapping an existing expression in a
8490/// block.
8591fn on_opening_brace_typed ( file : & Parse < SourceFile > , offset : TextSize ) -> Option < TextEdit > {
86- stdx:: always!( file. tree( ) . syntax( ) . text( ) . char_at( offset) == Some ( '{' ) ) ;
92+ if !stdx:: always!( file. tree( ) . syntax( ) . text( ) . char_at( offset) == Some ( '{' ) ) {
93+ return None ;
94+ }
8795
8896 let brace_token = file. tree ( ) . syntax ( ) . token_at_offset ( offset) . right_biased ( ) ?;
8997
@@ -120,7 +128,9 @@ fn on_opening_brace_typed(file: &Parse<SourceFile>, offset: TextSize) -> Option<
120128/// this works when adding `let =`.
121129// FIXME: use a snippet completion instead of this hack here.
122130fn on_eq_typed ( file : & SourceFile , offset : TextSize ) -> Option < TextEdit > {
123- stdx:: always!( file. syntax( ) . text( ) . char_at( offset) == Some ( '=' ) ) ;
131+ if !stdx:: always!( file. syntax( ) . text( ) . char_at( offset) == Some ( '=' ) ) {
132+ return None ;
133+ }
124134 let let_stmt: ast:: LetStmt = find_node_at_offset ( file. syntax ( ) , offset) ?;
125135 if let_stmt. semicolon_token ( ) . is_some ( ) {
126136 return None ;
@@ -142,7 +152,9 @@ fn on_eq_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
142152
143153/// Returns an edit which should be applied when a dot ('.') is typed on a blank line, indenting the line appropriately.
144154fn on_dot_typed ( file : & SourceFile , offset : TextSize ) -> Option < TextEdit > {
145- stdx:: always!( file. syntax( ) . text( ) . char_at( offset) == Some ( '.' ) ) ;
155+ if !stdx:: always!( file. syntax( ) . text( ) . char_at( offset) == Some ( '.' ) ) {
156+ return None ;
157+ }
146158 let whitespace =
147159 file. syntax ( ) . token_at_offset ( offset) . left_biased ( ) . and_then ( ast:: Whitespace :: cast) ?;
148160
@@ -171,7 +183,9 @@ fn on_dot_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
171183/// Adds a space after an arrow when `fn foo() { ... }` is turned into `fn foo() -> { ... }`
172184fn on_arrow_typed ( file : & SourceFile , offset : TextSize ) -> Option < TextEdit > {
173185 let file_text = file. syntax ( ) . text ( ) ;
174- stdx:: always!( file_text. char_at( offset) == Some ( '>' ) ) ;
186+ if !stdx:: always!( file_text. char_at( offset) == Some ( '>' ) ) {
187+ return None ;
188+ }
175189 let after_arrow = offset + TextSize :: of ( '>' ) ;
176190 if file_text. char_at ( after_arrow) != Some ( '{' ) {
177191 return None ;
0 commit comments