@@ -2,7 +2,6 @@ import type { DesignSystem } from 'tailwindcss-language-service/src/util/v4'
22
33import postcss from 'postcss'
44import postcssImport from 'postcss-import'
5- import { format } from 'prettier'
65
76const resolveImports = postcss ( [ postcssImport ( ) ] )
87
@@ -61,26 +60,38 @@ export async function loadDesignSystem(
6160 // return str
6261 // })
6362
64- // Reformat with Prettier
65- let opts = {
66- parser : 'css' ,
67- singleQuote : true ,
68- trailingComma : 'all' ,
69- filepath : 'input.css' ,
70- }
71-
63+ // TODO: Formatting with prettier would be preferable, but it's too slow
64+ // Need to figure out why and if we can make it faster
7265 css = css . map ( ( str ) => {
7366 if ( ! str ) return null
74- try {
75- return format ( str , opts ) . trim ( )
76- } catch { }
77- return str
67+
68+ let lines = str
69+ //
70+ . replaceAll ( '{' , ' {\n' )
71+ . replaceAll ( ';' , ' ;\n' )
72+ . replaceAll ( '}' , ' }\n' )
73+ . split ( '\n' )
74+
75+ let depth = 0
76+
77+ for ( let i = 0 ; i < lines . length ; ++ i ) {
78+ let line = lines [ i ]
79+ if ( line . includes ( '}' ) ) depth --
80+ let indent = ' ' . repeat ( depth )
81+ line = indent + line
82+ if ( line . includes ( '{' ) ) depth ++
83+ lines [ i ] = line
84+ }
85+
86+ return lines . join ( '\n' )
7887 } )
7988
80- return css . map ( ( str ) => {
89+ let root = css . map ( ( str ) => {
8190 if ( str === null ) return postcss . root ( )
8291 return postcss . parse ( str )
8392 } )
93+
94+ return root
8495 } ,
8596
8697 toCss ( nodes : postcss . Root | postcss . Node [ ] ) : string {
0 commit comments