mirror of
https://github.com/microsoft/vscode.git
synced 2026-08-25 10:25:41 +01:00
fix tests, use real diff (slow) (#203022)
This commit is contained in:
@@ -40,6 +40,8 @@ import { CTX_INLINE_CHAT_USER_DID_EDIT, EditMode, IInlineChatService, InlineChat
|
||||
import { InlineChatServiceImpl } from 'vs/workbench/contrib/inlineChat/common/inlineChatServiceImpl';
|
||||
import { workbenchInstantiationService } from 'vs/workbench/test/browser/workbenchTestServices';
|
||||
import { EditOperation } from 'vs/editor/common/core/editOperation';
|
||||
import { TestWorkerService } from './testWorkerService';
|
||||
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorker';
|
||||
|
||||
suite('InteractiveChatController', function () {
|
||||
class TestController extends InlineChatController {
|
||||
@@ -106,6 +108,7 @@ suite('InteractiveChatController', function () {
|
||||
configurationService.setUserConfiguration('editor', {});
|
||||
|
||||
const serviceCollection = new ServiceCollection(
|
||||
[IEditorWorkerService, new SyncDescriptor(TestWorkerService)],
|
||||
[IContextKeyService, contextKeyService],
|
||||
[IInlineChatService, inlineChatService],
|
||||
[IDiffProviderFactoryService, new SyncDescriptor(TestDiffProviderFactoryService)],
|
||||
@@ -263,7 +266,7 @@ suite('InteractiveChatController', function () {
|
||||
|
||||
const session = inlineChatSessionService.getSession(editor, editor.getModel()!.uri);
|
||||
assert.ok(session);
|
||||
assert.deepStrictEqual(session.wholeRange.value, new Range(1, 1, 1, 6));
|
||||
assert.deepStrictEqual(session.wholeRange.value, new Range(1, 1, 1, 10 /* line length */));
|
||||
|
||||
editor.setSelection(new Range(2, 1, 2, 1));
|
||||
editor.trigger('test', 'type', { text: 'a' });
|
||||
@@ -299,19 +302,19 @@ suite('InteractiveChatController', function () {
|
||||
store.add(d);
|
||||
ctrl = instaService.createInstance(TestController, editor);
|
||||
const p = ctrl.waitFor(TestController.INIT_SEQUENCE);
|
||||
const r = ctrl.run({ message: 'Hello', autoSend: false });
|
||||
const r = ctrl.run({ message: 'GENGEN', autoSend: false });
|
||||
|
||||
await p;
|
||||
|
||||
const session = inlineChatSessionService.getSession(editor, editor.getModel()!.uri);
|
||||
assert.ok(session);
|
||||
assert.deepStrictEqual(session.wholeRange.value, new Range(3, 1, 3, 3));
|
||||
assert.deepStrictEqual(session.wholeRange.value, new Range(3, 1, 3, 3)); // initial
|
||||
|
||||
ctrl.acceptInput();
|
||||
|
||||
await ctrl.waitFor([State.MAKE_REQUEST, State.APPLY_RESPONSE, State.SHOW_RESPONSE, State.WAIT_FOR_INPUT]);
|
||||
|
||||
assert.deepStrictEqual(session.wholeRange.value, new Range(4, 1, 4, 3));
|
||||
assert.deepStrictEqual(session.wholeRange.value, new Range(1, 1, 4, 3));
|
||||
|
||||
await ctrl.cancelSession();
|
||||
await r;
|
||||
|
||||
@@ -41,12 +41,8 @@ import { assertType } from 'vs/base/common/types';
|
||||
import { InlineChatServiceImpl } from 'vs/workbench/contrib/inlineChat/common/inlineChatServiceImpl';
|
||||
import { EditOperation } from 'vs/editor/common/core/editOperation';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { DiffAlgorithmName, IEditorWorkerService, ILineChange } from 'vs/editor/common/services/editorWorker';
|
||||
import { IDocumentDiff, IDocumentDiffProviderOptions } from 'vs/editor/common/diff/documentDiffProvider';
|
||||
import { EditorSimpleWorker } from 'vs/editor/common/services/editorSimpleWorker';
|
||||
import { LineRange } from 'vs/editor/common/core/lineRange';
|
||||
import { MovedText } from 'vs/editor/common/diff/linesDiffComputer';
|
||||
import { LineRangeMapping, DetailedLineRangeMapping, RangeMapping } from 'vs/editor/common/diff/rangeMapping';
|
||||
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorker';
|
||||
import { TestWorkerService } from './testWorkerService';
|
||||
|
||||
|
||||
suite('ReplyResponse', function () {
|
||||
@@ -86,69 +82,6 @@ suite('ReplyResponse', function () {
|
||||
});
|
||||
});
|
||||
|
||||
class TestWorkerService extends mock<IEditorWorkerService>() {
|
||||
|
||||
private readonly _worker = new EditorSimpleWorker(null!, null);
|
||||
|
||||
constructor(@IModelService private readonly _modelService: IModelService) {
|
||||
super();
|
||||
}
|
||||
|
||||
override async computeDiff(original: URI, modified: URI, options: IDocumentDiffProviderOptions, algorithm: DiffAlgorithmName): Promise<IDocumentDiff | null> {
|
||||
|
||||
const originalModel = this._modelService.getModel(original);
|
||||
const modifiedModel = this._modelService.getModel(modified);
|
||||
|
||||
assertType(originalModel);
|
||||
assertType(modifiedModel);
|
||||
|
||||
this._worker.acceptNewModel({
|
||||
url: originalModel.uri.toString(),
|
||||
versionId: originalModel.getVersionId(),
|
||||
lines: originalModel.getLinesContent(),
|
||||
EOL: originalModel.getEOL(),
|
||||
});
|
||||
|
||||
this._worker.acceptNewModel({
|
||||
url: modifiedModel.uri.toString(),
|
||||
versionId: modifiedModel.getVersionId(),
|
||||
lines: modifiedModel.getLinesContent(),
|
||||
EOL: modifiedModel.getEOL(),
|
||||
});
|
||||
|
||||
const result = await this._worker.computeDiff(originalModel.uri.toString(), modifiedModel.uri.toString(), options, algorithm);
|
||||
if (!result) {
|
||||
return result;
|
||||
}
|
||||
// Convert from space efficient JSON data to rich objects.
|
||||
const diff: IDocumentDiff = {
|
||||
identical: result.identical,
|
||||
quitEarly: result.quitEarly,
|
||||
changes: toLineRangeMappings(result.changes),
|
||||
moves: result.moves.map(m => new MovedText(
|
||||
new LineRangeMapping(new LineRange(m[0], m[1]), new LineRange(m[2], m[3])),
|
||||
toLineRangeMappings(m[4])
|
||||
))
|
||||
};
|
||||
return diff;
|
||||
|
||||
function toLineRangeMappings(changes: readonly ILineChange[]): readonly DetailedLineRangeMapping[] {
|
||||
return changes.map(
|
||||
(c) => new DetailedLineRangeMapping(
|
||||
new LineRange(c[0], c[1]),
|
||||
new LineRange(c[2], c[3]),
|
||||
c[4]?.map(
|
||||
(c) => new RangeMapping(
|
||||
new Range(c[0], c[1], c[2], c[3]),
|
||||
new Range(c[4], c[5], c[6], c[7])
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suite('InlineChatSession', function () {
|
||||
|
||||
const store = new DisposableStore();
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { mock } from 'vs/base/test/common/mock';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { IModelService } from 'vs/editor/common/services/model';
|
||||
import { assertType } from 'vs/base/common/types';
|
||||
import { DiffAlgorithmName, IEditorWorkerService, ILineChange } from 'vs/editor/common/services/editorWorker';
|
||||
import { IDocumentDiff, IDocumentDiffProviderOptions } from 'vs/editor/common/diff/documentDiffProvider';
|
||||
import { EditorSimpleWorker } from 'vs/editor/common/services/editorSimpleWorker';
|
||||
import { LineRange } from 'vs/editor/common/core/lineRange';
|
||||
import { MovedText } from 'vs/editor/common/diff/linesDiffComputer';
|
||||
import { LineRangeMapping, DetailedLineRangeMapping, RangeMapping } from 'vs/editor/common/diff/rangeMapping';
|
||||
import { TextEdit } from 'vs/editor/common/languages';
|
||||
|
||||
|
||||
export class TestWorkerService extends mock<IEditorWorkerService>() {
|
||||
|
||||
private readonly _worker = new EditorSimpleWorker(null!, null);
|
||||
|
||||
constructor(@IModelService private readonly _modelService: IModelService) {
|
||||
super();
|
||||
}
|
||||
|
||||
override async computeMoreMinimalEdits(resource: URI, edits: TextEdit[] | null | undefined, pretty?: boolean | undefined): Promise<TextEdit[] | undefined> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
override async computeDiff(original: URI, modified: URI, options: IDocumentDiffProviderOptions, algorithm: DiffAlgorithmName): Promise<IDocumentDiff | null> {
|
||||
|
||||
const originalModel = this._modelService.getModel(original);
|
||||
const modifiedModel = this._modelService.getModel(modified);
|
||||
|
||||
assertType(originalModel);
|
||||
assertType(modifiedModel);
|
||||
|
||||
this._worker.acceptNewModel({
|
||||
url: originalModel.uri.toString(),
|
||||
versionId: originalModel.getVersionId(),
|
||||
lines: originalModel.getLinesContent(),
|
||||
EOL: originalModel.getEOL(),
|
||||
});
|
||||
|
||||
this._worker.acceptNewModel({
|
||||
url: modifiedModel.uri.toString(),
|
||||
versionId: modifiedModel.getVersionId(),
|
||||
lines: modifiedModel.getLinesContent(),
|
||||
EOL: modifiedModel.getEOL(),
|
||||
});
|
||||
|
||||
const result = await this._worker.computeDiff(originalModel.uri.toString(), modifiedModel.uri.toString(), options, algorithm);
|
||||
if (!result) {
|
||||
return result;
|
||||
}
|
||||
// Convert from space efficient JSON data to rich objects.
|
||||
const diff: IDocumentDiff = {
|
||||
identical: result.identical,
|
||||
quitEarly: result.quitEarly,
|
||||
changes: toLineRangeMappings(result.changes),
|
||||
moves: result.moves.map(m => new MovedText(
|
||||
new LineRangeMapping(new LineRange(m[0], m[1]), new LineRange(m[2], m[3])),
|
||||
toLineRangeMappings(m[4])
|
||||
))
|
||||
};
|
||||
return diff;
|
||||
|
||||
function toLineRangeMappings(changes: readonly ILineChange[]): readonly DetailedLineRangeMapping[] {
|
||||
return changes.map(
|
||||
(c) => new DetailedLineRangeMapping(
|
||||
new LineRange(c[0], c[1]),
|
||||
new LineRange(c[2], c[3]),
|
||||
c[4]?.map(
|
||||
(c) => new RangeMapping(
|
||||
new Range(c[0], c[1], c[2], c[3]),
|
||||
new Range(c[4], c[5], c[6], c[7])
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user