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
16 changes: 16 additions & 0 deletions packages/tailwindcss-language-server/src/project-locator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,22 @@ testLocator({
],
})

testLocator({
name: 'A stylesheet can be named tailwindcss.css',
fs: {
'src/tailwindcss.css': css`
@import 'tailwindcss';
`,
},
expected: [
{
version: '4.1.18 (bundled)',
config: '/src/tailwindcss.css',
content: [],
},
],
})

// ---

function testLocator({
Expand Down
28 changes: 27 additions & 1 deletion packages/tailwindcss-language-server/src/resolver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ export async function createResolver(opts: ResolverOptions): Promise<Resolver> {
preferRelative: true,
})

let absoluteCssResolver = ResolverFactory.createResolver({
fileSystem,
extensions: ['.css'],
mainFields: ['style'],
conditionNames: ['style'],
pnpApi,

// Used as a fallback when a file ends up importing itself
preferRelative: false,
})

async function resolveId(
resolver: BaseResolver,
id: string,
Expand Down Expand Up @@ -235,7 +246,22 @@ export async function createResolver(opts: ResolverOptions): Promise<Resolver> {
}

async function resolveCssId(id: string, base: string): Promise<string> {
return (await resolveId(cssResolver, id, base)) || id
// If the ID matches `tailwindcss` exactly we tell the CSS resolver to
// ignore relative file paths. This ensures that Tailwind CSS itself is
// found even when a stylesheet named `tailwindcss.css` exists.
//
// If someone needs to import that stylesheet it must be done by:
// - relative path: `@import "./tailwindcss"`
// - adding an extension: `@import "tailwindcss.css"`
//
// Ideally this code would only be in place if the _importer_ is
// `tailwindcss.css` but that data is not available. Only the base
// path is so we enable it all the time.
//
// https://github.com/tailwindlabs/tailwindcss-intellisense/issues/1427
let resolver = id === 'tailwindcss' ? absoluteCssResolver : cssResolver

return (await resolveId(resolver, id, base)) || id
}

// Takes a path which may or may not be complete and returns the aliased path
Expand Down
1 change: 1 addition & 0 deletions packages/vscode-tailwindcss/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Add a source to all emitted diagnostics ([#1491](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1491))
- Improve performance in large files ([#1507](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1507))
- Improve utility lookup performance when using v4 ([#1509](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1509))
- Fix project initalization when stylesheet is named `tailwindcss.css` ([#1517](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1517))

## 0.14.29

Expand Down