@@ -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 ) {
@@ -985,32 +989,20 @@ export class TW {
985
989
}
986
990
987
991
for ( let selector of project . documentSelector ( ) ) {
988
- let pattern = selector . pattern . replace ( / [ \[ \] { } ( ) ] / g, ( m ) => `\\${ m } ` )
989
-
990
- if ( pattern . startsWith ( '!' ) ) {
991
- if ( picomatch ( pattern . slice ( 1 ) , { dot : true } ) ( fsPath ) ) {
992
- break
993
- }
994
-
995
- if ( picomatch ( pattern . slice ( 1 ) , { dot : true } ) ( normalPath ) ) {
996
- break
997
- }
992
+ if (
993
+ selector . pattern . startsWith ( '!' ) &&
994
+ this . pathMatcher . anyMatches ( selector . pattern . slice ( 1 ) , [ fsPath , normalPath ] )
995
+ ) {
996
+ break
998
997
}
999
998
1000
- if ( selector . priority < matchedPriority ) {
1001
- if ( picomatch ( pattern , { dot : true } ) ( fsPath ) ) {
1002
- matchedProject = project
1003
- matchedPriority = selector . priority
1004
-
1005
- continue
1006
- }
1007
-
1008
- if ( picomatch ( pattern , { dot : true } ) ( normalPath ) ) {
1009
- matchedProject = project
1010
- matchedPriority = selector . priority
1011
-
1012
- continue
1013
- }
999
+ if (
1000
+ selector . priority < matchedPriority &&
1001
+ this . pathMatcher . anyMatches ( selector . pattern , [ fsPath , normalPath ] )
1002
+ ) {
1003
+ matchedProject = project
1004
+ matchedPriority = selector . priority
1005
+ continue
1014
1006
}
1015
1007
}
1016
1008
}
0 commit comments