Skip to content

Commit

Permalink
Handle postcss throwing when parsing more complex files (#1043)
Browse files Browse the repository at this point in the history
Fixes: #1033
Fixes: #1034 
Fixes: #1035 
Fixes: #1036 
Fixes: #1037 
Fixes: #1038 
Fixes: #1039 
Fixes: #1040
Fixes: #1041
Fixes: #1042 
Fixes: tailwindlabs/tailwindcss#14274

When we worked on #1030, we added a new `postcss` run inside the project
locator. Unfortunately this can crash (e.g. when non standard CSS
features are discovered like those in a `.sass` or `.scss` file) which
currently breaks the whole project locator step, making the extension
not work anymore as soon as such a file is detected.

The short term fix here is to handle this error. In the very future we
have to replace this postcss step anyways because now that Tailwind v4
supports plugins and JS config files, we need to be able to execute the
config to get the proper sources.

## Before

<img width="659" alt="before"
src="https://github.com/user-attachments/assets/8f86e70d-66c2-40a1-ba97-9f4b9b018c94">

## After

<img width="656" alt="after"
src="https://github.com/user-attachments/assets/bfd17b72-c748-4ea9-b73d-86c444cda16a">
  • Loading branch information
philipp-spiess authored Aug 28, 2024
1 parent 5e308e8 commit cb09921
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 14 additions & 10 deletions packages/tailwindcss-language-server/src/project-locator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,17 +615,21 @@ class FileEntry {
}

async resolveSourceDirectives() {
if (this.sources.length > 0) {
return
}
try {
if (this.sources.length > 0) {
return
}

// Note: This should eventually use the DesignSystem to extract the same
// sources also discovered by tailwind. Since we don't have everything yet
// to initialize the design system though, we set up a simple postcss at
// rule exporter instead for now.
await postcss([extractSourceDirectives(this.sources)]).process(this.content, {
from: this.realpath,
})
// Note: This should eventually use the DesignSystem to extract the same
// sources also discovered by tailwind. Since we don't have everything yet
// to initialize the design system though, we set up a simple postcss at
// rule exporter instead for now.
await postcss([extractSourceDirectives(this.sources)]).process(this.content, {
from: this.realpath,
})
} catch (err) {
//
}
}

/**
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!
- Fix an issue that caused the language server for any project with a non-standard CSS file to crash ([#1030](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1030))

## 0.12.7

Expand Down

0 comments on commit cb09921

Please sign in to comment.