Skip to content

Commit 52858d5

Browse files
Normalize drive letter in file path (#980)
* Normalize drive letter in file path * Move normalization * Normalize drive letters in document selector patterns * Add comment * Update changelog --------- Co-authored-by: Jordan Pittman <[email protected]>
1 parent c61f4c9 commit 52858d5

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

packages/tailwindcss-language-server/src/project-locator.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import resolveFrom from './util/resolveFrom'
1616
import { type Feature, supportedFeatures } from '@tailwindcss/language-service/src/features'
1717
import { pathToFileURL } from 'node:url'
1818
import { resolveCssImports } from './resolve-css-imports'
19+
import { normalizeDriveLetter } from './utils'
1920

2021
export interface ProjectConfig {
2122
/** The folder that contains the project */
@@ -70,6 +71,22 @@ export class ProjectLocator {
7071
})
7172
}
7273

74+
// Normalize drive letters in filepaths on Windows so paths
75+
// are consistent across the filesystem and the language client
76+
for (let project of projects) {
77+
project.folder = normalizeDriveLetter(project.folder)
78+
project.configPath = normalizeDriveLetter(project.configPath)
79+
project.config.path = normalizeDriveLetter(project.config.path)
80+
81+
for (let entry of project.config.entries) {
82+
entry.path = normalizeDriveLetter(entry.path)
83+
}
84+
85+
for (let selector of project.documentSelector) {
86+
selector.pattern = normalizeDriveLetter(selector.pattern)
87+
}
88+
}
89+
7390
return projects
7491
}
7592

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ export class TW {
282282

283283
changeLoop: for (let change of changes) {
284284
let normalizedFilename = normalizePath(change.file)
285+
286+
// This filename comes from VSCode rather than from the filesystem
287+
// which means the drive letter *might* be lowercased and we need
288+
// to normalize it so that we can compare it properly.
285289
normalizedFilename = normalizeDriveLetter(normalizedFilename)
286290

287291
for (let ignorePattern of ignore) {
@@ -322,8 +326,6 @@ export class TW {
322326
...project.projectConfig.config.entries.map((entry) => entry.path),
323327
]
324328

325-
reloadableFiles = reloadableFiles.map(normalizeDriveLetter)
326-
327329
if (!changeAffectsFile(normalizedFilename, reloadableFiles)) continue
328330

329331
needsSoftRestart = true
@@ -783,6 +785,12 @@ export class TW {
783785
for (let selector of documentSelector) {
784786
let fsPath = URI.parse(document.uri).fsPath
785787
let pattern = selector.pattern.replace(/[\[\]{}]/g, (m) => `\\${m}`)
788+
789+
// This filename comes from VSCode rather than from the filesystem
790+
// which means the drive letter *might* be lowercased and we need
791+
// to normalize it so that we can compare it properly.
792+
fsPath = normalizeDriveLetter(fsPath)
793+
786794
if (pattern.startsWith('!') && picomatch(pattern.slice(1), { dot: true })(fsPath)) {
787795
break
788796
}

packages/vscode-tailwindcss/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Prerelease
44

5-
- Nothing yet!
5+
- Normalize Windows drive letters in document URIs ([#980](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/980))
66

77
## 0.12.0
88

0 commit comments

Comments
 (0)