File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -289,10 +289,12 @@ export function create({
289289 let suffixes = [ ] ;
290290
291291 if ( codeOptions ?. initialIndentLevel ) {
292+ const documentText = document . getText ( ) ;
293+ const lastSuffix = endWithNewLine ( documentText ) ? '}' : '\n}' ;
292294 for ( let i = 0 ; i < codeOptions . initialIndentLevel ; i ++ ) {
293295 if ( i === codeOptions . initialIndentLevel - 1 ) {
294296 prefixes . push ( '_' , '{' ) ;
295- suffixes . unshift ( '}' ) ;
297+ suffixes . unshift ( lastSuffix ) ;
296298 }
297299 else {
298300 prefixes . push ( '_' , '{\n' ) ;
@@ -303,7 +305,7 @@ export function create({
303305 document . uri ,
304306 document . languageId ,
305307 document . version ,
306- prefixes . join ( '' ) + document . getText ( ) + suffixes . join ( '' ) ,
308+ prefixes . join ( '' ) + documentText + suffixes . join ( '' ) ,
307309 ) ;
308310 formatRange = {
309311 start : formatDocument . positionAt ( 0 ) ,
@@ -336,11 +338,12 @@ export function create({
336338 return edits ;
337339
338340 function ensureNewLines ( newText : string ) {
341+ const verifySuffix = endWithNewLine ( newText ) ? '}' : '\n}' ;
339342 const verifyDocument = TextDocument . create (
340343 document . uri ,
341344 document . languageId ,
342345 document . version ,
343- '_ {' + newText + '}' ,
346+ '_ {' + newText + verifySuffix ,
344347 ) ;
345348 const verifyEdits = cssLs . format ( verifyDocument , undefined , formatOptions ) ;
346349 let verifyText = TextDocument . applyEdits ( verifyDocument , verifyEdits ) ;
You can’t perform that action at this time.
0 commit comments