From cb0992178b6a775270c7640974e51d11d94541ab Mon Sep 17 00:00:00 2001 From: Philipp Spiess Date: Wed, 28 Aug 2024 11:09:10 +0200 Subject: [PATCH] Handle postcss throwing when parsing more complex files (#1043) Fixes: #1033 Fixes: #1034 Fixes: #1035 Fixes: #1036 Fixes: #1037 Fixes: #1038 Fixes: #1039 Fixes: #1040 Fixes: #1041 Fixes: #1042 Fixes: https://github.com/tailwindlabs/tailwindcss/discussions/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 before ## After after --- .../src/project-locator.ts | 24 +++++++++++-------- packages/vscode-tailwindcss/CHANGELOG.md | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/tailwindcss-language-server/src/project-locator.ts b/packages/tailwindcss-language-server/src/project-locator.ts index 50c3d426..9e39f67d 100644 --- a/packages/tailwindcss-language-server/src/project-locator.ts +++ b/packages/tailwindcss-language-server/src/project-locator.ts @@ -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) { + // + } } /** diff --git a/packages/vscode-tailwindcss/CHANGELOG.md b/packages/vscode-tailwindcss/CHANGELOG.md index de7ac14e..25b06e9f 100644 --- a/packages/vscode-tailwindcss/CHANGELOG.md +++ b/packages/vscode-tailwindcss/CHANGELOG.md @@ -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