Skip to content

Commit

Permalink
Fixes #164583. Renames diffAlgo name smart to legacy and experimental…
Browse files Browse the repository at this point in the history
… to advanced.
  • Loading branch information
hediet committed Apr 19, 2023
1 parent 1bb47a1 commit fc8f0a9
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/vs/editor/browser/widget/diffEditorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
diffCodeLens: false,
renderOverviewRuler: true,
diffWordWrap: 'inherit',
diffAlgorithm: 'smart',
diffAlgorithm: 'advanced',
});

if (typeof options.isInEmbeddedEditor !== 'undefined') {
Expand Down Expand Up @@ -2758,7 +2758,7 @@ function validateDiffEditorOptions(options: Readonly<IDiffEditorOptions>, defaul
diffCodeLens: validateBooleanOption(options.diffCodeLens, defaults.diffCodeLens),
renderOverviewRuler: validateBooleanOption(options.renderOverviewRuler, defaults.renderOverviewRuler),
diffWordWrap: validateDiffWordWrap(options.diffWordWrap, defaults.diffWordWrap),
diffAlgorithm: validateStringSetOption(options.diffAlgorithm, defaults.diffAlgorithm, ['smart', 'experimental']),
diffAlgorithm: validateStringSetOption(options.diffAlgorithm, defaults.diffAlgorithm, ['legacy', 'advanced'], { 'smart': 'legacy', 'experimental': 'advanced' }),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class WorkerBasedDocumentDiffProvider implements IDocumentDiffProvider, I
private onDidChangeEventEmitter = new Emitter<void>();
public readonly onDidChange: Event<void> = this.onDidChangeEventEmitter.event;

private diffAlgorithm: DiffAlgorithmName | IDocumentDiffProvider = 'smart';
private diffAlgorithm: DiffAlgorithmName | IDocumentDiffProvider = 'advanced';
private diffAlgorithmOnDidChangeSubscription: IDisposable | undefined = undefined;

constructor(
Expand Down Expand Up @@ -61,5 +61,5 @@ export class WorkerBasedDocumentDiffProvider implements IDocumentDiffProvider, I
}

interface IWorkerBasedDocumentDiffProviderOptions {
readonly diffAlgorithm?: 'smart' | 'experimental' | IDocumentDiffProvider;
readonly diffAlgorithm?: 'legacy' | 'advanced' | IDocumentDiffProvider;
}
8 changes: 4 additions & 4 deletions src/vs/editor/common/config/editorConfigurationSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ const editorConfiguration: IConfigurationNode = {
},
'diffEditor.diffAlgorithm': {
type: 'string',
enum: ['smart', 'experimental'],
default: 'experimental',
enum: ['legacy', 'advanced'],
default: 'advanced',
markdownEnumDescriptions: [
nls.localize('diffAlgorithm.smart', "Uses the default diffing algorithm."),
nls.localize('diffAlgorithm.experimental', "Uses an experimental diffing algorithm."),
nls.localize('diffAlgorithm.legacy', "Uses the legacy diffing algorithm."),
nls.localize('diffAlgorithm.advanced', "Uses the advanced diffing algorithm."),
]
},
}
Expand Down
7 changes: 5 additions & 2 deletions src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ export interface IDiffEditorBaseOptions {
/**
* Diff Algorithm
*/
diffAlgorithm?: 'smart' | 'experimental' | IDocumentDiffProvider;
diffAlgorithm?: 'legacy' | 'advanced' | IDocumentDiffProvider;
}

/**
Expand Down Expand Up @@ -1128,10 +1128,13 @@ class EditorStringOption<K extends EditorOption> extends SimpleEditorOption<K, s
/**
* @internal
*/
export function stringSet<T>(value: T | undefined, defaultValue: T, allowedValues: ReadonlyArray<T>): T {
export function stringSet<T>(value: T | undefined, defaultValue: T, allowedValues: ReadonlyArray<T>, renamedValues?: Record<string, T>): T {
if (typeof value !== 'string') {
return defaultValue;
}
if (renamedValues && value in renamedValues) {
return renamedValues[value];
}
if (allowedValues.indexOf(value) === -1) {
return defaultValue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/common/diff/linesDiffComputers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import { SmartLinesDiffComputer } from 'vs/editor/common/diff/smartLinesDiffComp
import { StandardLinesDiffComputer } from 'vs/editor/common/diff/standardLinesDiffComputer';

export const linesDiffComputers = {
smart: new SmartLinesDiffComputer(),
experimental: new StandardLinesDiffComputer(),
legacy: new SmartLinesDiffComputer(),
advanced: new StandardLinesDiffComputer(),
};
4 changes: 2 additions & 2 deletions src/vs/editor/common/services/editorSimpleWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ export class EditorSimpleWorker implements IRequestHandler, IDisposable {
}

private static computeDiff(originalTextModel: ICommonModel | ITextModel, modifiedTextModel: ICommonModel | ITextModel, options: IDocumentDiffProviderOptions, algorithm: DiffAlgorithmName): IDiffComputationResult {
const diffAlgorithm: ILinesDiffComputer = algorithm === 'experimental' ? linesDiffComputers.experimental : linesDiffComputers.smart;
const diffAlgorithm: ILinesDiffComputer = algorithm === 'advanced' ? linesDiffComputers.advanced : linesDiffComputers.legacy;

const originalLines = originalTextModel.getLinesContent();
const modifiedLines = modifiedTextModel.getLinesContent();
Expand Down Expand Up @@ -580,7 +580,7 @@ export class EditorSimpleWorker implements IRequestHandler, IDisposable {
const originalLines = original.split(/\r\n|\n|\r/);
const modifiedLines = text.split(/\r\n|\n|\r/);

const diff = linesDiffComputers.experimental.computeDiff(originalLines, modifiedLines, options);
const diff = linesDiffComputers.advanced.computeDiff(originalLines, modifiedLines, options);

const start = Range.lift(range).getStartPosition();

Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/common/services/editorWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { EditorSimpleWorker } from 'vs/editor/common/services/editorSimpleW

export const IEditorWorkerService = createDecorator<IEditorWorkerService>('editorWorkerService');

export type DiffAlgorithmName = 'smart' | 'experimental';
export type DiffAlgorithmName = 'legacy' | 'advanced';

export interface IEditorWorkerService {
readonly _serviceBrand: undefined;
Expand Down
8 changes: 4 additions & 4 deletions src/vs/editor/test/node/diffing/diffingFixture.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ suite('diff fixtures', () => {
const fixturesSrcDir = resolve(fixturesOutDir).replaceAll('\\', '/').replace('/out/vs/editor/', '/src/vs/editor/');
const folders = readdirSync(fixturesSrcDir);

function runTest(folder: string, diffingAlgoName: 'smart' | 'experimental') {
function runTest(folder: string, diffingAlgoName: 'legacy' | 'advanced') {
const folderPath = join(fixturesSrcDir, folder);
const files = readdirSync(folderPath);

Expand All @@ -29,7 +29,7 @@ suite('diff fixtures', () => {
const secondContent = readFileSync(join(folderPath, secondFileName), 'utf8').replaceAll('\r\n', '\n').replaceAll('\r', '\n');
const secondContentLines = secondContent.split(/\n/);

const diffingAlgo = diffingAlgoName === 'smart' ? new SmartLinesDiffComputer() : new StandardLinesDiffComputer();
const diffingAlgo = diffingAlgoName === 'legacy' ? new SmartLinesDiffComputer() : new StandardLinesDiffComputer();

const diff = diffingAlgo.computeDiff(firstContentLines, secondContentLines, { ignoreTrimWhitespace: false, maxComputationTimeMs: Number.MAX_SAFE_INTEGER });

Expand Down Expand Up @@ -91,11 +91,11 @@ suite('diff fixtures', () => {
}

test(`uiae`, () => {
runTest('subword', 'experimental');
runTest('subword', 'advanced');
});

for (const folder of folders) {
for (const diffingAlgoName of ['smart', 'experimental'] as const) {
for (const diffingAlgoName of ['legacy', 'advanced'] as const) {
test(`${folder}-${diffingAlgoName}`, () => {
runTest(folder, diffingAlgoName);
});
Expand Down
2 changes: 1 addition & 1 deletion src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3803,7 +3803,7 @@ declare namespace monaco.editor {
/**
* Diff Algorithm
*/
diffAlgorithm?: 'smart' | 'experimental' | IDocumentDiffProvider;
diffAlgorithm?: 'legacy' | 'advanced' | IDocumentDiffProvider;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const _previewEditorEditorOptions: IDiffEditorConstructionOptions = {
stickyScroll: { enabled: false },
originalAriaLabel: localize('modified', 'Modified'),
modifiedAriaLabel: localize('original', 'Original'),
diffAlgorithm: 'smart',
diffAlgorithm: 'advanced',
readOnly: true,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfigurat
properties: {
'mergeEditor.diffAlgorithm': {
type: 'string',
enum: ['smart', 'experimental'],
default: 'experimental',
enum: ['legacy', 'advanced'],
default: 'advanced',
markdownEnumDescriptions: [
localize('diffAlgorithm.smart', "Uses the default diffing algorithm."),
localize('diffAlgorithm.experimental', "Uses an experimental diffing algorithm."),
localize('diffAlgorithm.legacy', "Uses the legacy diffing algorithm."),
localize('diffAlgorithm.advanced', "Uses the advanced diffing algorithm."),
]
},
'mergeEditor.showDeletionMarkers': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export interface IMergeDiffComputerResult {
}

export class MergeDiffComputer implements IMergeDiffComputer {
private readonly mergeAlgorithm = observableConfigValue<'smart' | 'experimental'>('mergeEditor.diffAlgorithm', 'experimental', this.configurationService);
private readonly mergeAlgorithm = observableConfigValue<'smart' | 'experimental' | 'legacy' | 'advanced'>(
'mergeEditor.diffAlgorithm', 'advanced', this.configurationService)
.map(v => v === 'smart' ? 'legacy' : v === 'experimental' ? 'advanced' : v);

constructor(
@IEditorWorkerService private readonly editorWorkerService: IEditorWorkerService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class MergeModelInterface extends Disposable {

const diffComputer: IMergeDiffComputer = {
async computeDiff(textModel1: ITextModel, textModel2: ITextModel, reader: IReader): Promise<IMergeDiffComputerResult> {
const result = await linesDiffComputers.smart.computeDiff(
const result = await linesDiffComputers.legacy.computeDiff(
textModel1.getLinesContent(),
textModel2.getLinesContent(),
{ ignoreTrimWhitespace: false, maxComputationTimeMs: 10000 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ export const fixedDiffEditorOptions: IDiffEditorConstructionOptions = {
renderOverviewRuler: false,
wordWrap: 'off',
diffWordWrap: 'off',
diffAlgorithm: 'smart',
diffAlgorithm: 'advanced',
};
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/scm/browser/dirtydiffDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ class DirtyDiffWidget extends PeekViewWidget {
renderSideBySide: false,
readOnly: false,
renderIndicators: false,
diffAlgorithm: 'smart',
diffAlgorithm: 'advanced',
stickyScroll: { enabled: false }
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ const diffEditorOptions: IDiffEditorConstructionOptions = {
renderSideBySide: true,
originalAriaLabel: localize('testingOutputExpected', 'Expected result'),
modifiedAriaLabel: localize('testingOutputActual', 'Actual result'),
diffAlgorithm: 'smart',
diffAlgorithm: 'advanced',
};

const isDiffable = (message: ITestMessage): message is ITestErrorMessage & { actualOutput: string; expectedOutput: string } =>
Expand Down

0 comments on commit fc8f0a9

Please sign in to comment.