Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion packages/tailwindcss-language-server/src/project-locator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -502,7 +539,7 @@ function testLocator({
})
}

async function prepare({ root }: TestUtils) {
async function prepare({ root }: TestUtils<any>) {
let defaultSettings = {
tailwindCSS: {
files: {
Expand Down
13 changes: 12 additions & 1 deletion packages/tailwindcss-language-server/src/project-locator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,22 @@ export class ProjectLocator {
}

private async findConfigs(): Promise<ConfigEntry[]> {
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,
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!
- Prevent infinite loop when any file exclusion starts with `/` ([#1307](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1307))

# 0.14.14

Expand Down