Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion packages/tailwindcss-language-server/src/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import resolveFrom from './util/resolveFrom'
import * as parcel from './watcher/index.js'
import { equal } from '@tailwindcss/language-service/src/util/array'
import { CONFIG_GLOB, CSS_GLOB, PACKAGE_LOCK_GLOB } from './lib/constants'
import { clearRequireCache, isObject, changeAffectsFile } from './utils'
import { clearRequireCache, isObject, changeAffectsFile, normalizeDriveLetter } from './utils'
import { DocumentService } from './documents'
import { createProjectService, type ProjectService } from './projects'
import { type SettingsCache, createSettingsCache } from './config'
Expand Down Expand Up @@ -273,6 +273,7 @@ export class TW {

changeLoop: for (let change of changes) {
let normalizedFilename = normalizePath(change.file)
normalizedFilename = normalizeDriveLetter(normalizedFilename)

for (let ignorePattern of ignore) {
let isIgnored = picomatch(ignorePattern, { dot: true })
Expand Down Expand Up @@ -312,6 +313,8 @@ export class TW {
...project.projectConfig.config.entries.map((entry) => entry.path),
]

reloadableFiles = reloadableFiles.map(normalizeDriveLetter)

if (!changeAffectsFile(normalizedFilename, reloadableFiles)) continue

needsSoftRestart = true
Expand Down
11 changes: 11 additions & 0 deletions packages/tailwindcss-language-server/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ export function dirContains(dir: string, file: string): boolean {
return !!relative && !relative.startsWith('..') && !path.isAbsolute(relative)
}

const WIN_DRIVE_LETTER = /^([a-zA-Z]):/

/**
* Windows drive letters are case-insensitive and we may get them as either
* lower or upper case. This function normalizes the drive letter to uppercase
* to be consistent with the rest of the codebase.
*/
export function normalizeDriveLetter(filepath: string) {
return filepath.replace(WIN_DRIVE_LETTER, (_, letter) => letter.toUpperCase() + ':')
}

export function changeAffectsFile(change: string, files: string[]): boolean {
for (let file of files) {
if (change === file || dirContains(change, file)) {
Expand Down