',
position: { line: 0, character: 13 },
expected: '.p-\\[theme\\(spacing\\.4\\)\\] {\n' + ' padding: 1rem /* 16px */;\n' + '}',
expectedRange: {
start: { line: 0, character: 12 },
end: { line: 0, character: 32 },
},
})
testHover('arbitrary property', {
text: '
',
position: { line: 0, character: 13 },
expected: '.\\[text-wrap\\:balance\\] {\n text-wrap: balance;\n}',
expectedRange: {
start: { line: 0, character: 12 },
end: { line: 0, character: 31 },
},
})
testHover('vue `,
position: { line: 2, character: 13 },
expected: '.underline {\n' + ' text-decoration-line: underline;\n' + '}',
expectedRange: {
start: { line: 2, character: 9 },
end: { line: 2, character: 18 },
},
})
testHover('css @source glob expansion', {
exact: true,
lang: 'css',
text: `@source "../{app,components}/**/*.jsx"`,
position: { line: 0, character: 23 },
expected: {
contents: {
kind: 'markdown',
value: [
'**Expansion**',
'```plaintext',
'- ../app/**/*.jsx',
'- ../components/**/*.jsx',
'```',
].join('\n'),
},
range: {
start: { line: 0, character: 8 },
end: { line: 0, character: 38 },
},
},
expectedRange: {
start: { line: 2, character: 9 },
end: { line: 2, character: 18 },
},
})
testHover('css @source not glob expansion', {
exact: true,
lang: 'css',
text: `@source not "../{app,components}/**/*.jsx"`,
position: { line: 0, character: 23 },
expected: {
contents: {
kind: 'markdown',
value: [
'**Expansion**',
'```plaintext',
'- ../app/**/*.jsx',
'- ../components/**/*.jsx',
'```',
].join('\n'),
},
range: {
start: { line: 0, character: 12 },
end: { line: 0, character: 42 },
},
},
expectedRange: {
start: { line: 2, character: 9 },
end: { line: 2, character: 18 },
},
})
testHover('css @source inline glob expansion', {
exact: true,
lang: 'css',
text: `@source inline("{hover:,active:,}m-{1,2,3}")`,
position: { line: 0, character: 23 },
expected: {
contents: {
kind: 'markdown',
value: [
'**Expansion**',
'```plaintext',
'- hover:m-1',
'- hover:m-2',
'- hover:m-3',
'- active:m-1',
'- active:m-2',
'- active:m-3',
'- m-1',
'- m-2',
'- m-3',
'```',
].join('\n'),
},
range: {
start: { line: 0, character: 15 },
end: { line: 0, character: 43 },
},
},
expectedRange: {
start: { line: 2, character: 9 },
end: { line: 2, character: 15 },
},
})
testHover('css @source not inline glob expansion', {
exact: true,
lang: 'css',
text: `@source not inline("{hover:,active:,}m-{1,2,3}")`,
position: { line: 0, character: 23 },
expected: {
contents: {
kind: 'markdown',
value: [
'**Expansion**',
'```plaintext',
'- hover:m-1',
'- hover:m-2',
'- hover:m-3',
'- active:m-1',
'- active:m-2',
'- active:m-3',
'- m-1',
'- m-2',
'- m-3',
'```',
].join('\n'),
},
range: {
start: { line: 0, character: 19 },
end: { line: 0, character: 47 },
},
},
expectedRange: {
start: { line: 2, character: 9 },
end: { line: 2, character: 18 },
},
})
testHover('--theme() works inside @media queries', {
lang: 'tailwindcss',
text: `@media (width>=--theme(--breakpoint-xl)) { .foo { color: red; } }`,
position: { line: 0, character: 23 },
exact: true,
expected: {
contents: {
kind: 'markdown',
value: [
//
'```css',
'@theme {',
' --breakpoint-xl: 80rem /* 1280px */;',
'}',
'```',
].join('\n'),
},
range: {
start: { line: 0, character: 23 },
end: { line: 0, character: 38 },
},
},
})
testHover('@media queries include pixel equivalents', {
text: '
',
position: { line: 0, character: 13 },
expected: '.sm\\:flex {\n @media (width >= 40rem /* 640px */) {\n display: flex;\n }\n}',
expectedRange: {
start: { line: 0, character: 12 },
end: { line: 0, character: 19 },
},
})
testHover('@container queries include pixel equivalents', {
text: '
',
position: { line: 0, character: 13 },
expected:
'.\\@xs\\:flex {\n @container (width >= 20rem /* 320px */) {\n display: flex;\n }\n}',
expectedRange: {
start: { line: 0, character: 12 },
end: { line: 0, character: 20 },
},
})
testHover('named @container queries include pixel equivalents', {
text: '
',
position: { line: 0, character: 13 },
expected:
'.\\@xs\\/named\\:flex {\n @container named (width >= 20rem /* 320px */) {\n display: flex;\n }\n}',
expectedRange: {
start: { line: 0, character: 12 },
end: { line: 0, character: 26 },
},
})
})
withFixture('v4/css-loading-js', (c) => {
async function testHover(name, { text, lang, position, expected, expectedRange, settings }) {
test(name, async ({ expect }) => {
let textDocument = await c.openDocument({ text, lang, settings })
let res = await c.sendRequest('textDocument/hover', {
textDocument,
position,
})
expect(res).toEqual(
expected
? {
contents: {
language: 'css',
value: expected,
},
range: expectedRange,
}
: expected,
)
})
}
testHover('Plugins: ESM', {
text: '
',
position: { line: 0, character: 13 },
expected: '.bg-esm-from-plugin {\n background-color: black;\n}',
expectedRange: {
start: { line: 0, character: 12 },
end: { line: 0, character: 30 },
},
})
testHover('Plugins: CJS', {
text: '
',
position: { line: 0, character: 13 },
expected: '.bg-cjs-from-plugin {\n background-color: black;\n}',
expectedRange: {
start: { line: 0, character: 12 },
end: { line: 0, character: 30 },
},
})
testHover('Plugins: TypeScript', {
text: '
',
position: { line: 0, character: 13 },
expected: '.bg-ts-from-plugin {\n background-color: black;\n}',
expectedRange: {
start: { line: 0, character: 12 },
end: { line: 0, character: 29 },
},
})
testHover('Configs: ESM', {
text: '
',
position: { line: 0, character: 13 },
expected: '.bg-esm-from-config {\n background-color: black;\n}',
expectedRange: {
start: { line: 0, character: 12 },
end: { line: 0, character: 30 },
},
})
testHover('Configs: CJS', {
text: '
',
position: { line: 0, character: 13 },
expected: '.bg-cjs-from-config {\n background-color: black;\n}',
expectedRange: {
start: { line: 0, character: 12 },
end: { line: 0, character: 30 },
},
})
testHover('Configs: TypeScript', {
text: '
',
position: { line: 0, character: 13 },
expected: '.bg-ts-from-config {\n background-color: black;\n}',
expectedRange: {
start: { line: 0, character: 12 },
end: { line: 0, character: 29 },
},
})
})
withFixture('v4/path-mappings', (c) => {
async function testHover(name, { text, lang, position, expected, expectedRange, settings }) {
test(name, async ({ expect }) => {
let textDocument = await c.openDocument({ text, lang, settings })
let res = await c.sendRequest('textDocument/hover', {
textDocument,
position,
})
expect(res).toEqual(
expected
? {
contents: {
language: 'css',
value: expected,
},
range: expectedRange,
}
: expected,
)
})
}
testHover('Mapping: CSS Imports', {
text: '
',
position: { line: 0, character: 13 },
expected:
'.bg-map-a-css {\n background-color: var(--color-map-a-css) /* black = #000000 */;\n}',
expectedRange: {
start: { line: 0, character: 12 },
end: { line: 0, character: 24 },
},
})
testHover('Mapping: Configs', {
text: '
',
position: { line: 0, character: 13 },
expected: '.bg-map-a-config {\n background-color: black;\n}',
expectedRange: {
start: { line: 0, character: 12 },
end: { line: 0, character: 27 },
},
})
testHover('Mapping: Plugins', {
text: '
',
position: { line: 0, character: 13 },
expected: '.bg-map-a-plugin {\n background-color: black;\n}',
expectedRange: {
start: { line: 0, character: 12 },
end: { line: 0, character: 27 },
},
})
})
defineTest({
name: 'Can hover showing theme values used in var(…) and theme(…) functions',
fs: {
'app.css': css`
@import 'tailwindcss';
`,
},
prepare: async ({ root }) => ({ client: await createClient({ root }) }),
handle: async ({ client }) => {
let doc = await client.open({
lang: 'css',
text: css`
.foo {
color: theme(--color-black);
}
.bar {
color: var(--color-black);
}
`,
})
// color: theme(--color-black);
// ^
let hoverTheme = await doc.hover({ line: 1, character: 18 })
// color: var(--color-black);
// ^
let hoverVar = await doc.hover({ line: 4, character: 16 })
expect(hoverTheme).toEqual({
contents: {
kind: 'markdown',
value: [
//
'```css',
'@theme {',
' --color-black: #000;',
'}',
'```',
].join('\n'),
},
range: {
start: { line: 1, character: 15 },
end: { line: 1, character: 28 },
},
})
expect(hoverVar).toEqual({
contents: {
kind: 'markdown',
value: [
//
'```css',
'@theme {',
' --color-black: #000;',
'}',
'```',
].join('\n'),
},
range: {
start: { line: 4, character: 13 },
end: { line: 4, character: 26 },
},
})
},
})