@@ -28,7 +28,8 @@ export class DocumentFormattingEditProvider implements vscode.DocumentFormatting
2828 let jsScript = false ;
2929 let sql = false ;
3030 let sqlParens = 0 ;
31- for ( let i = 0 ; i < document . lineCount ; i ++ ) {
31+ const lineFrom = isClass ? 0 : 1 ; // just skip ROUTINE header
32+ for ( let i = lineFrom ; i < document . lineCount ; i ++ ) {
3233 const line = document . lineAt ( i ) ;
3334 const text = this . stripLineComments ( line . text ) ;
3435
@@ -40,7 +41,7 @@ export class DocumentFormattingEditProvider implements vscode.DocumentFormatting
4041 jsScript = true ;
4142 }
4243
43- if ( text . match ( "& sql" ) ) {
44+ if ( text . match ( / ( & | # # ) s q l / i ) ) {
4445 sql = true ;
4546 sqlParens = 0 ;
4647 }
@@ -184,8 +185,10 @@ export class DocumentFormattingEditProvider implements vscode.DocumentFormatting
184185 const newText = line . text
185186 . replace ( / " (?: " " | [ ^ " ] ) * " | \/ \* .* \* \/ | \/ \/ + .* | # # ; .* / g, toKeep )
186187 . replace ( / (?< = ^ \s | { | } ) ( \s * ) ( \b ( [ a - z ] + ) \b ) / gi, formatCommand )
187- . replace ( / ( [ { } ] ) (? ! \s | $ ) / g, "$1 " )
188- . replace ( / (?< ! \s ) ( [ { } ] ) / g, " $1" )
188+ . replace ( / { (? ! \s | } | $ ) / g, "{ " )
189+ . replace ( / } (? ! \s | \. | $ ) / g, "} " )
190+ . replace ( / (?< ! \s | { ) } / g, " }" )
191+ . replace ( / (?< ! \s ) { / g, " {" )
189192 . replace ( new RegExp ( restorePattern . join ( "|" ) , "g" ) , toRestore ) ;
190193
191194 if ( newText != line . text ) {
0 commit comments