Skip to content

Allow hover over --theme(…) function in @media rule without spaces #1172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions packages/tailwindcss-language-server/tests/hover/hover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,24 @@ withFixture('basic', (c) => {
},
},
})

testHover('theme() works inside @media queries', {
lang: 'tailwindcss',
text: `@media (width>=theme(screens.xl)) { .foo { color: red; } }`,
position: { line: 0, character: 21 },

exact: true,
expected: {
contents: {
kind: 'markdown',
value: ['```plaintext', '1280px', '```'].join('\n'),
},
range: {
start: { line: 0, character: 21 },
end: { line: 0, character: 31 },
},
},
})
})

withFixture('v4/basic', (c) => {
Expand Down Expand Up @@ -272,6 +290,24 @@ withFixture('v4/basic', (c) => {
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: ['```plaintext', '80rem /* 1280px */', '```'].join('\n'),
},
range: {
start: { line: 0, character: 23 },
end: { line: 0, character: 38 },
},
},
})
})

withFixture('v4/css-loading-js', (c) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/tailwindcss-language-service/src/util/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export function findHelperFunctionsInRange(
): DocumentHelperFunction[] {
const text = getTextWithoutComments(doc, 'css', range)
let matches = findAll(
/(?<prefix>[\s:;/*(){}])(?<helper>config|theme|--theme)(?<innerPrefix>\(\s*)(?<path>[^)]*?)\s*\)/g,
/(?<prefix>[\W])(?<helper>config|theme|--theme)(?<innerPrefix>\(\s*)(?<path>[^)]*?)\s*\)/g,
text,
)

Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-tailwindcss/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Prerelease

- Nothing yet!
- Ensure hover information for `theme(…)` and other functions are shown when used in `@media` queries ([#1172](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1172))

## 0.14.3

Expand Down