Skip to content

Commit

Permalink
Normalize drive letter in file path (#980)
Browse files Browse the repository at this point in the history
* Normalize drive letter in file path

* Move normalization

* Normalize drive letters in document selector patterns

* Add comment

* Update changelog

---------

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
  • Loading branch information
xt0rted and thecrypticace committed Jun 25, 2024
1 parent c61f4c9 commit 52858d5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
17 changes: 17 additions & 0 deletions packages/tailwindcss-language-server/src/project-locator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import resolveFrom from './util/resolveFrom'
import { type Feature, supportedFeatures } from '@tailwindcss/language-service/src/features'
import { pathToFileURL } from 'node:url'
import { resolveCssImports } from './resolve-css-imports'
import { normalizeDriveLetter } from './utils'

export interface ProjectConfig {
/** The folder that contains the project */
Expand Down Expand Up @@ -70,6 +71,22 @@ export class ProjectLocator {
})
}

// Normalize drive letters in filepaths on Windows so paths
// are consistent across the filesystem and the language client
for (let project of projects) {
project.folder = normalizeDriveLetter(project.folder)
project.configPath = normalizeDriveLetter(project.configPath)
project.config.path = normalizeDriveLetter(project.config.path)

for (let entry of project.config.entries) {
entry.path = normalizeDriveLetter(entry.path)
}

for (let selector of project.documentSelector) {
selector.pattern = normalizeDriveLetter(selector.pattern)
}
}

return projects
}

Expand Down
12 changes: 10 additions & 2 deletions packages/tailwindcss-language-server/src/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ export class TW {

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

// 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.
normalizedFilename = normalizeDriveLetter(normalizedFilename)

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

reloadableFiles = reloadableFiles.map(normalizeDriveLetter)

if (!changeAffectsFile(normalizedFilename, reloadableFiles)) continue

needsSoftRestart = true
Expand Down Expand Up @@ -783,6 +785,12 @@ export class TW {
for (let selector of documentSelector) {
let fsPath = URI.parse(document.uri).fsPath
let pattern = selector.pattern.replace(/[\[\]{}]/g, (m) => `\\${m}`)

// 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
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-tailwindcss/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Prerelease

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

## 0.12.0

Expand Down

0 comments on commit 52858d5

Please sign in to comment.