Skip to content

Commit 86d43c5

Browse files
author
Andrew Hall
committed
Add checksum and encoding information to publish data
1 parent 4719d13 commit 86d43c5

File tree

7 files changed

+108
-35
lines changed

7 files changed

+108
-35
lines changed

src/razor/src/csharp/csharpProjectedDocument.ts

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export class CSharpProjectedDocument implements IProjectedDocument {
2020
private ProvisionalDotPosition: Position | undefined;
2121
private hostDocumentVersion: number | null = null;
2222
private updates: Update[] | null = null;
23+
private _checksum: Uint8Array = new Uint8Array();
24+
private _checksumAlgorithm: number = 0;
25+
private _encodingCodePage: number | null = null;
2326

2427
public constructor(public readonly uri: vscode.Uri) {
2528
this.path = getUriPath(uri);
@@ -33,33 +36,55 @@ export class CSharpProjectedDocument implements IProjectedDocument {
3336
return this.content.length;
3437
}
3538

39+
public get checksum(): Uint8Array {
40+
return this._checksum;
41+
}
42+
43+
public get checksumAlgorithm(): number {
44+
return this._checksumAlgorithm;
45+
}
46+
47+
public get encodingCodePage(): number | null {
48+
return this._encodingCodePage;
49+
}
50+
3651
public clear() {
3752
this.setContent('');
3853
}
3954

40-
public update(edits: ServerTextChange[], hostDocumentVersion: number) {
41-
this.removeProvisionalDot();
42-
43-
// Apply any stored edits if needed
44-
if (this.updates) {
45-
for (const update of this.updates) {
46-
this.updateContent(update.changes);
55+
public update(
56+
hostDocumentIsOpen: boolean,
57+
edits: ServerTextChange[],
58+
hostDocumentVersion: number,
59+
checksum: Uint8Array,
60+
checksumAlgorithm: number,
61+
encodingCodePage: number | null
62+
) {
63+
if (hostDocumentIsOpen) {
64+
this.removeProvisionalDot();
65+
66+
// Apply any stored edits if needed
67+
if (this.updates) {
68+
for (const update of this.updates) {
69+
this.updateContent(update.changes);
70+
}
71+
72+
this.updates = null;
4773
}
4874

49-
this.updates = null;
75+
this.updateContent(edits);
76+
} else {
77+
if (this.updates) {
78+
this.updates = this.updates.concat(new Update(edits));
79+
} else {
80+
this.updates = [new Update(edits)];
81+
}
5082
}
5183

84+
this._checksum = checksum;
85+
this._checksumAlgorithm = checksumAlgorithm;
86+
this._encodingCodePage = encodingCodePage;
5287
this.hostDocumentVersion = hostDocumentVersion;
53-
this.updateContent(edits);
54-
}
55-
56-
public storeEdits(edits: ServerTextChange[], hostDocumentVersion: number) {
57-
this.hostDocumentVersion = hostDocumentVersion;
58-
if (this.updates) {
59-
this.updates = this.updates.concat(new Update(edits));
60-
} else {
61-
this.updates = [new Update(edits)];
62-
}
6388
}
6489

6590
public getAndApplyEdits() {

src/razor/src/document/razorDocumentManager.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,14 @@ export class RazorDocumentManager implements IRazorDocumentManager {
258258
csharpProjectedDocument.clear();
259259
}
260260

261-
if (document.isOpen) {
262-
// Make sure the document is open, because updating will cause a didChange event to fire.
263-
await vscode.workspace.openTextDocument(document.csharpDocument.uri);
264-
265-
csharpProjectedDocument.update(updateBufferRequest.changes, updateBufferRequest.hostDocumentVersion);
266-
} else {
267-
csharpProjectedDocument.storeEdits(
268-
updateBufferRequest.changes,
269-
updateBufferRequest.hostDocumentVersion
270-
);
271-
}
261+
csharpProjectedDocument.update(
262+
document.isOpen,
263+
updateBufferRequest.changes,
264+
updateBufferRequest.hostDocumentVersion,
265+
updateBufferRequest.checksum,
266+
updateBufferRequest.checksumAlgorithm,
267+
updateBufferRequest.encodingCodePage
268+
);
272269

273270
this.notifyDocumentChange(document, RazorDocumentChangeKind.csharpChanged);
274271
} else {
@@ -311,7 +308,13 @@ export class RazorDocumentManager implements IRazorDocumentManager {
311308
htmlProjectedDocument.clear();
312309
}
313310

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

316319
this.notifyDocumentChange(document, RazorDocumentChangeKind.htmlChanged);
317320
} else {

src/razor/src/dynamicFile/dynamicFileInfoHandler.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,26 @@ export class DynamicFileInfoHandler {
7575
if (this.documentManager.isRazorDocumentOpenInCSharpWorkspace(vscodeUri)) {
7676
// Open documents have didOpen/didChange to update the csharp buffer. Razor
7777
// does not send edits and instead lets vscode handle them.
78-
return new ProvideDynamicFileResponse({ uri: virtualCsharpUri }, null);
78+
return new ProvideDynamicFileResponse(
79+
{ uri: virtualCsharpUri },
80+
null,
81+
razorDocument.csharpDocument.checksum,
82+
razorDocument.csharpDocument.checksumAlgorithm,
83+
razorDocument.csharpDocument.encodingCodePage
84+
);
7985
} else {
8086
// Closed documents provide edits since the last time they were requested since
8187
// there is no open buffer in vscode corresponding to the csharp content.
8288
const csharpDocument = razorDocument.csharpDocument as CSharpProjectedDocument;
8389
const edits = csharpDocument.getAndApplyEdits();
8490

85-
return new ProvideDynamicFileResponse({ uri: virtualCsharpUri }, edits ?? null);
91+
return new ProvideDynamicFileResponse(
92+
{ uri: virtualCsharpUri },
93+
edits ?? null,
94+
razorDocument.csharpDocument.checksum,
95+
razorDocument.csharpDocument.checksumAlgorithm,
96+
razorDocument.csharpDocument.encodingCodePage
97+
);
8698
}
8799
} catch (error) {
88100
this.logger.logWarning(`${DynamicFileInfoHandler.provideDynamicFileInfoCommand} failed with ${error}`);

src/razor/src/dynamicFile/provideDynamicFileResponse.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { ServerTextChange } from '../rpc/serverTextChange';
1010
export class ProvideDynamicFileResponse {
1111
constructor(
1212
public readonly csharpDocument: TextDocumentIdentifier | null,
13-
public readonly edits: ServerTextChange[] | null
13+
public readonly edits: ServerTextChange[] | null,
14+
public readonly checksum: Uint8Array,
15+
public readonly checksumAlgorithm: number,
16+
public readonly encodingCodePage: number | null
1417
) {}
1518
}

src/razor/src/html/htmlProjectedDocument.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ 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;
1518

1619
public constructor(public readonly uri: vscode.Uri) {
1720
this.path = getUriPath(uri);
@@ -29,7 +32,13 @@ export class HtmlProjectedDocument implements IProjectedDocument {
2932
this.setContent('');
3033
}
3134

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

3544
if (edits.length === 0) {
@@ -43,12 +52,27 @@ export class HtmlProjectedDocument implements IProjectedDocument {
4352
}
4453

4554
this.setContent(content);
55+
this._checksum = checksum;
56+
this._checksumAlgorithm = checksumAlgorithm;
57+
this._encodingCodePage = encodingCodePage;
4658
}
4759

4860
public getContent() {
4961
return this.content;
5062
}
5163

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+
5276
private getEditedContent(newText: string, start: number, end: number, content: string) {
5377
const before = content.substr(0, start);
5478
const after = content.substr(end);

src/razor/src/projection/IProjectedDocument.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ 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;
1417
}

src/razor/src/rpc/updateBufferRequest.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export class UpdateBufferRequest {
1010
public readonly hostDocumentVersion: number,
1111
public readonly hostDocumentFilePath: string,
1212
public readonly changes: ServerTextChange[],
13-
public readonly previousWasEmpty: boolean
13+
public readonly previousWasEmpty: boolean,
14+
public readonly checksum: Uint8Array,
15+
public readonly checksumAlgorithm: number,
16+
public readonly encodingCodePage: number | null
1417
) {}
1518
}

0 commit comments

Comments
 (0)