From a740944e23246d01e5287f67a1aa3d6cc1588c64 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 20 Mar 2025 12:17:40 -0400 Subject: [PATCH 1/4] Improve error message when a workspace folder is inaccessible --- .../tailwindcss-language-server/src/tw.ts | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/tailwindcss-language-server/src/tw.ts b/packages/tailwindcss-language-server/src/tw.ts index 48d7b5f7..0f186ba0 100644 --- a/packages/tailwindcss-language-server/src/tw.ts +++ b/packages/tailwindcss-language-server/src/tw.ts @@ -38,6 +38,7 @@ import { import { URI } from 'vscode-uri' import normalizePath from 'normalize-path' import * as path from 'node:path' +import * as fs from 'node:fs/promises' import type * as chokidar from 'chokidar' import picomatch from 'picomatch' import * as parcel from './watcher/index.js' @@ -174,6 +175,26 @@ export class TW { } private async _initFolder(baseUri: URI): Promise { + // NOTE: We do this check because on Linux when using a LSP client that does + // not support watching files on behalf of the server, we'll use Parcel + // Watcher (if possible). If we start the watcher with a non-existent or + // inaccessible directory, it will throw an error with a very unhelpful + // message: "Bad file descriptor" + // + // The best thing we can do is an initial check for access to the directory + // and log a more helpful error message if it fails. + let base = baseUri.fsPath + + try { + await fs.access(base) + } catch (err) { + console.error( + `Unable to access the workspace folder [${base}]. This may happen if the directory does not exist or the current user does not have the necessary permissions to access it.`, + ) + console.error(err) + return + } + let initUserLanguages = this.initializeParams.initializationOptions?.userLanguages ?? {} if (Object.keys(initUserLanguages).length > 0) { @@ -182,7 +203,6 @@ export class TW { ) } - let base = baseUri.fsPath let workspaceFolders: Array = [] let globalSettings = await this.settingsCache.get() let ignore = globalSettings.tailwindCSS.files.exclude From 028b38a0d6535d67a5d52292c51e200755ad109a Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 20 Mar 2025 12:20:51 -0400 Subject: [PATCH 2/4] Update changelog --- packages/vscode-tailwindcss/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/vscode-tailwindcss/CHANGELOG.md b/packages/vscode-tailwindcss/CHANGELOG.md index fa2d07c3..32733ec8 100644 --- a/packages/vscode-tailwindcss/CHANGELOG.md +++ b/packages/vscode-tailwindcss/CHANGELOG.md @@ -7,6 +7,7 @@ - v4: Add support for upcoming `@source not` feature ([#1262](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1262)) - v4: Add support for upcoming `@source inline(…)` feature ([#1262](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1262)) - LSP: Refresh internal caches when settings are updated ([#1273](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1273)) +- LSP: Improve error message when a workspace folder does not exist or is inaccesible to the current user ([#1276](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1276)) # 0.14.9 From 61f95ce953fa3dc0b1a88a95c9c0d4f32a105c3a Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 20 Mar 2025 12:29:52 -0400 Subject: [PATCH 3/4] Check for directory visibility _and_ readability --- packages/tailwindcss-language-server/src/tw.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tailwindcss-language-server/src/tw.ts b/packages/tailwindcss-language-server/src/tw.ts index 0f186ba0..603751a0 100644 --- a/packages/tailwindcss-language-server/src/tw.ts +++ b/packages/tailwindcss-language-server/src/tw.ts @@ -186,7 +186,7 @@ export class TW { let base = baseUri.fsPath try { - await fs.access(base) + await fs.access(base, fs.constants.F_OK | fs.constants.R_OK) } catch (err) { console.error( `Unable to access the workspace folder [${base}]. This may happen if the directory does not exist or the current user does not have the necessary permissions to access it.`, From 0bc0783d36acc564f2a274e8793490215da719d3 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 20 Mar 2025 12:43:07 -0400 Subject: [PATCH 4/4] Update packages/tailwindcss-language-server/src/tw.ts Co-authored-by: Robin Malfait --- packages/tailwindcss-language-server/src/tw.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tailwindcss-language-server/src/tw.ts b/packages/tailwindcss-language-server/src/tw.ts index 603751a0..d5cfba20 100644 --- a/packages/tailwindcss-language-server/src/tw.ts +++ b/packages/tailwindcss-language-server/src/tw.ts @@ -175,7 +175,7 @@ export class TW { } private async _initFolder(baseUri: URI): Promise { - // NOTE: We do this check because on Linux when using a LSP client that does + // NOTE: We do this check because on Linux when using an LSP client that does // not support watching files on behalf of the server, we'll use Parcel // Watcher (if possible). If we start the watcher with a non-existent or // inaccessible directory, it will throw an error with a very unhelpful