Skip to content

Improve CSS completions #1165

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
merged 6 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
11 changes: 10 additions & 1 deletion packages/tailwindcss-language-server/src/language/cssServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ function replace(delta = 0) {
return `@media(${MEDIA_MARKER})${' '.repeat(p1.length + delta)}{`
}
}
function replaceWithStyleRule(delta = 0) {
return (_match: string, p1: string) => {
let spaces = ' '.repeat(p1.length + delta)
return `.foo${spaces}{`
}
}

function createVirtualCssDocument(textDocument: TextDocument): TextDocument {
let content = textDocument
Expand All @@ -347,6 +353,9 @@ function createVirtualCssDocument(textDocument: TextDocument): TextDocument {
.replace(/@screen(\s+[^{]+){/g, replace(-2))
.replace(/@variants(\s+[^{]+){/g, replace())
.replace(/@responsive(\s*){/g, replace())
.replace(/@utility(\s+[^{]+){/g, replaceWithStyleRule())
.replace(/@custom-variant(\s+[^{]+){/g, replaceWithStyleRule())
.replace(/@variant(\s+[^{]+){/g, replaceWithStyleRule())
.replace(/@layer(\s+[^{]{2,}){/g, replace(-3))
.replace(/@reference\s*([^;]{2,})/g, '@import $1')
.replace(
Expand Down Expand Up @@ -401,7 +410,7 @@ async function validateTextDocument(textDocument: TextDocument): Promise<void> {
.filter((diagnostic) => {
if (
diagnostic.code === 'unknownAtRules' &&
/Unknown at rule @(tailwind|apply|config|theme|plugin|source|utility|variant|custom-variant)/.test(
/Unknown at rule @(tailwind|apply|config|theme|plugin|source|utility|variant|custom-variant|slot)/.test(
diagnostic.message,
)
) {
Expand Down
4 changes: 4 additions & 0 deletions packages/vscode-tailwindcss/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
- Allow v4.0 projects not installed with npm to use IntelliSense ([#1157](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1157))
- Ignore preprocessor files when looking for v4 configs ([#1159](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1159))
- Allow language service to be used in native ESM environments ([#1122](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1122))
- Support property and variable completions inside `@utility` ([#1165](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1165))
- Support style-rule like completions inside `@custom-variant` ([#1165](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1165))
- Support style-rule like completions inside `@variant` ([#1165](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1165))
- Make sure `@slot` isn't considered an unknown at-rule ([#1165](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1165))

## 0.14.2

Expand Down