Skip to content

Commit a4cee91

Browse files
committed
Expose source locations to the language server
1 parent 0e77b83 commit a4cee91

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

packages/tailwindcss/src/design-system.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { Utilities, createUtilities, withAlpha } from './utilities'
2424
import { DefaultMap } from './utils/default-map'
2525
import { extractUsedVariables } from './utils/variables'
2626
import { Variants, createVariants, substituteAtVariant } from './variants'
27+
import { WalkAction, walk } from './walk'
2728

2829
export const enum CompileAstFlags {
2930
None = 0,
@@ -65,7 +66,7 @@ export type DesignSystem = {
6566
storage: Record<symbol, unknown>
6667
}
6768

68-
export function buildDesignSystem(theme: Theme): DesignSystem {
69+
export function buildDesignSystem(theme: Theme, utilitiesNode?: AstNode | null): DesignSystem {
6970
let utilities = createUtilities(theme)
7071
let variants = createVariants(theme)
7172

@@ -122,6 +123,17 @@ export function buildDesignSystem(theme: Theme): DesignSystem {
122123
},
123124
})
124125

126+
if (utilitiesNode) {
127+
walk(astNodes, (node) => {
128+
// We do this conditionally to preserve source locations from both
129+
// `@utility` and `@custom-variant`. Even though generated nodes are
130+
// cached this should be fine because `utilitiesNode.src` should not
131+
// change without a full rebuild which destroys the cache.
132+
node.src ??= utilitiesNode.src
133+
return WalkAction.Continue
134+
})
135+
}
136+
125137
// Disable all polyfills to not unnecessarily pollute IntelliSense output
126138
astNodes = optimizeAst(astNodes, designSystem, Polyfills.None)
127139

packages/tailwindcss/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ async function parseCss(
595595
}
596596
})
597597

598-
let designSystem = buildDesignSystem(theme)
598+
let designSystem = buildDesignSystem(theme, utilitiesNode)
599599

600600
if (important) {
601601
designSystem.important = important
@@ -855,7 +855,7 @@ export async function compile(
855855
}
856856

857857
export async function __unstable__loadDesignSystem(css: string, opts: CompileOptions = {}) {
858-
let result = await parseCss(CSS.parse(css), opts)
858+
let result = await parseCss(CSS.parse(css, { from: opts.from }), opts)
859859
return result.designSystem
860860
}
861861

0 commit comments

Comments
 (0)