mirror of
https://github.com/Microsoft/vscode
synced 2024-11-05 18:29:38 +00:00
add "pretty" option to computeMoreMinimalEdits
This commit is contained in:
parent
b5827cf895
commit
97f069093e
4 changed files with 12 additions and 12 deletions
|
@ -131,13 +131,13 @@ export class EditorWorkerService extends Disposable implements IEditorWorkerServ
|
|||
return this._workerManager.withWorker().then(client => client.computeDirtyDiff(original, modified, ignoreTrimWhitespace));
|
||||
}
|
||||
|
||||
public computeMoreMinimalEdits(resource: URI, edits: languages.TextEdit[] | null | undefined): Promise<languages.TextEdit[] | undefined> {
|
||||
public computeMoreMinimalEdits(resource: URI, edits: languages.TextEdit[] | null | undefined, pretty: boolean = false): Promise<languages.TextEdit[] | undefined> {
|
||||
if (isNonEmptyArray(edits)) {
|
||||
if (!canSyncModel(this._modelService, resource)) {
|
||||
return Promise.resolve(edits); // File too large
|
||||
}
|
||||
const sw = StopWatch.create(true);
|
||||
const result = this._workerManager.withWorker().then(client => client.computeMoreMinimalEdits(resource, edits));
|
||||
const result = this._workerManager.withWorker().then(client => client.computeMoreMinimalEdits(resource, edits, pretty));
|
||||
result.finally(() => this._logService.trace('FORMAT#computeMoreMinimalEdits', resource.toString(true), sw.elapsed()));
|
||||
return Promise.race([result, timeout(1000).then(() => edits)]);
|
||||
|
||||
|
@ -528,9 +528,9 @@ export class EditorWorkerClient extends Disposable implements IEditorWorkerClien
|
|||
});
|
||||
}
|
||||
|
||||
public computeMoreMinimalEdits(resource: URI, edits: languages.TextEdit[]): Promise<languages.TextEdit[]> {
|
||||
public computeMoreMinimalEdits(resource: URI, edits: languages.TextEdit[], pretty: boolean): Promise<languages.TextEdit[]> {
|
||||
return this._withSyncedResources([resource]).then(proxy => {
|
||||
return proxy.computeMoreMinimalEdits(resource.toString(), edits);
|
||||
return proxy.computeMoreMinimalEdits(resource.toString(), edits, pretty);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -461,7 +461,7 @@ export class EditorSimpleWorker implements IRequestHandler, IDisposable {
|
|||
|
||||
private static readonly _diffLimit = 100000;
|
||||
|
||||
public async computeMoreMinimalEdits(modelUrl: string, edits: TextEdit[]): Promise<TextEdit[]> {
|
||||
public async computeMoreMinimalEdits(modelUrl: string, edits: TextEdit[], pretty: boolean): Promise<TextEdit[]> {
|
||||
const model = this._getModel(modelUrl);
|
||||
if (!model) {
|
||||
return edits;
|
||||
|
@ -506,7 +506,7 @@ export class EditorSimpleWorker implements IRequestHandler, IDisposable {
|
|||
}
|
||||
|
||||
// compute diff between original and edit.text
|
||||
const changes = stringDiff(original, text, false);
|
||||
const changes = stringDiff(original, text, pretty);
|
||||
const editOffset = model.offsetAt(Range.lift(range).getStartPosition());
|
||||
|
||||
for (const change of changes) {
|
||||
|
|
|
@ -28,7 +28,7 @@ export interface IEditorWorkerService {
|
|||
canComputeDirtyDiff(original: URI, modified: URI): boolean;
|
||||
computeDirtyDiff(original: URI, modified: URI, ignoreTrimWhitespace: boolean): Promise<IChange[] | null>;
|
||||
|
||||
computeMoreMinimalEdits(resource: URI, edits: TextEdit[] | null | undefined): Promise<TextEdit[] | undefined>;
|
||||
computeMoreMinimalEdits(resource: URI, edits: TextEdit[] | null | undefined, pretty?: boolean): Promise<TextEdit[] | undefined>;
|
||||
|
||||
canComputeWordRanges(resource: URI): boolean;
|
||||
computeWordRanges(resource: URI, range: IRange): Promise<{ [word: string]: IRange[] } | null>;
|
||||
|
|
|
@ -88,7 +88,7 @@ suite('EditorSimpleWorker', () => {
|
|||
|
||||
test('MoreMinimal', () => {
|
||||
|
||||
return worker.computeMoreMinimalEdits(model.uri.toString(), [{ text: 'This is line One', range: new Range(1, 1, 1, 17) }]).then(edits => {
|
||||
return worker.computeMoreMinimalEdits(model.uri.toString(), [{ text: 'This is line One', range: new Range(1, 1, 1, 17) }], false).then(edits => {
|
||||
assert.strictEqual(edits.length, 1);
|
||||
const [first] = edits;
|
||||
assert.strictEqual(first.text, 'O');
|
||||
|
@ -104,7 +104,7 @@ suite('EditorSimpleWorker', () => {
|
|||
'}'
|
||||
], '\n');
|
||||
|
||||
return worker.computeMoreMinimalEdits(model.uri.toString(), [{ text: '{\r\n\t"a":1\r\n}', range: new Range(1, 1, 3, 2) }]).then(edits => {
|
||||
return worker.computeMoreMinimalEdits(model.uri.toString(), [{ text: '{\r\n\t"a":1\r\n}', range: new Range(1, 1, 3, 2) }], false).then(edits => {
|
||||
assert.strictEqual(edits.length, 0);
|
||||
});
|
||||
});
|
||||
|
@ -117,7 +117,7 @@ suite('EditorSimpleWorker', () => {
|
|||
'}'
|
||||
], '\n');
|
||||
|
||||
return worker.computeMoreMinimalEdits(model.uri.toString(), [{ text: '{\r\n\t"b":1\r\n}', range: new Range(1, 1, 3, 2) }]).then(edits => {
|
||||
return worker.computeMoreMinimalEdits(model.uri.toString(), [{ text: '{\r\n\t"b":1\r\n}', range: new Range(1, 1, 3, 2) }], false).then(edits => {
|
||||
assert.strictEqual(edits.length, 1);
|
||||
const [first] = edits;
|
||||
assert.strictEqual(first.text, 'b');
|
||||
|
@ -125,7 +125,7 @@ suite('EditorSimpleWorker', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('MoreMinimal, issue #15385 newline changes and other', function () {
|
||||
test('MoreMinimal, issue #15385 newline changes and other 2/2', function () {
|
||||
|
||||
const model = worker.addModel([
|
||||
'package main', // 1
|
||||
|
@ -133,7 +133,7 @@ suite('EditorSimpleWorker', () => {
|
|||
'}' // 3
|
||||
]);
|
||||
|
||||
return worker.computeMoreMinimalEdits(model.uri.toString(), [{ text: '\n', range: new Range(3, 2, 4, 1000) }]).then(edits => {
|
||||
return worker.computeMoreMinimalEdits(model.uri.toString(), [{ text: '\n', range: new Range(3, 2, 4, 1000) }], false).then(edits => {
|
||||
assert.strictEqual(edits.length, 1);
|
||||
const [first] = edits;
|
||||
assert.strictEqual(first.text, '\n');
|
||||
|
|
Loading…
Reference in a new issue