Skip to content

[release] Ignore updates with no changes for csharp files #8170

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

Merged
merged 3 commits into from
Apr 11, 2025
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
2 changes: 2 additions & 0 deletions src/razor/src/document/IRazorDocumentChangeEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ServerTextChange } from '../rpc/serverTextChange';
import { IRazorDocument } from './IRazorDocument';
import { RazorDocumentChangeKind } from './razorDocumentChangeKind';

export interface IRazorDocumentChangeEvent {
readonly document: IRazorDocument;
readonly kind: RazorDocumentChangeKind;
readonly changes: ServerTextChange[];
}
20 changes: 12 additions & 8 deletions src/razor/src/document/razorDocumentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { createDocument } from './razorDocumentFactory';
import { razorInitializeCommand } from '../../../lsptoolshost/razor/razorCommands';
import { PlatformInformation } from '../../../shared/platform';
import { v4 as uuidv4 } from 'uuid';
import { ServerTextChange } from '../rpc/serverTextChange';

export class RazorDocumentManager implements IRazorDocumentManager {
public roslynActivated = false;
Expand Down Expand Up @@ -158,7 +159,7 @@ export class RazorDocumentManager implements IRazorDocumentManager {

const document = this._getDocument(uri);

this.notifyDocumentChange(document, RazorDocumentChangeKind.opened);
this.notifyDocumentChange(document, RazorDocumentChangeKind.opened, []);
}

public async ensureRazorInitialized() {
Expand Down Expand Up @@ -189,7 +190,7 @@ export class RazorDocumentManager implements IRazorDocumentManager {
}
}

this.notifyDocumentChange(document, RazorDocumentChangeKind.closed);
this.notifyDocumentChange(document, RazorDocumentChangeKind.closed, []);
}

private addDocument(uri: vscode.Uri): IRazorDocument {
Expand All @@ -203,7 +204,7 @@ export class RazorDocumentManager implements IRazorDocumentManager {
document = createDocument(uri);
this.razorDocuments[document.path] = document;

this.notifyDocumentChange(document, RazorDocumentChangeKind.added);
this.notifyDocumentChange(document, RazorDocumentChangeKind.added, []);

return document;
}
Expand All @@ -212,7 +213,7 @@ export class RazorDocumentManager implements IRazorDocumentManager {
const document = this._getDocument(uri);
delete this.razorDocuments[document.path];

this.notifyDocumentChange(document, RazorDocumentChangeKind.removed);
this.notifyDocumentChange(document, RazorDocumentChangeKind.removed, []);
}

private findDocument(path: string) {
Expand Down Expand Up @@ -267,7 +268,7 @@ export class RazorDocumentManager implements IRazorDocumentManager {
updateBufferRequest.encodingCodePage
);

this.notifyDocumentChange(document, RazorDocumentChangeKind.csharpChanged);
this.notifyDocumentChange(document, RazorDocumentChangeKind.csharpChanged, updateBufferRequest.changes);
} else {
this.logger.logWarning(
'Failed to update the C# document buffer. This is unexpected and may result in incorrect C# interactions.'
Expand Down Expand Up @@ -310,24 +311,27 @@ export class RazorDocumentManager implements IRazorDocumentManager {

htmlProjectedDocument.update(updateBufferRequest.changes, updateBufferRequest.hostDocumentVersion);

this.notifyDocumentChange(document, RazorDocumentChangeKind.htmlChanged);
this.notifyDocumentChange(document, RazorDocumentChangeKind.htmlChanged, updateBufferRequest.changes);
} else {
this.logger.logWarning(
'Failed to update the HTML document buffer. This is unexpected and may result in incorrect HTML interactions.'
);
}
}

private notifyDocumentChange(document: IRazorDocument, kind: RazorDocumentChangeKind) {
private notifyDocumentChange(document: IRazorDocument, kind: RazorDocumentChangeKind, changes: ServerTextChange[]) {
if (this.logger.verboseEnabled) {
this.logger.logVerbose(
`Notifying document '${getUriPath(document.uri)}' changed '${RazorDocumentChangeKind[kind]}'`
`Notifying document '${getUriPath(document.uri)}' changed '${RazorDocumentChangeKind[kind]}' with '${
changes.length
}' changes.`
);
}

const args: IRazorDocumentChangeEvent = {
document,
kind,
changes,
};

this.onChangeEmitter.fire(args);
Expand Down
4 changes: 3 additions & 1 deletion src/razor/src/dynamicFile/dynamicFileInfoHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export class DynamicFileInfoHandler {
}
);
this.documentManager.onChange(async (e) => {
if (e.kind == RazorDocumentChangeKind.csharpChanged && !e.document.isOpen) {
// Ignore any updates without text changes. This is important for perf since sending an update to roslyn does
// a round trip for producing nothing new and causes a lot of churn in solution updates.
if (e.kind == RazorDocumentChangeKind.csharpChanged && !e.document.isOpen && e.changes.length > 0) {
const uriString = UriConverter.serialize(e.document.uri);
const identifier = TextDocumentIdentifier.create(uriString);
await vscode.commands.executeCommand(
Expand Down
Loading