Skip to content

Commit ba346d1

Browse files
committed
Use a case-insensitive find for files on Mac and Windows
1 parent c68964c commit ba346d1

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/razor/src/document/razorDocumentManager.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { IRazorDocumentManager } from './IRazorDocumentManager';
1818
import { RazorDocumentChangeKind } from './razorDocumentChangeKind';
1919
import { createDocument } from './razorDocumentFactory';
2020
import { razorInitializeCommand } from '../../../lsptoolshost/razorCommands';
21+
import { PlatformInformation } from '../../../shared/platform';
2122

2223
export class RazorDocumentManager implements IRazorDocumentManager {
2324
public roslynActivated = false;
@@ -32,7 +33,8 @@ export class RazorDocumentManager implements IRazorDocumentManager {
3233
constructor(
3334
private readonly serverClient: RazorLanguageServerClient,
3435
private readonly logger: RazorLogger,
35-
private readonly telemetryReporter: TelemetryReporter
36+
private readonly telemetryReporter: TelemetryReporter,
37+
private readonly platformInfo: PlatformInformation
3638
) {}
3739

3840
public get onChange() {
@@ -146,7 +148,7 @@ export class RazorDocumentManager implements IRazorDocumentManager {
146148

147149
private _getDocument(uri: vscode.Uri) {
148150
const path = getUriPath(uri);
149-
let document = this.razorDocuments[path];
151+
let document = this.findDocument(path);
150152

151153
// This might happen in the case that a file is opened outside the workspace
152154
if (!document) {
@@ -198,7 +200,7 @@ export class RazorDocumentManager implements IRazorDocumentManager {
198200

199201
private addDocument(uri: vscode.Uri) {
200202
const path = getUriPath(uri);
201-
let document = this.razorDocuments[path];
203+
let document = this.findDocument(path);
202204
if (document) {
203205
this.logger.logMessage(`Skipping document creation for '${path}' because it already exists.`);
204206
return document;
@@ -219,6 +221,26 @@ export class RazorDocumentManager implements IRazorDocumentManager {
219221
this.notifyDocumentChange(document, RazorDocumentChangeKind.removed);
220222
}
221223

224+
private findDocument(path: string) {
225+
// This method ultimately gets called from VS Code, using file system paths, or from DevKit, which
226+
// can use paths as specified in the sln file. When these don't agree, on case-insensitive operating
227+
// systems, we have to be careful to match things up correctly.
228+
229+
if (this.platformInfo.isLinux()) {
230+
return this.razorDocuments[path];
231+
}
232+
233+
const lowerCasePath = path.toLowerCase();
234+
const key = Object.keys(this.razorDocuments).find(
235+
(documentPath) => documentPath.toLowerCase() === lowerCasePath
236+
);
237+
if (key) {
238+
return this.razorDocuments[key];
239+
}
240+
241+
return undefined;
242+
}
243+
222244
private async updateCSharpBuffer(updateBufferRequest: UpdateBufferRequest) {
223245
if (this.logger.verboseEnabled) {
224246
this.logger.logVerbose(

src/razor/src/extension.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,12 @@ export async function activate(
128128

129129
const languageServiceClient = new RazorLanguageServiceClient(languageServerClient);
130130

131-
const documentManager = new RazorDocumentManager(languageServerClient, logger, razorTelemetryReporter);
131+
const documentManager = new RazorDocumentManager(
132+
languageServerClient,
133+
logger,
134+
razorTelemetryReporter,
135+
platformInfo
136+
);
132137
const documentSynchronizer = new RazorDocumentSynchronizer(documentManager, logger);
133138
reportTelemetryForDocuments(documentManager, razorTelemetryReporter);
134139
const languageConfiguration = new RazorLanguageConfiguration();

0 commit comments

Comments
 (0)