Skip to content

Commit 9a8ce41

Browse files
Add logs and tweak detecting projects for documents (#999)
* Add logs * Attempt match on non-normalized path for a project
1 parent 28c63d1 commit 9a8ce41

File tree

1 file changed

+48
-3
lines changed
  • packages/tailwindcss-language-server/src

1 file changed

+48
-3
lines changed

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

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,8 @@ export class TW {
505505
}
506506
}
507507

508+
console.log(`[Global] Preparing projects...`)
509+
508510
await Promise.all(
509511
workspaceFolders.map((projectConfig) =>
510512
this.addProject(
@@ -517,18 +519,24 @@ export class TW {
517519
),
518520
)
519521

522+
console.log(`[Global] Initializing projects...`)
523+
520524
// init projects for documents that are _already_ open
521525
let readyDocuments: string[] = []
526+
let enabledProjectCount = 0
522527
for (let document of this.documentService.getAllDocuments()) {
523528
let project = this.getProject(document)
524529
if (project && !project.enabled()) {
525530
project.enable()
526531
await project.tryInit()
532+
enabledProjectCount++
527533
}
528534

529535
readyDocuments.push(document.uri)
530536
}
531537

538+
console.log(`[Global] Initialized ${enabledProjectCount} projects`)
539+
532540
this.setupLSPHandlers()
533541

534542
this.disposables.push(
@@ -554,6 +562,8 @@ export class TW {
554562

555563
if (!isTestMode) return
556564

565+
console.log(`[Global][Test] Sending document notifications...`)
566+
557567
await Promise.all(
558568
readyDocuments.map((uri) =>
559569
this.connection.sendNotification('@/tailwindCSS/documentReady', {
@@ -783,20 +793,55 @@ export class TW {
783793
return 0
784794
})
785795
for (let selector of documentSelector) {
786-
let fsPath = URI.parse(document.uri).fsPath
796+
let uri = URI.parse(document.uri)
787797
let pattern = selector.pattern.replace(/[\[\]{}]/g, (m) => `\\${m}`)
788798

799+
let fsPath = uri.fsPath
800+
let normalPath = uri.path
801+
789802
// This filename comes from VSCode rather than from the filesystem
790803
// which means the drive letter *might* be lowercased and we need
791804
// to normalize it so that we can compare it properly.
792805
fsPath = normalizeDriveLetter(fsPath)
793806

794-
if (pattern.startsWith('!') && picomatch(pattern.slice(1), { dot: true })(fsPath)) {
795-
break
807+
console.log('[GLOBAL] Checking document', {
808+
fsPath,
809+
normalPath,
810+
})
811+
812+
if (pattern.startsWith('!')) {
813+
if (picomatch(pattern.slice(1), { dot: true })(fsPath)) {
814+
break
815+
}
816+
817+
if (picomatch(pattern.slice(1), { dot: true })(normalPath)) {
818+
console.log('[GLOBAL] Matched ignored non-FS path', {
819+
pattern,
820+
})
821+
822+
break
823+
}
796824
}
825+
797826
if (picomatch(pattern, { dot: true })(fsPath) && selector.priority < matchedPriority) {
798827
matchedProject = project
799828
matchedPriority = selector.priority
829+
830+
continue
831+
}
832+
833+
if (
834+
picomatch(pattern, { dot: true })(normalPath) &&
835+
selector.priority < matchedPriority
836+
) {
837+
console.log('[GLOBAL] Matched non-FS path', {
838+
pattern,
839+
})
840+
841+
matchedProject = project
842+
matchedPriority = selector.priority
843+
844+
continue
800845
}
801846
}
802847
} else {

0 commit comments

Comments
 (0)