Skip to content

Commit e5c352d

Browse files
authored
Merge pull request #6683 from davidwengier/CaseInsensitivePaths
Use a case-insensitive find for files on Mac and Windows
2 parents c68964c + 63e4db7 commit e5c352d

File tree

4 files changed

+56
-45
lines changed

4 files changed

+56
-45
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Direct debugger setting documentation to code.visualstudio.com (PR: [#6659](https://github.com/dotnet/vscode-csharp/pull/6659))
1313
* Add a timeout for downloading razor telemetry (PR: [#6622](https://github.com/dotnet/vscode-csharp/pull/6622))
1414
* Rearrange settings sections into actual categories (PR: [#6652](https://github.com/dotnet/vscode-csharp/pull/6652))
15+
* Use case-insensitive path lookups for Razor files on Windows and Mac (PR: [#6683](https://github.com/dotnet/vscode-csharp/pull/6683))
1516

1617
## 2.10.28
1718
* Fix C# Debugger telemetry (PR: [#6627](https://github.com/dotnet/vscode-csharp/pull/6627))

src/razor/src/document/razorDocumentManager.ts

Lines changed: 19 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,20 @@ 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+
return Object.values(this.razorDocuments).find(
234+
(document) => document.path.localeCompare(path, undefined, { sensitivity: 'base' }) === 0
235+
);
236+
}
237+
222238
private async updateCSharpBuffer(updateBufferRequest: UpdateBufferRequest) {
223239
if (this.logger.verboseEnabled) {
224240
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();

test/razorIntegrationTests/formatting.integration.test.ts

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@ import { describe, beforeAll, afterAll, test, expect } from '@jest/globals';
99
import testAssetWorkspace from './testAssets/testAssetWorkspace';
1010
import * as integrationHelpers from '../integrationTests/integrationHelpers';
1111

12-
function normalizeNewlines(original: string | undefined): string | undefined {
13-
if (!original) {
14-
return original;
15-
}
16-
17-
while (original.indexOf('\r\n') != -1) {
18-
original = original.replace('\r\n', '\n');
19-
}
20-
21-
return original;
22-
}
23-
2412
describe(`Razor Formatting ${testAssetWorkspace.description}`, function () {
2513
beforeAll(async function () {
2614
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
@@ -59,34 +47,35 @@ describe(`Razor Formatting ${testAssetWorkspace.description}`, function () {
5947
}
6048
);
6149

62-
expect(edits).toBeDefined();
63-
64-
console.log(`Got ${edits.length} edits`);
65-
66-
// It's much easier to verify the expected state of the document, than a bunch of edits
67-
const formatEdit = new vscode.WorkspaceEdit();
68-
formatEdit.set(activeDocument, edits);
69-
70-
console.log(`Applying edit ${formatEdit}`);
71-
72-
await vscode.workspace.applyEdit(formatEdit);
73-
74-
const contents = normalizeNewlines(vscode.window.activeTextEditor?.document.getText());
75-
76-
console.log(`Checking document contents...`);
77-
78-
expect(contents).toBe(
79-
normalizeNewlines(`@page "/bad"
80-
81-
@code {
82-
private string _x = "";
83-
84-
private void M()
85-
{
86-
// hi there
87-
}
88-
}
89-
`)
90-
);
50+
expect(edits).toHaveLength(13);
51+
52+
assertEditEqual(edits[0], 3, 0, 3, 0, ' ');
53+
assertEditEqual(edits[1], 3, 7, 3, 17, '');
54+
assertEditEqual(edits[2], 3, 18, 3, 31, '');
55+
assertEditEqual(edits[3], 3, 37, 3, 38, '');
56+
assertEditEqual(edits[4], 3, 39, 3, 57, '');
57+
assertEditEqual(edits[5], 3, 59, 3, 69, '');
58+
assertEditEqual(edits[6], 3, 70, 3, 86, '');
59+
assertEditEqual(edits[7], 3, 87, 3, 99, '');
60+
assertEditEqual(edits[8], 3, 100, 3, 108, '');
61+
assertEditEqual(edits[9], 5, 0, 5, 0, ' ');
62+
assertEditEqual(edits[10], 6, 0, 6, 0, ' ');
63+
assertEditEqual(edits[11], 7, 0, 7, 0, ' ');
64+
assertEditEqual(edits[12], 8, 0, 8, 0, ' ');
65+
66+
function assertEditEqual(
67+
actual: vscode.TextEdit,
68+
startLine: number,
69+
startChar: number,
70+
endLine: number,
71+
endChar: number,
72+
text: string
73+
) {
74+
expect(actual.newText).toBe(text);
75+
expect(actual.range.start.line).toBe(startLine);
76+
expect(actual.range.start.character).toBe(startChar);
77+
expect(actual.range.end.line).toBe(endLine);
78+
expect(actual.range.end.character).toBe(endChar);
79+
}
9180
});
9281
});

0 commit comments

Comments
 (0)