diff --git a/packages/tailwindcss-language-server/src/tw.ts b/packages/tailwindcss-language-server/src/tw.ts index 48d7b5f7..d5cfba20 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 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 + // 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, 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.`, + ) + 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 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