@@ -149,19 +149,16 @@ export class LineFormatter {
149149 this . builder . append ( '*' ) ;
150150 return ;
151151 }
152+ if ( this . handleStarOperator ( t , prev ) ) {
153+ return ;
154+ }
152155 break ;
153156 default :
154157 break ;
155158 }
156159 } else if ( t . length === 2 ) {
157160 if ( this . text . charCodeAt ( t . start ) === Char . Asterisk && this . text . charCodeAt ( t . start + 1 ) === Char . Asterisk ) {
158- if ( ! prev || ( prev . type !== TokenType . Identifier && prev . type !== TokenType . Number ) ) {
159- this . builder . append ( '**' ) ;
160- return ;
161- }
162- if ( prev && this . isKeyword ( prev , 'lambda' ) ) {
163- this . builder . softAppendSpace ( ) ;
164- this . builder . append ( '**' ) ;
161+ if ( this . handleStarOperator ( t , prev ) ) {
165162 return ;
166163 }
167164 }
@@ -185,6 +182,28 @@ export class LineFormatter {
185182 this . builder . softAppendSpace ( ) ;
186183 }
187184
185+ private handleStarOperator ( current : IToken , prev : IToken ) : boolean {
186+ if ( this . text . charCodeAt ( current . start ) === Char . Asterisk && this . text . charCodeAt ( current . start + 1 ) === Char . Asterisk ) {
187+ if ( ! prev || ( prev . type !== TokenType . Identifier && prev . type !== TokenType . Number ) ) {
188+ this . builder . append ( '**' ) ;
189+ return true ;
190+ }
191+ if ( prev && this . isKeyword ( prev , 'lambda' ) ) {
192+ this . builder . softAppendSpace ( ) ;
193+ this . builder . append ( '**' ) ;
194+ return true ;
195+ }
196+ }
197+ // Check previous line for the **/* condition
198+ const lastLine = this . getPreviousLineTokens ( ) ;
199+ const lastToken = lastLine && lastLine . count > 0 ? lastLine . getItemAt ( lastLine . count - 1 ) : undefined ;
200+ if ( lastToken && ( this . isOpenBraceType ( lastToken . type ) || lastToken . type === TokenType . Comma ) ) {
201+ this . builder . append ( this . text . substring ( current . start , current . end ) ) ;
202+ return true ;
203+ }
204+ return false ;
205+ }
206+
188207 private handleEqual ( t : IToken , index : number ) : void {
189208 if ( this . isMultipleStatements ( index ) && ! this . braceCounter . isOpened ( TokenType . OpenBrace ) ) {
190209 // x = 1; x, y = y, x
@@ -411,4 +430,12 @@ export class LineFormatter {
411430 }
412431 return - 1 ;
413432 }
433+
434+ private getPreviousLineTokens ( ) : ITextRangeCollection < IToken > | undefined {
435+ if ( ! this . document || this . lineNumber === 0 ) {
436+ return undefined ; // unable to determine
437+ }
438+ const line = this . document . lineAt ( this . lineNumber - 1 ) ;
439+ return new Tokenizer ( ) . tokenize ( line . text ) ;
440+ }
414441}
0 commit comments