@@ -56,6 +56,7 @@ import { ProjectLocator, type ProjectConfig } from './project-locator'
56
56
import type { TailwindCssSettings } from '@tailwindcss/language-service/src/util/state'
57
57
import { createResolver , Resolver } from './resolver'
58
58
import { analyzeStylesheet } from './version-guesser.js'
59
+ import { createPathMatcher , PathMatcher } from './matching.js'
59
60
60
61
const TRIGGER_CHARACTERS = [
61
62
// class attributes
@@ -104,12 +105,14 @@ export class TW {
104
105
private watched : string [ ] = [ ]
105
106
106
107
private settingsCache : SettingsCache
108
+ private pathMatcher : PathMatcher
107
109
108
110
constructor ( private connection : Connection ) {
109
111
this . documentService = new DocumentService ( this . connection )
110
112
this . projects = new Map ( )
111
113
this . projectCounter = 0
112
114
this . settingsCache = createSettingsCache ( connection )
115
+ this . pathMatcher = createPathMatcher ( )
113
116
}
114
117
115
118
async init ( ) : Promise < void > {
@@ -151,6 +154,7 @@ export class TW {
151
154
private async _init ( ) : Promise < void > {
152
155
clearRequireCache ( )
153
156
157
+ this . pathMatcher . clear ( )
154
158
let folders = this . getWorkspaceFolders ( ) . map ( ( folder ) => normalizePath ( folder . uri ) )
155
159
156
160
if ( folders . length === 0 ) {
@@ -961,32 +965,20 @@ export class TW {
961
965
}
962
966
963
967
for ( let selector of project . documentSelector ( ) ) {
964
- let pattern = selector . pattern . replace ( / [ \[ \] { } ( ) ] / g, ( m ) => `\\${ m } ` )
965
-
966
- if ( pattern . startsWith ( '!' ) ) {
967
- if ( picomatch ( pattern . slice ( 1 ) , { dot : true } ) ( fsPath ) ) {
968
- break
969
- }
970
-
971
- if ( picomatch ( pattern . slice ( 1 ) , { dot : true } ) ( normalPath ) ) {
972
- break
973
- }
968
+ if (
969
+ selector . pattern . startsWith ( '!' ) &&
970
+ this . pathMatcher . anyMatches ( selector . pattern . slice ( 1 ) , [ fsPath , normalPath ] )
971
+ ) {
972
+ break
974
973
}
975
974
976
- if ( selector . priority < matchedPriority ) {
977
- if ( picomatch ( pattern , { dot : true } ) ( fsPath ) ) {
978
- matchedProject = project
979
- matchedPriority = selector . priority
980
-
981
- continue
982
- }
983
-
984
- if ( picomatch ( pattern , { dot : true } ) ( normalPath ) ) {
985
- matchedProject = project
986
- matchedPriority = selector . priority
987
-
988
- continue
989
- }
975
+ if (
976
+ selector . priority < matchedPriority &&
977
+ this . pathMatcher . anyMatches ( selector . pattern , [ fsPath , normalPath ] )
978
+ ) {
979
+ matchedProject = project
980
+ matchedPriority = selector . priority
981
+ continue
990
982
}
991
983
}
992
984
}
0 commit comments