File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1218,14 +1218,10 @@ impl<'a> App<'a> {
12181218 match handle. receiver . try_recv ( ) {
12191219 Ok ( Some ( ( builder, elapsed) ) ) => {
12201220 // Take ownership of wuc_substring from the waiting state.
1221- let wuc =
1222- match std:: mem:: replace ( & mut self . content_mode , ContentMode :: Normal ) {
1223- ContentMode :: TabCompletionWaiting {
1224- wuc_substring,
1225- ..
1226- } => wuc_substring,
1227- _ => unreachable ! ( ) ,
1228- } ;
1221+ let wuc = match std:: mem:: replace ( & mut self . content_mode , ContentMode :: Normal ) {
1222+ ContentMode :: TabCompletionWaiting { wuc_substring, .. } => wuc_substring,
1223+ _ => unreachable ! ( ) ,
1224+ } ;
12291225 self . finish_tab_complete ( builder, wuc, elapsed) ;
12301226 self . on_possible_buffer_change ( ) ;
12311227 return true ;
Original file line number Diff line number Diff line change @@ -1006,7 +1006,8 @@ impl App<'_> {
10061006
10071007 let wuc_substring = completion_context. word_under_cursor . clone ( ) ;
10081008
1009- let ( tx, rx) = std:: sync:: mpsc:: channel :: < Option < ( ActiveSuggestionsBuilder , std:: time:: Duration ) > > ( ) ;
1009+ let ( tx, rx) =
1010+ std:: sync:: mpsc:: channel :: < Option < ( ActiveSuggestionsBuilder , std:: time:: Duration ) > > ( ) ;
10101011
10111012 let completion_context_owned = completion_context. into_owned ( ) ;
10121013
Original file line number Diff line number Diff line change @@ -480,7 +480,19 @@ impl DParser {
480480 {
481481 let depth = nestings. len ( ) ;
482482 self . tokens [ idx] . annotations . opening = Some ( OpeningState :: Unmatched ) ;
483- self . tokens [ idx] . annotations . bracket_depth = Some ( depth) ;
483+
484+ if matches ! (
485+ token. kind,
486+ TokenKind :: If
487+ | TokenKind :: Case
488+ | TokenKind :: For
489+ | TokenKind :: While
490+ | TokenKind :: Until
491+ ) {
492+ // Do not color keywords like bracket tokens
493+ } else {
494+ self . tokens [ idx] . annotations . bracket_depth = Some ( depth) ;
495+ }
484496
485497 if self . current_command_range . is_none ( ) {
486498 self . current_command_range = Some ( idx..=idx) ;
@@ -515,7 +527,15 @@ impl DParser {
515527 opening_idx,
516528 is_auto_inserted : false ,
517529 } ) ;
518- self . tokens [ idx] . annotations . bracket_depth = Some ( depth) ;
530+
531+ if matches ! (
532+ token. kind,
533+ TokenKind :: Fi | TokenKind :: Done | TokenKind :: Esac
534+ ) {
535+ // Do not color keywords like bracket tokens
536+ } else {
537+ self . tokens [ idx] . annotations . bracket_depth = Some ( depth) ;
538+ }
519539
520540 let current_command_range_contains_cursor =
521541 cursor_byte_pos. is_some_and ( |pos| {
@@ -2426,3 +2446,22 @@ mod tests {
24262446 }
24272447 }
24282448}
2449+
2450+ #[ cfg( test) ]
2451+ mod test_keyword_bracket_color {
2452+ use super :: * ;
2453+
2454+ #[ test]
2455+ fn test_keywords_have_no_bracket_depth ( ) {
2456+ let mut parser = DParser :: from ( "if true; then echo hi; while true; do echo; done; fi" ) ;
2457+ parser. walk_to_end ( ) ;
2458+ for token in parser. tokens ( ) {
2459+ if matches ! (
2460+ token. token. kind,
2461+ TokenKind :: If | TokenKind :: Fi | TokenKind :: While | TokenKind :: Done
2462+ ) {
2463+ assert_eq ! ( token. annotations. bracket_depth, None ) ;
2464+ }
2465+ }
2466+ }
2467+ }
You can’t perform that action at this time.
0 commit comments