mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 02:28:34 +01:00
use IRawText and compare before pretending things have changed, #18664
This commit is contained in:
@@ -122,7 +122,7 @@ export abstract class MainThreadDocumentsShape {
|
||||
$tryCreateDocument(options?: { language: string; }): TPromise<any> { throw ni(); }
|
||||
$tryOpenDocument(uri: URI): TPromise<any> { throw ni(); }
|
||||
$registerTextContentProvider(handle: number, scheme: string): void { throw ni(); }
|
||||
$onVirtualDocumentChange(uri: URI, value: string): void { throw ni(); }
|
||||
$onVirtualDocumentChange(uri: URI, value: editorCommon.IRawText): void { throw ni(); }
|
||||
$unregisterTextContentProvider(handle: number): void { throw ni(); }
|
||||
$trySaveDocument(uri: URI): TPromise<boolean> { throw ni(); }
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { regExpLeadsToEndlessLoop } from 'vs/base/common/strings';
|
||||
import * as editorCommon from 'vs/editor/common/editorCommon';
|
||||
import { RawText } from 'vs/editor/common/model/textModel';
|
||||
import { MirrorModel2 } from 'vs/editor/common/model/mirrorModel2';
|
||||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
@@ -126,7 +127,27 @@ export class ExtHostDocuments extends ExtHostDocumentsShape {
|
||||
subscription = provider.onDidChange(uri => {
|
||||
if (this._documentData.has(uri.toString())) {
|
||||
this.$provideTextDocumentContent(handle, <URI>uri).then(value => {
|
||||
return this._proxy.$onVirtualDocumentChange(<URI>uri, value);
|
||||
|
||||
const document = this._documentData.get(uri.toString());
|
||||
if (!document) {
|
||||
// disposed in the meantime
|
||||
return;
|
||||
}
|
||||
|
||||
// create lines and compare
|
||||
const raw = RawText.fromString(value, {
|
||||
defaultEOL: editorCommon.DefaultEndOfLine.CRLF,
|
||||
tabSize: 0,
|
||||
detectIndentation: false,
|
||||
insertSpaces: false,
|
||||
trimAutoWhitespace: false
|
||||
});
|
||||
|
||||
// broadcast event when content changed
|
||||
if (!document.equalLines(raw)) {
|
||||
return this._proxy.$onVirtualDocumentChange(<URI>uri, raw);
|
||||
}
|
||||
|
||||
}, onUnexpectedError);
|
||||
}
|
||||
});
|
||||
@@ -241,6 +262,19 @@ export class ExtHostDocumentData extends MirrorModel2 {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
equalLines({lines}: editorCommon.IRawText): boolean {
|
||||
const len = lines.length;
|
||||
if (len !== this._lines.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < len; i++) {
|
||||
if (lines[i] !== this._lines[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
get document(): vscode.TextDocument {
|
||||
if (!this._document) {
|
||||
const data = this;
|
||||
|
||||
@@ -8,6 +8,7 @@ import { toErrorMessage } from 'vs/base/common/errorMessage';
|
||||
import { EmitterEvent } from 'vs/base/common/eventEmitter';
|
||||
import { IModelService } from 'vs/editor/common/services/modelService';
|
||||
import * as editorCommon from 'vs/editor/common/editorCommon';
|
||||
import { RawText } from 'vs/editor/common/model/textModel';
|
||||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
@@ -237,10 +238,26 @@ export class MainThreadDocuments extends MainThreadDocumentsShape {
|
||||
}
|
||||
}
|
||||
|
||||
$onVirtualDocumentChange(uri: URI, value: string): void {
|
||||
$onVirtualDocumentChange(uri: URI, value: editorCommon.IRawText): void {
|
||||
const model = this._modelService.getModel(uri);
|
||||
if (model) {
|
||||
model.setValue(value);
|
||||
if (!model) {
|
||||
return;
|
||||
}
|
||||
// fetch the raw text from the ext host but
|
||||
// reuse the current options
|
||||
const {options} = RawText.fromStringWithModelOptions('', model);
|
||||
const raw = <editorCommon.IRawText>{
|
||||
options,
|
||||
lines: value.lines,
|
||||
length: value.length,
|
||||
BOM: value.BOM,
|
||||
EOL: value.EOL,
|
||||
containsRTL: value.containsRTL,
|
||||
isBasicASCII: value.isBasicASCII,
|
||||
};
|
||||
|
||||
if (!model.equals(raw)) {
|
||||
model.setValueFromRawText(raw);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user