diff --git a/packages/tailwindcss-language-server/src/project-locator.test.ts b/packages/tailwindcss-language-server/src/project-locator.test.ts index f43479ae..3d5cddbb 100644 --- a/packages/tailwindcss-language-server/src/project-locator.test.ts +++ b/packages/tailwindcss-language-server/src/project-locator.test.ts @@ -462,6 +462,43 @@ testLocator({ ], }) +testLocator({ + name: 'File exclusions starting with `/` do not cause traversal to loop forever', + fs: { + 'index.css': css` + @import 'tailwindcss'; + `, + 'vendor/a.css': css` + @import 'tailwindcss'; + `, + 'vendor/nested/b.css': css` + @import 'tailwindcss'; + `, + 'src/vendor/c.css': css` + @import 'tailwindcss'; + `, + }, + settings: { + tailwindCSS: { + files: { + exclude: ['/vendor'], + }, + } as Settings['tailwindCSS'], + }, + expected: [ + { + version: '4.1.1 (bundled)', + config: '/index.css', + content: [], + }, + { + version: '4.1.1 (bundled)', + config: '/src/vendor/c.css', + content: [], + }, + ], +}) + // --- function testLocator({ @@ -502,7 +539,7 @@ function testLocator({ }) } -async function prepare({ root }: TestUtils) { +async function prepare({ root }: TestUtils) { let defaultSettings = { tailwindCSS: { files: { diff --git a/packages/tailwindcss-language-server/src/project-locator.ts b/packages/tailwindcss-language-server/src/project-locator.ts index de562b63..4e3c0453 100644 --- a/packages/tailwindcss-language-server/src/project-locator.ts +++ b/packages/tailwindcss-language-server/src/project-locator.ts @@ -274,11 +274,22 @@ export class ProjectLocator { } private async findConfigs(): Promise { + let ignore = this.settings.tailwindCSS.files.exclude + + // NOTE: This is a temporary workaround for a bug in the `fdir` package used + // by `tinyglobby`. It infinite loops when the ignore pattern starts with + // a `/`. This should be removed once the bug is fixed. + ignore = ignore.map((pattern) => { + if (!pattern.startsWith('/')) return pattern + + return pattern.slice(1) + }) + // Look for config files and CSS files let files = await glob({ patterns: [`**/${CONFIG_GLOB}`, `**/${CSS_GLOB}`], cwd: this.base, - ignore: this.settings.tailwindCSS.files.exclude, + ignore, onlyFiles: true, absolute: true, followSymbolicLinks: true, diff --git a/packages/vscode-tailwindcss/CHANGELOG.md b/packages/vscode-tailwindcss/CHANGELOG.md index fa0302ae..e9a9bbde 100644 --- a/packages/vscode-tailwindcss/CHANGELOG.md +++ b/packages/vscode-tailwindcss/CHANGELOG.md @@ -2,7 +2,7 @@ ## Prerelease -- Nothing yet! +- Prevent infinite loop when any file exclusion starts with `/` ([#1307](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1307)) # 0.14.14