Skip to content

Commit 9ada582

Browse files
authored
Merge pull request microsoft#97644 from ludokx/diff-editor-codelens
Add microsoft#97640: Added options to enable codelens for diff editors
2 parents d1d6eae + 684f7d4 commit 9ada582

5 files changed

Lines changed: 65 additions & 7 deletions

File tree

src/vs/editor/browser/widget/diffEditorWidget.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
206206

207207
private _ignoreTrimWhitespace: boolean;
208208
private _originalIsEditable: boolean;
209+
private _originalCodeLens: boolean;
210+
private _modifiedCodeLens: boolean;
209211

210212
private _renderSideBySide: boolean;
211213
private _maxComputationTime: number;
@@ -281,6 +283,16 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
281283
this._originalIsEditable = Boolean(options.originalEditable);
282284
}
283285

286+
this._originalCodeLens = false;
287+
if (typeof options.originalCodeLens !== 'undefined') {
288+
this._originalCodeLens = Boolean(options.originalCodeLens);
289+
}
290+
291+
this._modifiedCodeLens = false;
292+
if (typeof options.modifiedCodeLens !== 'undefined') {
293+
this._modifiedCodeLens = Boolean(options.modifiedCodeLens);
294+
}
295+
284296
this._updateDecorationsRunner = this._register(new RunOnceScheduler(() => this._updateDecorations(), 0));
285297

286298
this._containerDomElement = document.createElement('div');
@@ -469,7 +481,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
469481
}
470482

471483
private _createLeftHandSideEditor(options: IDiffEditorOptions, instantiationService: IInstantiationService): CodeEditorWidget {
472-
const editor = this._createInnerEditor(instantiationService, this._originalDomNode, this._adjustOptionsForLeftHandSide(options, this._originalIsEditable));
484+
const editor = this._createInnerEditor(instantiationService, this._originalDomNode, this._adjustOptionsForLeftHandSide(options, this._originalIsEditable, this._originalCodeLens));
473485

474486
this._register(editor.onDidScrollChange((e) => {
475487
if (this._isHandlingScrollEvent) {
@@ -502,7 +514,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
502514
}
503515

504516
private _createRightHandSideEditor(options: IDiffEditorOptions, instantiationService: IInstantiationService): CodeEditorWidget {
505-
const editor = this._createInnerEditor(instantiationService, this._modifiedDomNode, this._adjustOptionsForRightHandSide(options));
517+
const editor = this._createInnerEditor(instantiationService, this._modifiedDomNode, this._adjustOptionsForRightHandSide(options, this._modifiedCodeLens));
506518

507519
this._register(editor.onDidScrollChange((e) => {
508520
if (this._isHandlingScrollEvent) {
@@ -662,9 +674,15 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
662674
if (typeof newOptions.originalEditable !== 'undefined') {
663675
this._originalIsEditable = Boolean(newOptions.originalEditable);
664676
}
677+
if (typeof newOptions.originalCodeLens !== 'undefined') {
678+
this._originalCodeLens = Boolean(newOptions.originalCodeLens);
679+
}
680+
if (typeof newOptions.modifiedCodeLens !== 'undefined') {
681+
this._modifiedCodeLens = Boolean(newOptions.modifiedCodeLens);
682+
}
665683

666-
this.modifiedEditor.updateOptions(this._adjustOptionsForRightHandSide(newOptions));
667-
this.originalEditor.updateOptions(this._adjustOptionsForLeftHandSide(newOptions, this._originalIsEditable));
684+
this.modifiedEditor.updateOptions(this._adjustOptionsForRightHandSide(newOptions, this._modifiedCodeLens));
685+
this.originalEditor.updateOptions(this._adjustOptionsForLeftHandSide(newOptions, this._originalIsEditable, this._originalCodeLens));
668686

669687
// enableSplitViewResizing
670688
if (typeof newOptions.enableSplitViewResizing !== 'undefined') {
@@ -1059,15 +1077,21 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
10591077
return clonedOptions;
10601078
}
10611079

1062-
private _adjustOptionsForLeftHandSide(options: IDiffEditorOptions, isEditable: boolean): IEditorOptions {
1080+
private _adjustOptionsForLeftHandSide(options: IDiffEditorOptions, isEditable: boolean, isCodeLensEnabled: boolean): IEditorOptions {
10631081
let result = this._adjustOptionsForSubEditor(options);
1082+
if (isCodeLensEnabled) {
1083+
result.codeLens = true;
1084+
}
10641085
result.readOnly = !isEditable;
10651086
result.extraEditorClassName = 'original-in-monaco-diff-editor';
10661087
return result;
10671088
}
10681089

1069-
private _adjustOptionsForRightHandSide(options: IDiffEditorOptions): IEditorOptions {
1090+
private _adjustOptionsForRightHandSide(options: IDiffEditorOptions, isCodeLensEnabled: boolean): IEditorOptions {
10701091
let result = this._adjustOptionsForSubEditor(options);
1092+
if (isCodeLensEnabled) {
1093+
result.codeLens = true;
1094+
}
10711095
result.revealHorizontalRightPadding = EditorOptions.revealHorizontalRightPadding.defaultValue + DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH;
10721096
result.scrollbar!.verticalHasArrows = false;
10731097
result.extraEditorClassName = 'modified-in-monaco-diff-editor';

src/vs/editor/common/config/commonEditorConfig.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,11 @@ const editorConfiguration: IConfigurationNode = {
541541
type: 'boolean',
542542
default: true,
543543
description: nls.localize('renderIndicators', "Controls whether the diff editor shows +/- indicators for added/removed changes.")
544+
},
545+
'diffEditor.codeLens': {
546+
type: 'boolean',
547+
default: false,
548+
description: nls.localize('codeLens', "Controls whether the editor shows CodeLens.")
544549
}
545550
}
546551
};

src/vs/editor/common/config/editorOptions.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,16 @@ export interface IDiffEditorOptions extends IEditorOptions {
647647
* Defaults to false.
648648
*/
649649
originalEditable?: boolean;
650+
/**
651+
* Original editor should be have code lens enabled?
652+
* Defaults to false.
653+
*/
654+
originalCodeLens?: boolean;
655+
/**
656+
* Modified editor should be have code lens enabled?
657+
* Defaults to false.
658+
*/
659+
modifiedCodeLens?: boolean;
650660
}
651661

652662
//#endregion

src/vs/monaco.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3179,6 +3179,16 @@ declare namespace monaco.editor {
31793179
* Defaults to false.
31803180
*/
31813181
originalEditable?: boolean;
3182+
/**
3183+
* Original editor should be have code lens enabled?
3184+
* Defaults to false.
3185+
*/
3186+
originalCodeLens?: boolean;
3187+
/**
3188+
* Modified editor should be have code lens enabled?
3189+
* Defaults to false.
3190+
*/
3191+
modifiedCodeLens?: boolean;
31823192
}
31833193

31843194
/**

src/vs/workbench/browser/parts/editor/textDiffEditor.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,16 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditorPan
202202

203203
// Handle diff editor specially by merging in diffEditor configuration
204204
if (isObject(configuration.diffEditor)) {
205-
objects.mixin(editorConfiguration, configuration.diffEditor);
205+
// User settings defines `diffEditor.codeLens`, but there is also `editor.codeLens`.
206+
// Due to the mixin, the two settings cannot be distinguished anymore.
207+
//
208+
// So we map `diffEditor.codeLens` to `diffEditor.originalCodeLens` and `diffEditor.modifiedCodeLens`.
209+
const diffEditorConfiguration = <IDiffEditorOptions>objects.deepClone(configuration.diffEditor);
210+
diffEditorConfiguration.originalCodeLens = diffEditorConfiguration.codeLens;
211+
diffEditorConfiguration.modifiedCodeLens = diffEditorConfiguration.codeLens;
212+
delete diffEditorConfiguration.codeLens;
213+
214+
objects.mixin(editorConfiguration, diffEditorConfiguration);
206215
}
207216

208217
return editorConfiguration;

0 commit comments

Comments
 (0)