Skip to content

Commit c3c1755

Browse files
committed
Remove custom AST pretty printer
This won’t be necessary as the alpha now always pretty prints an AST
1 parent e871015 commit c3c1755

File tree

2 files changed

+7
-55
lines changed

2 files changed

+7
-55
lines changed

packages/tailwindcss-language-server/src/util/v4/design-system.ts

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -60,64 +60,13 @@ export async function loadDesignSystem(
6060
// return str
6161
// })
6262

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
6563
let roots = css.map((str) => {
6664
if (str === null) return postcss.root()
6765

68-
let result = ''
69-
for (let i = 0; i < str.length; ++i) {
70-
if (str[i] === '\\') {
71-
result += str[i] + str[i + 1]
72-
i += 1
73-
} else if (str[i] === '"') {
74-
let end = str.indexOf('"', i + 1)
75-
result += str.slice(i, end + 1)
76-
i = end
77-
} else if (str[i] === "'") {
78-
let end = str.indexOf("'", i + 1)
79-
result += str.slice(i, end + 1)
80-
i = end
81-
} else if (str[i] === '{') {
82-
result += ' {\n'
83-
} else if (str[i] === '}') {
84-
result += '}\n'
85-
} else if (str[i] === ';') {
86-
result += ';\n'
87-
} else if (str[i] === ':') {
88-
let prev = str.charCodeAt(i - 1)
89-
if (
90-
(prev >= 65 && prev <= 90) ||
91-
(prev >= 97 && prev <= 122) ||
92-
(prev >= 48 && prev <= 57)
93-
) {
94-
result += ': '
95-
} else {
96-
result += ':'
97-
}
98-
} else {
99-
result += str[i]
100-
}
101-
}
102-
103-
let lines = result.split('\n')
104-
105-
let depth = 0
106-
107-
for (let i = 0; i < lines.length; ++i) {
108-
let line = lines[i]
109-
if (line.includes('}')) depth--
110-
let indent = ' '.repeat(Math.max(0, depth))
111-
lines[i] = indent + line
112-
if (line.includes('{')) depth++
113-
}
114-
115-
let pretty = lines.join('\n').trim()
116-
11766
try {
118-
return postcss.parse(pretty)
119-
} catch {
12067
return postcss.parse(str)
68+
} catch {
69+
return null
12170
}
12271
})
12372

packages/tailwindcss-language-service/src/util/jit.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ export async function stringifyRoot(state: State, root: Root, uri?: string): Pro
4747
css = addPixelEquivalentsToCss(css, settings.tailwindCSS.rootFontSize)
4848
}
4949

50+
let identSize = state.v4 ? 2 : 4
51+
let identPattern = state.v4 ? /^(?: )+/gm : /^(?: )+/gm
52+
5053
return css
5154
.replace(/([^;{}\s])(\n\s*})/g, (_match, before, after) => `${before};${after}`)
52-
.replace(/^(?: )+/gm, (indent: string) =>
53-
' '.repeat((indent.length / 4) * settings.editor.tabSize)
55+
.replace(identPattern, (indent: string) =>
56+
' '.repeat((indent.length / identSize) * settings.editor.tabSize)
5457
)
5558
}
5659

0 commit comments

Comments
 (0)