Skip to content

Commit fbfe1dc

Browse files
author
Andrew Hall
committed
Use correct checksum values. Use base64 checksum
1 parent 6d9e1b4 commit fbfe1dc

File tree

8 files changed

+80
-69
lines changed

8 files changed

+80
-69
lines changed

src/razor/src/csharp/csharpProjectedDocument.ts

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ export class CSharpProjectedDocument implements IProjectedDocument {
1919
private resolveProvisionalEditAt: number | undefined;
2020
private ProvisionalDotPosition: Position | undefined;
2121
private hostDocumentVersion: number | null = null;
22-
private updates: Update[] | null = null;
23-
private _checksum: Uint8Array = new Uint8Array();
24-
private _checksumAlgorithm: number = 0;
22+
private updates: CSharpDocumentUpdate[] | null = null;
23+
private _checksum: string = '';
24+
private _checksumAlgorithm: number = 1; // Default to Sha1
2525
private _encodingCodePage: number | null = null;
2626

2727
public constructor(public readonly uri: vscode.Uri) {
@@ -36,7 +36,11 @@ export class CSharpProjectedDocument implements IProjectedDocument {
3636
return this.content.length;
3737
}
3838

39-
public get checksum(): Uint8Array {
39+
public clear() {
40+
this.setContent('');
41+
}
42+
43+
public get checksum(): string {
4044
return this._checksum;
4145
}
4246

@@ -48,15 +52,11 @@ export class CSharpProjectedDocument implements IProjectedDocument {
4852
return this._encodingCodePage;
4953
}
5054

51-
public clear() {
52-
this.setContent('');
53-
}
54-
5555
public update(
5656
hostDocumentIsOpen: boolean,
5757
edits: ServerTextChange[],
5858
hostDocumentVersion: number,
59-
checksum: Uint8Array,
59+
checksum: string,
6060
checksumAlgorithm: number,
6161
encodingCodePage: number | null
6262
) {
@@ -73,35 +73,45 @@ export class CSharpProjectedDocument implements IProjectedDocument {
7373
}
7474

7575
this.updateContent(edits);
76+
this._checksum = checksum;
77+
this._checksumAlgorithm = checksumAlgorithm;
78+
this._encodingCodePage = encodingCodePage;
7679
} else {
80+
const update = new CSharpDocumentUpdate(edits, checksum, checksumAlgorithm, encodingCodePage);
81+
7782
if (this.updates) {
78-
this.updates = this.updates.concat(new Update(edits));
83+
this.updates = this.updates.concat(update);
7984
} else {
80-
this.updates = [new Update(edits)];
85+
this.updates = [update];
8186
}
8287
}
8388

84-
this._checksum = checksum;
85-
this._checksumAlgorithm = checksumAlgorithm;
86-
this._encodingCodePage = encodingCodePage;
8789
this.hostDocumentVersion = hostDocumentVersion;
8890
}
8991

90-
public getAndApplyEdits() {
92+
public applyEdits(): ApplyEditsResponse {
9193
const updates = this.updates;
9294
this.updates = null;
9395

96+
const originalChecksum = this._checksum;
97+
const originalChecksumAlgorithm = this._checksumAlgorithm;
98+
const originalEncodingCodePage = this._encodingCodePage;
99+
94100
if (updates) {
95-
let changes: ServerTextChange[] = [];
96101
for (const update of updates) {
97102
this.updateContent(update.changes);
98-
changes = changes.concat(update.changes);
103+
this._checksum = update.checksum;
104+
this._checksumAlgorithm = update.checksumAlgorithm;
105+
this._encodingCodePage = update.encodingCodePage;
99106
}
100-
101-
return changes;
102107
}
103108

104-
return null;
109+
return {
110+
edits: updates,
111+
originalChecksum: originalChecksum,
112+
originalChecksumAlgorithm: originalChecksumAlgorithm,
113+
originalEncodingCodePage: originalEncodingCodePage,
114+
};
105115
}
106116

107117
public getContent() {
@@ -216,6 +226,18 @@ export class CSharpProjectedDocument implements IProjectedDocument {
216226
}
217227
}
218228

219-
class Update {
220-
constructor(public readonly changes: ServerTextChange[]) {}
229+
export class CSharpDocumentUpdate {
230+
constructor(
231+
public readonly changes: ServerTextChange[],
232+
public readonly checksum: string,
233+
public readonly checksumAlgorithm: number,
234+
public readonly encodingCodePage: number | null
235+
) {}
236+
}
237+
238+
export interface ApplyEditsResponse {
239+
edits: CSharpDocumentUpdate[] | null;
240+
originalChecksum: string;
241+
originalChecksumAlgorithm: number;
242+
originalEncodingCodePage: number | null;
221243
}

src/razor/src/document/razorDocumentManager.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,7 @@ export class RazorDocumentManager implements IRazorDocumentManager {
308308
htmlProjectedDocument.clear();
309309
}
310310

311-
htmlProjectedDocument.update(
312-
updateBufferRequest.changes,
313-
updateBufferRequest.hostDocumentVersion,
314-
updateBufferRequest.checksum,
315-
updateBufferRequest.checksumAlgorithm,
316-
updateBufferRequest.encodingCodePage
317-
);
311+
htmlProjectedDocument.update(updateBufferRequest.changes, updateBufferRequest.hostDocumentVersion);
318312

319313
this.notifyDocumentChange(document, RazorDocumentChangeKind.htmlChanged);
320314
} else {

src/razor/src/dynamicFile/dynamicFileInfoHandler.ts

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { CSharpProjectedDocument } from '../csharp/csharpProjectedDocument';
1414
import { RazorDocumentChangeKind } from '../document/razorDocumentChangeKind';
1515
import { RazorDynamicFileChangedParams } from './dynamicFileUpdatedParams';
1616
import { TextDocumentIdentifier } from 'vscode-languageserver-protocol';
17+
import { ServerTextChange } from '../rpc/serverTextChange';
1718

1819
// Handles Razor generated doc communication between the Roslyn workspace and Razor.
1920
// didChange behavior for Razor generated docs is handled in the RazorDocumentManager.
@@ -70,6 +71,27 @@ export class DynamicFileInfoHandler {
7071
return null;
7172
}
7273

74+
const csharpDocument = razorDocument.csharpDocument as CSharpProjectedDocument;
75+
if (request.fullText) {
76+
// The server asked for a full replace so the newtext is the important
77+
// thing here, the span doesn't matter.
78+
const change: ServerTextChange = {
79+
newText: razorDocument.csharpDocument.getContent(),
80+
span: {
81+
start: 0,
82+
length: 0,
83+
},
84+
};
85+
86+
return new ProvideDynamicFileResponse(
87+
request.razorDocument,
88+
[change],
89+
csharpDocument.checksum,
90+
csharpDocument.checksumAlgorithm,
91+
csharpDocument.encodingCodePage
92+
);
93+
}
94+
7395
const virtualCsharpUri = UriConverter.serialize(razorDocument.csharpDocument.uri);
7496

7597
if (this.documentManager.isRazorDocumentOpenInCSharpWorkspace(vscodeUri)) {
@@ -78,22 +100,22 @@ export class DynamicFileInfoHandler {
78100
return new ProvideDynamicFileResponse(
79101
{ uri: virtualCsharpUri },
80102
null,
81-
razorDocument.csharpDocument.checksum,
82-
razorDocument.csharpDocument.checksumAlgorithm,
83-
razorDocument.csharpDocument.encodingCodePage
103+
csharpDocument.checksum,
104+
csharpDocument.checksumAlgorithm,
105+
csharpDocument.encodingCodePage
84106
);
85107
} else {
86108
// Closed documents provide edits since the last time they were requested since
87109
// there is no open buffer in vscode corresponding to the csharp content.
88-
const csharpDocument = razorDocument.csharpDocument as CSharpProjectedDocument;
89-
const edits = csharpDocument.getAndApplyEdits();
110+
const response = csharpDocument.applyEdits();
111+
const changes = response.edits?.map((e) => e.changes).reduce((a, b) => a.concat(b)) ?? null;
90112

91113
return new ProvideDynamicFileResponse(
92114
{ uri: virtualCsharpUri },
93-
edits ?? null,
94-
razorDocument.csharpDocument.checksum,
95-
razorDocument.csharpDocument.checksumAlgorithm,
96-
razorDocument.csharpDocument.encodingCodePage
115+
changes,
116+
response.originalChecksum,
117+
response.originalChecksumAlgorithm,
118+
response.originalEncodingCodePage
97119
);
98120
}
99121
} catch (error) {

src/razor/src/dynamicFile/provideDynamicFileParams.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ import { TextDocumentIdentifier } from 'vscode-languageserver-protocol';
77

88
// matches https://github.com/dotnet/roslyn/blob/9e91ca6590450e66e0041ee3135bbf044ac0687a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/RazorDynamicFileInfoProvider.cs#L22
99
export class ProvideDynamicFileParams {
10-
constructor(public readonly razorDocument: TextDocumentIdentifier) {}
10+
constructor(public readonly razorDocument: TextDocumentIdentifier, public readonly fullText: boolean) {}
1111
}

src/razor/src/dynamicFile/provideDynamicFileResponse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class ProvideDynamicFileResponse {
1111
constructor(
1212
public readonly csharpDocument: TextDocumentIdentifier | null,
1313
public readonly edits: ServerTextChange[] | null,
14-
public readonly checksum: Uint8Array,
14+
public readonly checksum: string,
1515
public readonly checksumAlgorithm: number,
1616
public readonly encodingCodePage: number | null
1717
) {}

src/razor/src/html/htmlProjectedDocument.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ export class HtmlProjectedDocument implements IProjectedDocument {
1212
public readonly path: string;
1313
private content = '';
1414
private hostDocumentVersion: number | null = null;
15-
private _checksum: Uint8Array = new Uint8Array();
16-
private _checksumAlgorithm: number = 0;
17-
private _encodingCodePage: number | null = null;
1815

1916
public constructor(public readonly uri: vscode.Uri) {
2017
this.path = getUriPath(uri);
@@ -32,13 +29,7 @@ export class HtmlProjectedDocument implements IProjectedDocument {
3229
this.setContent('');
3330
}
3431

35-
public update(
36-
edits: ServerTextChange[],
37-
hostDocumentVersion: number,
38-
checksum: Uint8Array,
39-
checksumAlgorithm: number,
40-
encodingCodePage: number | null
41-
) {
32+
public update(edits: ServerTextChange[], hostDocumentVersion: number) {
4233
this.hostDocumentVersion = hostDocumentVersion;
4334

4435
if (edits.length === 0) {
@@ -52,27 +43,12 @@ export class HtmlProjectedDocument implements IProjectedDocument {
5243
}
5344

5445
this.setContent(content);
55-
this._checksum = checksum;
56-
this._checksumAlgorithm = checksumAlgorithm;
57-
this._encodingCodePage = encodingCodePage;
5846
}
5947

6048
public getContent() {
6149
return this.content;
6250
}
6351

64-
public get checksum(): Uint8Array {
65-
return this._checksum;
66-
}
67-
68-
public get checksumAlgorithm(): number {
69-
return this._checksumAlgorithm;
70-
}
71-
72-
public get encodingCodePage(): number | null {
73-
return this._encodingCodePage;
74-
}
75-
7652
private getEditedContent(newText: string, start: number, end: number, content: string) {
7753
const before = content.substr(0, start);
7854
const after = content.substr(end);

src/razor/src/projection/IProjectedDocument.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,4 @@ export interface IProjectedDocument {
1111
readonly hostDocumentSyncVersion: number | null;
1212
readonly length: number;
1313
getContent(): string;
14-
checksum: Uint8Array;
15-
checksumAlgorithm: number;
16-
encodingCodePage: number | null;
1714
}

src/razor/src/rpc/updateBufferRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class UpdateBufferRequest {
1111
public readonly hostDocumentFilePath: string,
1212
public readonly changes: ServerTextChange[],
1313
public readonly previousWasEmpty: boolean,
14-
public readonly checksum: Uint8Array,
14+
public readonly checksum: string,
1515
public readonly checksumAlgorithm: number,
1616
public readonly encodingCodePage: number | null
1717
) {}

0 commit comments

Comments
 (0)