Skip to content
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

Revert incremental change forwarding #4477

Merged
merged 2 commits into from
Apr 6, 2021
Merged
Changes from 1 commit
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
52 changes: 5 additions & 47 deletions src/features/changeForwarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,24 @@
import { Uri, workspace } from 'vscode';
import { OmniSharpServer } from '../omnisharp/server';
import * as serverUtils from '../omnisharp/utils';
import { FileChangeType, LinePositionSpanTextChange } from '../omnisharp/protocol';
import { FileChangeType } from '../omnisharp/protocol';
import { IDisposable } from '../Disposable';
import CompositeDisposable from '../CompositeDisposable';

function forwardDocumentChanges(server: OmniSharpServer): IDisposable {

return workspace.onDidChangeTextDocument(event => {

let { document, contentChanges } = event;
let { document } = event;
333fred marked this conversation as resolved.
Show resolved Hide resolved
if (document.isUntitled || document.languageId !== 'csharp' || document.uri.scheme !== 'file') {
return;
}

333fred marked this conversation as resolved.
Show resolved Hide resolved
if (contentChanges.length === 0) {
// This callback fires with no changes when a document's state changes between "clean" and "dirty".
return;
}

if (!server.isRunning()) {
return;
}

const lineChanges = contentChanges.map(function (change): LinePositionSpanTextChange {
const range = change.range;
return {
NewText: change.text,
StartLine: range.start.line,
StartColumn: range.start.character,
EndLine: range.end.line,
EndColumn: range.end.character
};
});

serverUtils.updateBuffer(server, { Changes: lineChanges, FileName: document.fileName, ApplyChangesTogether: true }).catch(err => {
serverUtils.updateBuffer(server, { Buffer: document.getText(), FileName: document.fileName }).catch(err => {
console.error(err);
return err;
});
Expand All @@ -54,28 +38,7 @@ function forwardFileChanges(server: OmniSharpServer): IDisposable {
return;
}

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

const req = { FileName: uri.fsPath, changeType };
let req = { FileName: uri.fsPath, changeType };

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

function isCSharpCodeFile(uri: Uri) : Boolean {
const normalized = uri.path.toLocaleLowerCase();
return normalized.endsWith(".cs") || normalized.endsWith(".csx") || normalized.endsWith(".cake");
}

function onFolderEvent(changeType: FileChangeType): (uri: Uri) => void {
return async function (uri: Uri) {
if (!server.isRunning()) {
return;
}

if (changeType === FileChangeType.Delete) {
const requests = [{ FileName: uri.fsPath, changeType: FileChangeType.DirectoryDelete }];
let requests = [{ FileName: uri.fsPath, changeType: FileChangeType.DirectoryDelete }];

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