Skip to content
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

Normalize drive letter in file path #980

Merged
merged 7 commits into from
Jun 25, 2024
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
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