@@ -783,73 +783,65 @@ export class TW {
783783 let matchedProject : ProjectService
784784 let matchedPriority : number = Infinity
785785
786- for ( let [ , project ] of this . projects ) {
787- if ( project . projectConfig . configPath ) {
788- let documentSelector = project
789- . documentSelector ( )
790- . concat ( )
791- // move all the negated patterns to the front
792- . sort ( ( a , z ) => {
793- if ( a . pattern . startsWith ( '!' ) && ! z . pattern . startsWith ( '!' ) ) {
794- return - 1
795- }
796- if ( ! a . pattern . startsWith ( '!' ) && z . pattern . startsWith ( '!' ) ) {
797- return 1
798- }
799- return 0
800- } )
801-
802- for ( let selector of documentSelector ) {
803- let uri = URI . parse ( document . uri )
804- let pattern = selector . pattern . replace ( / [ \[ \] { } ] / g, ( m ) => `\\${ m } ` )
805-
806- let fsPath = uri . fsPath
807- let normalPath = uri . path
786+ let uri = URI . parse ( document . uri )
787+ let fsPath = uri . fsPath
788+ let normalPath = uri . path
789+
790+ // This filename comes from VSCode rather than from the filesystem
791+ // which means the drive letter *might* be lowercased and we need
792+ // to normalize it so that we can compare it properly.
793+ fsPath = normalizeDriveLetter ( fsPath )
794+
795+ for ( let project of this . projects . values ( ) ) {
796+ if ( ! project . projectConfig . configPath ) {
797+ fallbackProject = fallbackProject ?? project
798+ continue
799+ }
808800
809- // This filename comes from VSCode rather than from the filesystem
810- // which means the drive letter *might* be lowercased and we need
811- // to normalize it so that we can compare it properly.
812- fsPath = normalizeDriveLetter ( fsPath )
801+ let documentSelector = project
802+ . documentSelector ( )
803+ . concat ( )
804+ // move all the negated patterns to the front
805+ . sort ( ( a , z ) => {
806+ if ( a . pattern . startsWith ( '!' ) && ! z . pattern . startsWith ( '!' ) ) {
807+ return - 1
808+ }
809+ if ( ! a . pattern . startsWith ( '!' ) && z . pattern . startsWith ( '!' ) ) {
810+ return 1
811+ }
812+ return 0
813+ } )
813814
814- if ( pattern . startsWith ( '!' ) ) {
815- if ( picomatch ( pattern . slice ( 1 ) , { dot : true } ) ( fsPath ) ) {
816- break
817- }
815+ for ( let selector of documentSelector ) {
816+ let pattern = selector . pattern . replace ( / [ \[ \] { } ] / g, ( m ) => `\\${ m } ` )
818817
819- if ( picomatch ( pattern . slice ( 1 ) , { dot : true } ) ( normalPath ) ) {
820- break
821- }
818+ if ( pattern . startsWith ( '!' ) ) {
819+ if ( picomatch ( pattern . slice ( 1 ) , { dot : true } ) ( fsPath ) ) {
820+ break
822821 }
823822
824- if ( picomatch ( pattern , { dot : true } ) ( fsPath ) && selector . priority < matchedPriority ) {
825- matchedProject = project
826- matchedPriority = selector . priority
827-
828- continue
823+ if ( picomatch ( pattern . slice ( 1 ) , { dot : true } ) ( normalPath ) ) {
824+ break
829825 }
826+ }
830827
831- if (
832- picomatch ( pattern , { dot : true } ) ( normalPath ) &&
833- selector . priority < matchedPriority
834- ) {
835- matchedProject = project
836- matchedPriority = selector . priority
828+ if ( picomatch ( pattern , { dot : true } ) ( fsPath ) && selector . priority < matchedPriority ) {
829+ matchedProject = project
830+ matchedPriority = selector . priority
837831
838- continue
839- }
832+ continue
840833 }
841- } else {
842- if ( ! fallbackProject ) {
843- fallbackProject = project
834+
835+ if ( picomatch ( pattern , { dot : true } ) ( normalPath ) && selector . priority < matchedPriority ) {
836+ matchedProject = project
837+ matchedPriority = selector . priority
838+
839+ continue
844840 }
845841 }
846842 }
847843
848- if ( matchedProject ) {
849- return matchedProject
850- }
851-
852- return fallbackProject
844+ return matchedProject ?? fallbackProject
853845 }
854846
855847 async onDocumentColor ( params : DocumentColorParams ) : Promise < ColorInformation [ ] > {
0 commit comments