Skip to content

Commit 07225f1

Browse files
committed
Revert incremental change forwarding
While I made this change with good intentions (and the perf benefit when working in Roslyn has been very real), this has proven to be more trouble than it's worth. LSP will be the way to get the perf benefits of incremental changes and should prove to be far more robust. This is a checkout of changeForwarding.ts to d26e995. The only other commits to this file since then have been about 0-based indexes, which no longer matters with this revert.
1 parent 737324e commit 07225f1

File tree

1 file changed

+5
-47
lines changed

1 file changed

+5
-47
lines changed

src/features/changeForwarding.ts

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,24 @@
66
import { Uri, workspace } from 'vscode';
77
import { OmniSharpServer } from '../omnisharp/server';
88
import * as serverUtils from '../omnisharp/utils';
9-
import { FileChangeType, LinePositionSpanTextChange } from '../omnisharp/protocol';
9+
import { FileChangeType } from '../omnisharp/protocol';
1010
import { IDisposable } from '../Disposable';
1111
import CompositeDisposable from '../CompositeDisposable';
1212

1313
function forwardDocumentChanges(server: OmniSharpServer): IDisposable {
1414

1515
return workspace.onDidChangeTextDocument(event => {
1616

17-
let { document, contentChanges } = event;
17+
let { document } = event;
1818
if (document.isUntitled || document.languageId !== 'csharp' || document.uri.scheme !== 'file') {
1919
return;
2020
}
2121

22-
if (contentChanges.length === 0) {
23-
// This callback fires with no changes when a document's state changes between "clean" and "dirty".
24-
return;
25-
}
26-
2722
if (!server.isRunning()) {
2823
return;
2924
}
3025

31-
const lineChanges = contentChanges.map(function (change): LinePositionSpanTextChange {
32-
const range = change.range;
33-
return {
34-
NewText: change.text,
35-
StartLine: range.start.line,
36-
StartColumn: range.start.character,
37-
EndLine: range.end.line,
38-
EndColumn: range.end.character
39-
};
40-
});
41-
42-
serverUtils.updateBuffer(server, { Changes: lineChanges, FileName: document.fileName, ApplyChangesTogether: true }).catch(err => {
26+
serverUtils.updateBuffer(server, { Buffer: document.getText(), FileName: document.fileName }).catch(err => {
4327
console.error(err);
4428
return err;
4529
});
@@ -54,28 +38,7 @@ function forwardFileChanges(server: OmniSharpServer): IDisposable {
5438
return;
5539
}
5640

57-
if (changeType === FileChangeType.Change) {
58-
const docs = workspace.textDocuments.filter(doc => doc.uri.fsPath === uri.fsPath && isCSharpCodeFile(doc.uri));
59-
if (Array.isArray(docs) && docs.some(doc => !doc.isClosed)) {
60-
// When a file changes on disk a FileSystemEvent is generated as well as a
61-
// DidChangeTextDocumentEvent.The ordering of these is:
62-
// 1. This method is called back. vscode's TextDocument has not yet been reloaded, so it has
63-
// the version from before the changes are applied.
64-
// 2. vscode reloads the file, and fires onDidChangeTextDocument. The document has been updated,
65-
// and the changes have the delta.
66-
// If we send this change to the server, then it will reload from the disk, which means it will
67-
// be synchronized to the version after the changes. Then, onDidChangeTextDocument will fire and
68-
// send the delta changes, which will cause the server to apply those exact changes. The results
69-
// being that the file is now in an inconsistent state.
70-
// If the document is closed, however, it will no longer be synchronized, so the text change will
71-
// not be triggered and we should tell the server to reread from the disk.
72-
// This applies to C# code files only, not other files significant for OmniSharp
73-
// e.g. csproj or editorconfig files
74-
return;
75-
}
76-
}
77-
78-
const req = { FileName: uri.fsPath, changeType };
41+
let req = { FileName: uri.fsPath, changeType };
7942

8043
serverUtils.filesChanged(server, [req]).catch(err => {
8144
console.warn(`[o] failed to forward file change event for ${uri.fsPath}`, err);
@@ -84,19 +47,14 @@ function forwardFileChanges(server: OmniSharpServer): IDisposable {
8447
};
8548
}
8649

87-
function isCSharpCodeFile(uri: Uri) : Boolean {
88-
const normalized = uri.path.toLocaleLowerCase();
89-
return normalized.endsWith(".cs") || normalized.endsWith(".csx") || normalized.endsWith(".cake");
90-
}
91-
9250
function onFolderEvent(changeType: FileChangeType): (uri: Uri) => void {
9351
return async function (uri: Uri) {
9452
if (!server.isRunning()) {
9553
return;
9654
}
9755

9856
if (changeType === FileChangeType.Delete) {
99-
const requests = [{ FileName: uri.fsPath, changeType: FileChangeType.DirectoryDelete }];
57+
let requests = [{ FileName: uri.fsPath, changeType: FileChangeType.DirectoryDelete }];
10058

10159
serverUtils.filesChanged(server, requests).catch(err => {
10260
console.warn(`[o] failed to forward file change event for ${uri.fsPath}`, err);

0 commit comments

Comments
 (0)