@@ -364,6 +364,10 @@ fn apply_comment_start_spacing(
364364 token : & LuaSyntaxToken ,
365365 syntax_id : LuaSyntaxId ,
366366) {
367+ if comment_start_looks_like_spaced_long_comment ( token) {
368+ return ;
369+ }
370+
367371 if let Some ( replacement) = normalized_comment_prefix ( ctx, token. text ( ) ) {
368372 spacing. add_token_replace ( syntax_id, replacement) ;
369373 spacing. add_token_right_expected ( syntax_id, TokenSpacingExpected :: Space ( 0 ) ) ;
@@ -457,6 +461,27 @@ fn get_prev_sibling_token_without_space(token: &LuaSyntaxToken) -> Option<LuaSyn
457461 None
458462}
459463
464+ fn comment_start_looks_like_spaced_long_comment ( token : & LuaSyntaxToken ) -> bool {
465+ if token. kind ( ) . to_token ( ) != LuaTokenKind :: TkNormalStart || token. text ( ) != "--" {
466+ return false ;
467+ }
468+
469+ let mut current = token. next_token ( ) ;
470+ let mut saw_whitespace = false ;
471+ while let Some ( next) = current {
472+ match next. kind ( ) . to_token ( ) {
473+ LuaTokenKind :: TkWhitespace => {
474+ saw_whitespace = true ;
475+ current = next. next_token ( ) ;
476+ }
477+ LuaTokenKind :: TkEndOfLine => return false ,
478+ _ => return saw_whitespace && next. text ( ) . starts_with ( '[' ) ,
479+ }
480+ }
481+
482+ false
483+ }
484+
460485fn normalized_comment_prefix ( ctx : & FormatContext , prefix_text : & str ) -> Option < String > {
461486 match dash_prefix_len ( prefix_text) {
462487 2 => Some ( if ctx. config . comments . space_after_comment_dash {
@@ -652,6 +677,22 @@ mod tests {
652677 ) ;
653678 }
654679
680+ #[ test]
681+ fn test_spacing_does_not_normalize_spaced_long_comment_prefix ( ) {
682+ let config = LuaFormatConfig :: default ( ) ;
683+ let tree = LuaParser :: parse (
684+ "-- [[ not a long comment ]]\n " ,
685+ ParserConfig :: with_level ( LuaLanguageLevel :: Lua54 ) ,
686+ ) ;
687+ let chunk = tree. get_chunk_node ( ) ;
688+ let spacing = analyze_root_spacing ( & FormatContext :: new ( & config) , & chunk) . spacing ;
689+ let start = find_token ( & chunk, LuaTokenKind :: TkNormalStart ) ;
690+ let start_id = LuaSyntaxId :: from_token ( & start) ;
691+
692+ assert_eq ! ( spacing. token_replace( start_id) , None ) ;
693+ assert_eq ! ( spacing. right_expected( start_id) , None ) ;
694+ }
695+
655696 #[ test]
656697 fn test_spacing_collects_doc_prefix_replacement ( ) {
657698 let config = LuaFormatConfig :: default ( ) ;
0 commit comments