Skip to content

Commit f1c597b

Browse files
authored
Make ServicesAccessor typing more consistent in editor commands (microsoft#218369)
1 parent 6575255 commit f1c597b

File tree

20 files changed

+298
-271
lines changed

20 files changed

+298
-271
lines changed

src/vs/editor/browser/coreCommands.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { EnterOperation } from '../common/cursor/cursorTypeEditOperations.js';
3535
const CORE_WEIGHT = KeybindingWeight.EditorCore;
3636

3737
export abstract class CoreEditorCommand<T> extends EditorCommand {
38-
public runEditorCommand(accessor: ServicesAccessor | null, editor: ICodeEditor, args?: Partial<T> | null): void {
38+
public runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args?: Partial<T> | null): void {
3939
const viewModel = editor._getViewModel();
4040
if (!viewModel) {
4141
// the editor has no view => has no cursors
@@ -2095,7 +2095,7 @@ export namespace CoreEditingCommands {
20952095
public runDOMCommand(activeElement: Element): void {
20962096
activeElement.ownerDocument.execCommand('undo');
20972097
}
2098-
public runEditorCommand(accessor: ServicesAccessor | null, editor: ICodeEditor, args: unknown): void | Promise<void> {
2098+
public runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: unknown): void | Promise<void> {
20992099
if (!editor.hasModel() || editor.getOption(EditorOption.readOnly) === true) {
21002100
return;
21012101
}
@@ -2110,7 +2110,7 @@ export namespace CoreEditingCommands {
21102110
public runDOMCommand(activeElement: Element): void {
21112111
activeElement.ownerDocument.execCommand('redo');
21122112
}
2113-
public runEditorCommand(accessor: ServicesAccessor | null, editor: ICodeEditor, args: unknown): void | Promise<void> {
2113+
public runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: unknown): void | Promise<void> {
21142114
if (!editor.hasModel() || editor.getOption(EditorOption.readOnly) === true) {
21152115
return;
21162116
}

src/vs/editor/browser/editorExtensions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ export abstract class EditorCommand extends Command {
295295
accessor: ServicesAccessor,
296296
args: any,
297297
precondition: ContextKeyExpression | undefined,
298-
runner: (accessor: ServicesAccessor | null, editor: ICodeEditor, args: any) => void | Promise<void>
298+
runner: (accessor: ServicesAccessor, editor: ICodeEditor, args: any) => void | Promise<void>
299299
): void | Promise<void> {
300300
const codeEditorService = accessor.get(ICodeEditorService);
301301

@@ -321,7 +321,7 @@ export abstract class EditorCommand extends Command {
321321
return EditorCommand.runEditorCommand(accessor, args, this.precondition, (accessor, editor, args) => this.runEditorCommand(accessor, editor, args));
322322
}
323323

324-
public abstract runEditorCommand(accessor: ServicesAccessor | null, editor: ICodeEditor, args: any): void | Promise<void>;
324+
public abstract runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void | Promise<void>;
325325
}
326326

327327
//#endregion EditorCommand

src/vs/editor/contrib/cursorUndo/test/browser/cursorUndo.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ suite('FindController', () => {
2626
editor.trigger('test', Handler.Type, { text: 'hello' });
2727

2828
// press left
29-
CoreNavigationCommands.CursorLeft.runEditorCommand(null, editor, {});
29+
editor.runCommand(CoreNavigationCommands.CursorLeft, {});
3030

3131
// press Delete
32-
CoreEditingCommands.DeleteRight.runEditorCommand(null, editor, {});
32+
editor.runCommand(CoreEditingCommands.DeleteRight, {});
3333
assert.deepStrictEqual(editor.getValue(), 'hell');
3434
assert.deepStrictEqual(editor.getSelections(), [new Selection(1, 5, 1, 5)]);
3535

3636
// press left
37-
CoreNavigationCommands.CursorLeft.runEditorCommand(null, editor, {});
37+
editor.runCommand(CoreNavigationCommands.CursorLeft, {});
3838
assert.deepStrictEqual(editor.getSelections(), [new Selection(1, 4, 1, 4)]);
3939

4040
// press Ctrl+U

src/vs/editor/contrib/dropOrPasteInto/browser/copyPasteContribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ registerEditorCommand(new class extends EditorCommand {
3232
});
3333
}
3434

35-
public override runEditorCommand(_accessor: ServicesAccessor | null, editor: ICodeEditor) {
35+
public override runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) {
3636
return CopyPasteController.get(editor)?.changePasteType();
3737
}
3838
});
@@ -49,7 +49,7 @@ registerEditorCommand(new class extends EditorCommand {
4949
});
5050
}
5151

52-
public override runEditorCommand(_accessor: ServicesAccessor | null, editor: ICodeEditor) {
52+
public override runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) {
5353
CopyPasteController.get(editor)?.clearWidgets();
5454
}
5555
});

src/vs/editor/contrib/dropOrPasteInto/browser/dropIntoEditorContribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ registerEditorCommand(new class extends EditorCommand {
2626
});
2727
}
2828

29-
public override runEditorCommand(_accessor: ServicesAccessor | null, editor: ICodeEditor, _args: any) {
29+
public override runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor, _args: any) {
3030
DropIntoEditorController.get(editor)?.changeDropType();
3131
}
3232
});
@@ -43,7 +43,7 @@ registerEditorCommand(new class extends EditorCommand {
4343
});
4444
}
4545

46-
public override runEditorCommand(_accessor: ServicesAccessor | null, editor: ICodeEditor, _args: any) {
46+
public override runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor, _args: any) {
4747
DropIntoEditorController.get(editor)?.clearWidgets();
4848
}
4949
});

src/vs/editor/contrib/find/browser/findController.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ export class StartFindWithArgsAction extends EditorAction {
594594
});
595595
}
596596

597-
public async run(accessor: ServicesAccessor | null, editor: ICodeEditor, args?: IFindStartArguments): Promise<void> {
597+
public async run(accessor: ServicesAccessor, editor: ICodeEditor, args?: IFindStartArguments): Promise<void> {
598598
const controller = CommonFindController.get(editor);
599599
if (controller) {
600600
const newState: INewFindReplaceState = args ? {
@@ -645,7 +645,7 @@ export class StartFindWithSelectionAction extends EditorAction {
645645
});
646646
}
647647

648-
public async run(accessor: ServicesAccessor | null, editor: ICodeEditor): Promise<void> {
648+
public async run(accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
649649
const controller = CommonFindController.get(editor);
650650
if (controller) {
651651
await controller.start({
@@ -664,7 +664,7 @@ export class StartFindWithSelectionAction extends EditorAction {
664664
}
665665
}
666666
export abstract class MatchFindAction extends EditorAction {
667-
public async run(accessor: ServicesAccessor | null, editor: ICodeEditor): Promise<void> {
667+
public async run(accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
668668
const controller = CommonFindController.get(editor);
669669
if (controller && !this._run(controller)) {
670670
await controller.start({
@@ -860,7 +860,7 @@ export class MoveToMatchFindAction extends EditorAction {
860860
}
861861

862862
export abstract class SelectionMatchFindAction extends EditorAction {
863-
public async run(accessor: ServicesAccessor | null, editor: ICodeEditor): Promise<void> {
863+
public async run(accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
864864
const controller = CommonFindController.get(editor);
865865
if (!controller) {
866866
return;

src/vs/editor/contrib/find/test/browser/findController.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ suite('FindController', () => {
205205
assert.deepStrictEqual(fromSelection(editor.getSelection()!), [1, 4, 1, 4]);
206206

207207
// I hit F3 to "Find Next" to find the next occurrence of ABC, but instead it searches for XYZ.
208-
await nextMatchFindAction.run(null, editor);
208+
await editor.runAction(nextMatchFindAction);
209209

210210
assert.strictEqual(findState.searchString, 'ABC');
211211
assert.strictEqual(findController.hasFocus, false);
@@ -227,10 +227,10 @@ suite('FindController', () => {
227227
column: 9
228228
});
229229

230-
await nextMatchFindAction.run(null, editor);
230+
await editor.runAction(nextMatchFindAction);
231231
assert.deepStrictEqual(fromSelection(editor.getSelection()!), [1, 26, 1, 29]);
232232

233-
await nextMatchFindAction.run(null, editor);
233+
await editor.runAction(nextMatchFindAction);
234234
assert.deepStrictEqual(fromSelection(editor.getSelection()!), [1, 8, 1, 11]);
235235

236236
findController.dispose();
@@ -252,10 +252,10 @@ suite('FindController', () => {
252252
findController.toggleRegex();
253253
await executeAction(instantiationService, editor, StartFindAction);
254254

255-
await nextMatchFindAction.run(null, editor);
255+
await editor.runAction(nextMatchFindAction);
256256
assert.deepStrictEqual(fromSelection(editor.getSelection()!), [2, 9, 2, 13]);
257257

258-
await nextMatchFindAction.run(null, editor);
258+
await editor.runAction(nextMatchFindAction);
259259
assert.deepStrictEqual(fromSelection(editor.getSelection()!), [1, 9, 1, 13]);
260260

261261
findController.dispose();
@@ -282,7 +282,7 @@ suite('FindController', () => {
282282
updateSearchScope: false,
283283
loop: true
284284
});
285-
await nextMatchFindAction.run(null, editor);
285+
await editor.runAction(nextMatchFindAction);
286286
await executeAction(instantiationService, editor, StartFindReplaceAction);
287287

288288
assert.strictEqual(findController.getState().searchString, testRegexString);
@@ -390,7 +390,7 @@ suite('FindController', () => {
390390
editor.setSelection(new Selection(1, 1, 1, 9));
391391

392392
// cmd+f3
393-
await nextSelectionMatchFindAction.run(null, editor);
393+
await editor.runAction(nextSelectionMatchFindAction);
394394

395395
assert.deepStrictEqual(editor.getSelections()!.map(fromSelection), [
396396
[3, 1, 3, 9]
@@ -420,7 +420,7 @@ suite('FindController', () => {
420420
editor.setSelection(new Selection(1, 1, 1, 9));
421421

422422
// cmd+f3
423-
await nextSelectionMatchFindAction.run(null, editor);
423+
await editor.runAction(nextSelectionMatchFindAction);
424424

425425
assert.deepStrictEqual(editor.getSelections()!.map(fromSelection), [
426426
[3, 1, 3, 9]
@@ -449,13 +449,13 @@ suite('FindController', () => {
449449

450450
editor.setSelection(new Selection(1, 1, 2, 4));
451451
const startFindWithSelectionAction = new StartFindWithSelectionAction();
452-
await startFindWithSelectionAction.run(null, editor);
452+
await editor.runAction(startFindWithSelectionAction);
453453
const findState = findController.getState();
454454

455455
assert.deepStrictEqual(findState.searchString.split(/\r\n|\r|\n/g), ['ABC', 'ABC']);
456456

457457
editor.setSelection(new Selection(3, 1, 3, 1));
458-
await startFindWithSelectionAction.run(null, editor);
458+
await editor.runAction(startFindWithSelectionAction);
459459

460460
findController.dispose();
461461
});
@@ -474,7 +474,7 @@ suite('FindController', () => {
474474
editor.setSelection(new Selection(1, 2, 1, 2));
475475

476476
const startFindWithSelectionAction = new StartFindWithSelectionAction();
477-
startFindWithSelectionAction.run(null, editor);
477+
editor.runAction(startFindWithSelectionAction);
478478

479479
const findState = findController.getState();
480480
assert.deepStrictEqual(findState.searchString, 'ABC');

src/vs/editor/contrib/inlineCompletions/browser/controller/commands.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class ShowNextInlineSuggestionAction extends EditorAction {
3636
});
3737
}
3838

39-
public async run(accessor: ServicesAccessor | undefined, editor: ICodeEditor): Promise<void> {
39+
public async run(accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
4040
const controller = InlineCompletionsController.get(editor);
4141
controller?.model.get()?.next();
4242
}
@@ -56,7 +56,7 @@ export class ShowPreviousInlineSuggestionAction extends EditorAction {
5656
});
5757
}
5858

59-
public async run(accessor: ServicesAccessor | undefined, editor: ICodeEditor): Promise<void> {
59+
public async run(accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
6060
const controller = InlineCompletionsController.get(editor);
6161
controller?.model.get()?.previous();
6262
}
@@ -71,7 +71,7 @@ export class TriggerInlineSuggestionAction extends EditorAction {
7171
});
7272
}
7373

74-
public async run(accessor: ServicesAccessor | undefined, editor: ICodeEditor): Promise<void> {
74+
public async run(accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
7575
const controller = InlineCompletionsController.get(editor);
7676
await asyncTransaction(async tx => {
7777
/** @description triggerExplicitly from command */
@@ -90,8 +90,8 @@ export class ExplicitTriggerInlineEditAction extends EditorAction {
9090
});
9191
}
9292

93-
public async run(accessor: ServicesAccessor | undefined, editor: ICodeEditor): Promise<void> {
94-
const notificationService = accessor!.get(INotificationService);
93+
public async run(accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
94+
const notificationService = accessor.get(INotificationService);
9595
const controller = InlineCompletionsController.get(editor);
9696

9797
await controller?.model.get()?.triggerExplicitly(undefined, true);
@@ -112,7 +112,7 @@ export class TriggerInlineEditAction extends EditorCommand {
112112
});
113113
}
114114

115-
public override async runEditorCommand(accessor: ServicesAccessor | null, editor: ICodeEditor, args: { triggerKind?: 'automatic' | 'explicit' }): Promise<void> {
115+
public override async runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: { triggerKind?: 'automatic' | 'explicit' }): Promise<void> {
116116
const controller = InlineCompletionsController.get(editor);
117117
await controller?.model.get()?.trigger(undefined, { onlyFetchInlineEdits: true });
118118
}
@@ -138,7 +138,7 @@ export class AcceptNextWordOfInlineCompletion extends EditorAction {
138138
});
139139
}
140140

141-
public async run(accessor: ServicesAccessor | undefined, editor: ICodeEditor): Promise<void> {
141+
public async run(accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
142142
const controller = InlineCompletionsController.get(editor);
143143
await controller?.model.get()?.acceptNextWord();
144144
}
@@ -162,7 +162,7 @@ export class AcceptNextLineOfInlineCompletion extends EditorAction {
162162
});
163163
}
164164

165-
public async run(accessor: ServicesAccessor | undefined, editor: ICodeEditor): Promise<void> {
165+
public async run(accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
166166
const controller = InlineCompletionsController.get(editor);
167167
await controller?.model.get()?.acceptNextLine();
168168
}
@@ -255,7 +255,7 @@ export class JumpToNextInlineEdit extends EditorAction {
255255
});
256256
}
257257

258-
public async run(accessor: ServicesAccessor | undefined, editor: ICodeEditor): Promise<void> {
258+
public async run(accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
259259
const controller = InlineCompletionsController.get(editor);
260260
if (controller) {
261261
controller.jump();

src/vs/editor/contrib/inlineCompletions/test/browser/utils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,27 +189,27 @@ export class GhostTextContext extends Disposable {
189189
}
190190

191191
public cursorUp(): void {
192-
CoreNavigationCommands.CursorUp.runEditorCommand(null, this.editor, null);
192+
this.editor.runCommand(CoreNavigationCommands.CursorUp, null);
193193
}
194194

195195
public cursorRight(): void {
196-
CoreNavigationCommands.CursorRight.runEditorCommand(null, this.editor, null);
196+
this.editor.runCommand(CoreNavigationCommands.CursorRight, null);
197197
}
198198

199199
public cursorLeft(): void {
200-
CoreNavigationCommands.CursorLeft.runEditorCommand(null, this.editor, null);
200+
this.editor.runCommand(CoreNavigationCommands.CursorLeft, null);
201201
}
202202

203203
public cursorDown(): void {
204-
CoreNavigationCommands.CursorDown.runEditorCommand(null, this.editor, null);
204+
this.editor.runCommand(CoreNavigationCommands.CursorDown, null);
205205
}
206206

207207
public cursorLineEnd(): void {
208-
CoreNavigationCommands.CursorLineEnd.runEditorCommand(null, this.editor, null);
208+
this.editor.runCommand(CoreNavigationCommands.CursorLineEnd, null);
209209
}
210210

211211
public leftDelete(): void {
212-
CoreEditingCommands.DeleteLeft.runEditorCommand(null, this.editor, null);
212+
this.editor.runCommand(CoreEditingCommands.DeleteLeft, null);
213213
}
214214
}
215215

src/vs/editor/contrib/linesOperations/test/browser/linesOperations.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ suite('Editor Contrib - Line Operations', () => {
424424
assert.strictEqual(model.getLineContent(1), 'one');
425425
assert.deepStrictEqual(editor.getSelection(), new Selection(1, 1, 1, 1));
426426

427-
CoreEditingCommands.Undo.runEditorCommand(null, editor, null);
427+
editor.runCommand(CoreEditingCommands.Undo, null);
428428
assert.strictEqual(model.getLineContent(1), 'Typing some text here on line one');
429429
assert.deepStrictEqual(editor.getSelection(), new Selection(1, 31, 1, 31));
430430
});
@@ -554,7 +554,7 @@ suite('Editor Contrib - Line Operations', () => {
554554
assert.strictEqual(model.getLineContent(1), 'hello my dear world');
555555
assert.deepStrictEqual(editor.getSelection(), new Selection(1, 14, 1, 14));
556556

557-
CoreEditingCommands.Undo.runEditorCommand(null, editor, null);
557+
editor.runCommand(CoreEditingCommands.Undo, null);
558558
assert.strictEqual(model.getLineContent(1), 'hello my dear');
559559
assert.deepStrictEqual(editor.getSelection(), new Selection(1, 14, 1, 14));
560560
});
@@ -1420,13 +1420,13 @@ suite('Editor Contrib - Line Operations', () => {
14201420
new Selection(2, 4, 2, 4)
14211421
]);
14221422

1423-
CoreEditingCommands.Undo.runEditorCommand(null, editor, null);
1423+
editor.runCommand(CoreEditingCommands.Undo, null);
14241424
assert.deepStrictEqual(editor.getSelections(), [
14251425
new Selection(1, 3, 1, 3),
14261426
new Selection(1, 6, 1, 6),
14271427
new Selection(3, 4, 3, 4)
14281428
]);
1429-
CoreEditingCommands.Redo.runEditorCommand(null, editor, null);
1429+
editor.runCommand(CoreEditingCommands.Redo, null);
14301430
assert.deepStrictEqual(editor.getSelections(), [
14311431
new Selection(1, 3, 1, 3),
14321432
new Selection(2, 4, 2, 4)
@@ -1537,7 +1537,7 @@ suite('Editor Contrib - Line Operations', () => {
15371537
assert.strictEqual(model.getLineContent(1), '\tfunction baz() {');
15381538
assert.deepStrictEqual(editor.getSelection(), new Selection(1, 3, 1, 3));
15391539

1540-
CoreEditingCommands.Tab.runEditorCommand(null, editor, null);
1540+
editor.runCommand(CoreEditingCommands.Tab, null);
15411541
assert.strictEqual(model.getLineContent(1), '\tf\tunction baz() {');
15421542
});
15431543

0 commit comments

Comments
 (0)