Skip to content

Commit 3b16cc4

Browse files
committed
Register editor contributions with their ID (microsoft#82603)
1 parent 99ba33d commit 3b16cc4

64 files changed

Lines changed: 198 additions & 393 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/vs/editor/browser/editorExtensions.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@ import { withNullAsUndefined } from 'vs/base/common/types';
2525
export type ServicesAccessor = InstantiationServicesAccessor;
2626
export type IEditorContributionCtor = IConstructorSignature1<ICodeEditor, IEditorContribution>;
2727
export type IDiffEditorContributionCtor = IConstructorSignature1<IDiffEditor, IDiffEditorContribution>;
28-
export type EditorTelemetryDataFragment = {
29-
target: { classification: 'SystemMetaData', purpose: 'FeatureInsight', };
30-
snippet: { classification: 'SystemMetaData', purpose: 'FeatureInsight', isMeasurement: true, };
31-
};
28+
29+
export interface IEditorContributionDescription {
30+
id: string;
31+
ctor: IEditorContributionCtor;
32+
}
33+
34+
export interface IDiffEditorContributionDescription {
35+
id: string;
36+
ctor: IDiffEditorContributionCtor;
37+
}
3238

3339
//#region Command
3440

@@ -297,12 +303,12 @@ export function registerInstantiatedEditorAction(editorAction: EditorAction): vo
297303
EditorContributionRegistry.INSTANCE.registerEditorAction(editorAction);
298304
}
299305

300-
export function registerEditorContribution(ctor: IEditorContributionCtor): void {
301-
EditorContributionRegistry.INSTANCE.registerEditorContribution(ctor);
306+
export function registerEditorContribution(id: string, ctor: IEditorContributionCtor): void {
307+
EditorContributionRegistry.INSTANCE.registerEditorContribution(id, ctor);
302308
}
303309

304-
export function registerDiffEditorContribution(ctor: IDiffEditorContributionCtor): void {
305-
EditorContributionRegistry.INSTANCE.registerDiffEditorContribution(ctor);
310+
export function registerDiffEditorContribution(id: string, ctor: IDiffEditorContributionCtor): void {
311+
EditorContributionRegistry.INSTANCE.registerDiffEditorContribution(id, ctor);
306312
}
307313

308314
export namespace EditorExtensionsRegistry {
@@ -315,11 +321,11 @@ export namespace EditorExtensionsRegistry {
315321
return EditorContributionRegistry.INSTANCE.getEditorActions();
316322
}
317323

318-
export function getEditorContributions(): IEditorContributionCtor[] {
324+
export function getEditorContributions(): IEditorContributionDescription[] {
319325
return EditorContributionRegistry.INSTANCE.getEditorContributions();
320326
}
321327

322-
export function getDiffEditorContributions(): IDiffEditorContributionCtor[] {
328+
export function getDiffEditorContributions(): IDiffEditorContributionDescription[] {
323329
return EditorContributionRegistry.INSTANCE.getDiffEditorContributions();
324330
}
325331
}
@@ -333,8 +339,8 @@ class EditorContributionRegistry {
333339

334340
public static readonly INSTANCE = new EditorContributionRegistry();
335341

336-
private readonly editorContributions: IEditorContributionCtor[];
337-
private readonly diffEditorContributions: IDiffEditorContributionCtor[];
342+
private readonly editorContributions: IEditorContributionDescription[];
343+
private readonly diffEditorContributions: IDiffEditorContributionDescription[];
338344
private readonly editorActions: EditorAction[];
339345
private readonly editorCommands: { [commandId: string]: EditorCommand; };
340346

@@ -345,19 +351,19 @@ class EditorContributionRegistry {
345351
this.editorCommands = Object.create(null);
346352
}
347353

348-
public registerEditorContribution(ctor: IEditorContributionCtor): void {
349-
this.editorContributions.push(ctor);
354+
public registerEditorContribution(id: string, ctor: IEditorContributionCtor): void {
355+
this.editorContributions.push({ id, ctor });
350356
}
351357

352-
public getEditorContributions(): IEditorContributionCtor[] {
358+
public getEditorContributions(): IEditorContributionDescription[] {
353359
return this.editorContributions.slice(0);
354360
}
355361

356-
public registerDiffEditorContribution(ctor: IDiffEditorContributionCtor): void {
357-
this.diffEditorContributions.push(ctor);
362+
public registerDiffEditorContribution(id: string, ctor: IDiffEditorContributionCtor): void {
363+
this.diffEditorContributions.push({ id, ctor });
358364
}
359365

360-
public getDiffEditorContributions(): IDiffEditorContributionCtor[] {
366+
public getDiffEditorContributions(): IDiffEditorContributionDescription[] {
361367
return this.diffEditorContributions.slice(0);
362368
}
363369

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { Schemas } from 'vs/base/common/network';
1818
import { Configuration } from 'vs/editor/browser/config/configuration';
1919
import { CoreEditorCommand } from 'vs/editor/browser/controller/coreCommands';
2020
import * as editorBrowser from 'vs/editor/browser/editorBrowser';
21-
import { EditorExtensionsRegistry, IEditorContributionCtor } from 'vs/editor/browser/editorExtensions';
21+
import { EditorExtensionsRegistry, IEditorContributionDescription } from 'vs/editor/browser/editorExtensions';
2222
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
2323
import { ICommandDelegate } from 'vs/editor/browser/view/viewController';
2424
import { IContentWidgetData, IOverlayWidgetData, View } from 'vs/editor/browser/view/viewImpl';
@@ -67,7 +67,7 @@ export interface ICodeEditorWidgetOptions {
6767
* Contributions to instantiate.
6868
* Defaults to EditorExtensionsRegistry.getEditorContributions().
6969
*/
70-
contributions?: IEditorContributionCtor[];
70+
contributions?: IEditorContributionDescription[];
7171

7272
/**
7373
* Telemetry data associated with this CodeEditorWidget.
@@ -294,17 +294,16 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
294294
this._contentWidgets = {};
295295
this._overlayWidgets = {};
296296

297-
let contributions: IEditorContributionCtor[];
297+
let contributions: IEditorContributionDescription[];
298298
if (Array.isArray(codeEditorWidgetOptions.contributions)) {
299299
contributions = codeEditorWidgetOptions.contributions;
300300
} else {
301301
contributions = EditorExtensionsRegistry.getEditorContributions();
302302
}
303-
for (let i = 0, len = contributions.length; i < len; i++) {
304-
const ctor = contributions[i];
303+
for (const desc of contributions) {
305304
try {
306-
const contribution = this._instantiationService.createInstance(ctor, this);
307-
this._contributions[contribution.getId()] = contribution;
305+
const contribution = this._instantiationService.createInstance(desc.ctor, this);
306+
this._contributions[desc.id] = contribution;
308307
} catch (err) {
309308
onUnexpectedError(err);
310309
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView
4444
import { IDiffLinesChange, InlineDiffMargin } from 'vs/editor/browser/widget/inlineDiffMargin';
4545
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
4646
import { Constants } from 'vs/base/common/uint';
47-
import { IDiffEditorContributionCtor, EditorExtensionsRegistry } from 'vs/editor/browser/editorExtensions';
47+
import { EditorExtensionsRegistry, IDiffEditorContributionDescription } from 'vs/editor/browser/editorExtensions';
4848
import { onUnexpectedError } from 'vs/base/common/errors';
4949
import { IEditorProgressService, IProgressRunner } from 'vs/platform/progress/common/progress';
5050

@@ -380,10 +380,10 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
380380
this._containerDomElement.className = DiffEditorWidget._getClassName(this._themeService.getTheme(), this._renderSideBySide);
381381
}));
382382

383-
const contributions: IDiffEditorContributionCtor[] = EditorExtensionsRegistry.getDiffEditorContributions();
384-
for (const ctor of contributions) {
383+
const contributions: IDiffEditorContributionDescription[] = EditorExtensionsRegistry.getDiffEditorContributions();
384+
for (const desc of contributions) {
385385
try {
386-
this._register(instantiationService.createInstance(ctor, this));
386+
this._register(instantiationService.createInstance(desc.ctor, this));
387387
} catch (err) {
388388
onUnexpectedError(err);
389389
}

src/vs/editor/common/editorCommon.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,6 @@ export interface IDiffEditor extends IEditor {
488488
* An editor contribution that gets created every time a new editor gets created and gets disposed when the editor gets disposed.
489489
*/
490490
export interface IEditorContribution {
491-
/**
492-
* Get a unique identifier for this contribution.
493-
*/
494-
getId(): string;
495491
/**
496492
* Dispose this contribution.
497493
*/
@@ -511,10 +507,6 @@ export interface IEditorContribution {
511507
* @internal
512508
*/
513509
export interface IDiffEditorContribution {
514-
/**
515-
* Get a unique identifier for this contribution.
516-
*/
517-
getId(): string;
518510
/**
519511
* Dispose this contribution.
520512
*/

src/vs/editor/contrib/bracketMatching/bracketMatching.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class BracketsData {
8282
}
8383

8484
export class BracketMatchingController extends Disposable implements editorCommon.IEditorContribution {
85-
private static readonly ID = 'editor.contrib.bracketMatchingController';
85+
public static readonly ID = 'editor.contrib.bracketMatchingController';
8686

8787
public static get(editor: ICodeEditor): BracketMatchingController {
8888
return editor.getContribution<BracketMatchingController>(BracketMatchingController.ID);
@@ -140,10 +140,6 @@ export class BracketMatchingController extends Disposable implements editorCommo
140140
}));
141141
}
142142

143-
public getId(): string {
144-
return BracketMatchingController.ID;
145-
}
146-
147143
public jumpToBracket(): void {
148144
if (!this._editor.hasModel()) {
149145
return;
@@ -311,7 +307,7 @@ export class BracketMatchingController extends Disposable implements editorCommo
311307
}
312308
}
313309

314-
registerEditorContribution(BracketMatchingController);
310+
registerEditorContribution(BracketMatchingController.ID, BracketMatchingController);
315311
registerEditorAction(SelectToBracketAction);
316312
registerEditorAction(JumpToBracketAction);
317313
registerThemingParticipant((theme, collector) => {

src/vs/editor/contrib/bracketMatching/test/bracketMatching.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ suite('bracket matching', () => {
3434
let model = TextModel.createFromString('var x = (3 + (5-7)) + ((5+3)+5);', undefined, mode.getLanguageIdentifier());
3535

3636
withTestCodeEditor(null, { model: model }, (editor, cursor) => {
37-
let bracketMatchingController = editor.registerAndInstantiateContribution<BracketMatchingController>(BracketMatchingController);
37+
let bracketMatchingController = editor.registerAndInstantiateContribution<BracketMatchingController>(BracketMatchingController.ID, BracketMatchingController);
3838

3939
// start on closing bracket
4040
editor.setPosition(new Position(1, 20));
@@ -66,7 +66,7 @@ suite('bracket matching', () => {
6666
let model = TextModel.createFromString('var x = (3 + (5-7)); y();', undefined, mode.getLanguageIdentifier());
6767

6868
withTestCodeEditor(null, { model: model }, (editor, cursor) => {
69-
let bracketMatchingController = editor.registerAndInstantiateContribution<BracketMatchingController>(BracketMatchingController);
69+
let bracketMatchingController = editor.registerAndInstantiateContribution<BracketMatchingController>(BracketMatchingController.ID, BracketMatchingController);
7070

7171
// start position between brackets
7272
editor.setPosition(new Position(1, 16));
@@ -103,7 +103,7 @@ suite('bracket matching', () => {
103103
let model = TextModel.createFromString('var x = (3 + (5-7)); y();', undefined, mode.getLanguageIdentifier());
104104

105105
withTestCodeEditor(null, { model: model }, (editor, cursor) => {
106-
let bracketMatchingController = editor.registerAndInstantiateContribution<BracketMatchingController>(BracketMatchingController);
106+
let bracketMatchingController = editor.registerAndInstantiateContribution<BracketMatchingController>(BracketMatchingController.ID, BracketMatchingController);
107107

108108

109109
// start position in open brackets
@@ -148,7 +148,7 @@ suite('bracket matching', () => {
148148
let model = TextModel.createFromString('{ } { } { }', undefined, mode.getLanguageIdentifier());
149149

150150
withTestCodeEditor(null, { model: model }, (editor, cursor) => {
151-
let bracketMatchingController = editor.registerAndInstantiateContribution<BracketMatchingController>(BracketMatchingController);
151+
let bracketMatchingController = editor.registerAndInstantiateContribution<BracketMatchingController>(BracketMatchingController.ID, BracketMatchingController);
152152

153153
// cursors inside brackets become selections of the entire bracket contents
154154
editor.setSelections([

src/vs/editor/contrib/codeAction/codeActionCommands.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function contextKeyForSupportedActions(kind: CodeActionKind) {
4040

4141
export class QuickFixController extends Disposable implements IEditorContribution {
4242

43-
private static readonly ID = 'editor.contrib.quickFixController';
43+
public static readonly ID = 'editor.contrib.quickFixController';
4444

4545
public static get(editor: ICodeEditor): QuickFixController {
4646
return editor.getContribution<QuickFixController>(QuickFixController.ID);
@@ -90,10 +90,6 @@ export class QuickFixController extends Disposable implements IEditorContributio
9090
return this._ui.getValue().showCodeActionList(actions, at);
9191
}
9292

93-
public getId(): string {
94-
return QuickFixController.ID;
95-
}
96-
9793
public manualTriggerAtCurrentPosition(
9894
notAvailableMessage: string,
9995
filter?: CodeActionFilter,

src/vs/editor/contrib/codeAction/codeActionContributions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { registerEditorAction, registerEditorCommand, registerEditorContribution
77
import { CodeActionCommand, OrganizeImportsAction, QuickFixAction, QuickFixController, RefactorAction, SourceAction, AutoFixAction, FixAllAction } from 'vs/editor/contrib/codeAction/codeActionCommands';
88

99

10-
registerEditorContribution(QuickFixController);
10+
registerEditorContribution(QuickFixController.ID, QuickFixController);
1111
registerEditorAction(QuickFixAction);
1212
registerEditorAction(RefactorAction);
1313
registerEditorAction(SourceAction);

src/vs/editor/contrib/codelens/codelensController.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { EditorOption } from 'vs/editor/common/config/editorOptions';
2121

2222
export class CodeLensContribution implements editorCommon.IEditorContribution {
2323

24-
private static readonly ID: string = 'css.editor.codeLens';
24+
public static readonly ID: string = 'css.editor.codeLens';
2525

2626
private _isEnabled: boolean;
2727

@@ -78,10 +78,6 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
7878
dispose(this._currentCodeLensModel);
7979
}
8080

81-
getId(): string {
82-
return CodeLensContribution.ID;
83-
}
84-
8581
private _onModelChange(): void {
8682

8783
this._localDispose();
@@ -366,4 +362,4 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
366362
}
367363
}
368364

369-
registerEditorContribution(CodeLensContribution);
365+
registerEditorContribution(CodeLensContribution.ID, CodeLensContribution);

src/vs/editor/contrib/colorPicker/colorDetector.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const MAX_DECORATORS = 500;
2525

2626
export class ColorDetector extends Disposable implements IEditorContribution {
2727

28-
private static readonly ID: string = 'editor.contrib.colorDetector';
28+
public static readonly ID: string = 'editor.contrib.colorDetector';
2929

3030
static readonly RECOMPUTE_TIME = 1000; // ms
3131

@@ -88,10 +88,6 @@ export class ColorDetector extends Disposable implements IEditorContribution {
8888
return this._editor.getOption(EditorOption.colorDecorators);
8989
}
9090

91-
getId(): string {
92-
return ColorDetector.ID;
93-
}
94-
9591
static get(editor: ICodeEditor): ColorDetector {
9692
return editor.getContribution<ColorDetector>(this.ID);
9793
}
@@ -247,4 +243,4 @@ export class ColorDetector extends Disposable implements IEditorContribution {
247243
}
248244
}
249245

250-
registerEditorContribution(ColorDetector);
246+
registerEditorContribution(ColorDetector.ID, ColorDetector);

0 commit comments

Comments
 (0)