Skip to content

Commit 4a98c04

Browse files
committed
Sort document selectors once
1 parent f9496db commit 4a98c04

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,5 +815,12 @@ export async function calculateDocumentSelectors(
815815
documentSelectors.findIndex(({ pattern: p }) => p === pattern) === index,
816816
)
817817

818+
// Move all the negated patterns to the front
819+
selectors = selectors.sort((a, z) => {
820+
if (a.pattern.startsWith('!') && !z.pattern.startsWith('!')) return -1
821+
if (!a.pattern.startsWith('!') && z.pattern.startsWith('!')) return 1
822+
return 0
823+
})
824+
818825
return selectors
819826
}

packages/tailwindcss-language-server/src/tw.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -984,21 +984,7 @@ export class TW {
984984
continue
985985
}
986986

987-
let documentSelector = project
988-
.documentSelector()
989-
.concat()
990-
// move all the negated patterns to the front
991-
.sort((a, z) => {
992-
if (a.pattern.startsWith('!') && !z.pattern.startsWith('!')) {
993-
return -1
994-
}
995-
if (!a.pattern.startsWith('!') && z.pattern.startsWith('!')) {
996-
return 1
997-
}
998-
return 0
999-
})
1000-
1001-
for (let selector of documentSelector) {
987+
for (let selector of project.documentSelector()) {
1002988
let pattern = selector.pattern.replace(/[\[\]{}()]/g, (m) => `\\${m}`)
1003989

1004990
if (pattern.startsWith('!')) {

0 commit comments

Comments
 (0)