Skip to content

Commit e769246

Browse files
committed
Try “roots” first instead of discarding non-roots
1 parent c8eaa7b commit e769246

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

packages/tailwindcss-language-server/src/project-locator.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,18 @@ export class ProjectLocator {
427427
if (indexPath && themePath) graph.connect(indexPath, themePath)
428428
if (indexPath && utilitiesPath) graph.connect(indexPath, utilitiesPath)
429429

430-
for (let root of graph.roots()) {
431-
if (!root.meta) continue
430+
// Sort the graph so potential "roots" appear first
431+
// The entire concept of roots needs to be rethought because it's not always
432+
// clear what the root of a project is. Even when imports are present a file
433+
// may import a file that is the actual "root" of the project.
434+
let roots = Array.from(graph.roots())
435+
436+
roots.sort((a, b) => {
437+
return a.meta.root === b.meta.root ? 0 : a.meta.root ? -1 : 1
438+
})
432439

433-
// This file is not eligible to act as a root of the CSS graph
434-
if (root.meta.root === false) continue
440+
for (let root of roots) {
441+
if (!root.meta) continue
435442

436443
let config: ConfigEntry = configs.remember(root.path, () => ({
437444
source: 'css',

0 commit comments

Comments
 (0)