Skip to content

Add logs and tweak detecting projects for documents #999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 48 additions & 3 deletions packages/tailwindcss-language-server/src/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ export class TW {
}
}

console.log(`[Global] Preparing projects...`)

await Promise.all(
workspaceFolders.map((projectConfig) =>
this.addProject(
Expand All @@ -517,18 +519,24 @@ export class TW {
),
)

console.log(`[Global] Initializing projects...`)

// init projects for documents that are _already_ open
let readyDocuments: string[] = []
let enabledProjectCount = 0
for (let document of this.documentService.getAllDocuments()) {
let project = this.getProject(document)
if (project && !project.enabled()) {
project.enable()
await project.tryInit()
enabledProjectCount++
}

readyDocuments.push(document.uri)
}

console.log(`[Global] Initialized ${enabledProjectCount} projects`)

this.setupLSPHandlers()

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

if (!isTestMode) return

console.log(`[Global][Test] Sending document notifications...`)

await Promise.all(
readyDocuments.map((uri) =>
this.connection.sendNotification('@/tailwindCSS/documentReady', {
Expand Down Expand Up @@ -783,20 +793,55 @@ export class TW {
return 0
})
for (let selector of documentSelector) {
let fsPath = URI.parse(document.uri).fsPath
let uri = URI.parse(document.uri)
let pattern = selector.pattern.replace(/[\[\]{}]/g, (m) => `\\${m}`)

let fsPath = uri.fsPath
let normalPath = uri.path

// This filename comes from VSCode rather than from the filesystem
// which means the drive letter *might* be lowercased and we need
// to normalize it so that we can compare it properly.
fsPath = normalizeDriveLetter(fsPath)

if (pattern.startsWith('!') && picomatch(pattern.slice(1), { dot: true })(fsPath)) {
break
console.log('[GLOBAL] Checking document', {
fsPath,
normalPath,
})

if (pattern.startsWith('!')) {
if (picomatch(pattern.slice(1), { dot: true })(fsPath)) {
break
}

if (picomatch(pattern.slice(1), { dot: true })(normalPath)) {
console.log('[GLOBAL] Matched ignored non-FS path', {
pattern,
})

break
}
}

if (picomatch(pattern, { dot: true })(fsPath) && selector.priority < matchedPriority) {
matchedProject = project
matchedPriority = selector.priority

continue
}

if (
picomatch(pattern, { dot: true })(normalPath) &&
selector.priority < matchedPriority
) {
console.log('[GLOBAL] Matched non-FS path', {
pattern,
})

matchedProject = project
matchedPriority = selector.priority

continue
}
}
} else {
Expand Down