Skip to content

Commit aad632b

Browse files
committed
Command wrapping is done in the adaptor
1 parent 4a676a4 commit aad632b

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

src/lib/adaptors/command.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as vscode from 'vscode';
22
import CommandWrapper from '../command-wrapper';
3+
import {Command} from '../commands/command';
4+
import {Logger} from '../types/logger';
35

46
type UriParser = (uri: string) => vscode.Uri;
57

@@ -8,16 +10,18 @@ export type CommandType = 'TEXT_EDITOR' | 'GENERAL';
810
export interface CommandItem {
911
name: string;
1012
type: CommandType;
11-
command: CommandWrapper;
13+
command: Command;
1214
}
1315

1416
export default class CommandAdaptor {
1517
private readonly commands: typeof vscode.commands;
1618
private readonly parseUri: UriParser;
19+
private readonly logger: Logger;
1720

18-
constructor(commands: typeof vscode.commands, parseUri: UriParser) {
21+
constructor(commands: typeof vscode.commands, parseUri: UriParser, logger: Logger) {
1922
this.commands = commands;
2023
this.parseUri = parseUri;
24+
this.logger = logger;
2125
}
2226

2327
async executeCommand(name: string, uri1: string, uri2: string, title: string): Promise<{}> {
@@ -26,7 +30,8 @@ export default class CommandAdaptor {
2630

2731
registerCommand(cmd: CommandItem): vscode.Disposable {
2832
const registerer = this.getCommandRegisterer(cmd.type);
29-
return registerer(cmd.name, cmd.command.execute, cmd.command);
33+
const command = new CommandWrapper(cmd.command, this.logger);
34+
return registerer(cmd.name, command.execute, command);
3035
}
3136

3237
private getCommandRegisterer(commandType: CommandType) {

src/lib/bootstrapper-factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default class BootstrapperFactory {
1515
const logger = console;
1616
const selectionInfoRegistry = new SelectionInfoRegistry();
1717
const workspaceAdaptor = new WorkspaceAdaptor(vscode.workspace);
18-
const commandAdaptor = new CommandAdaptor(vscode.commands, vscode.Uri.parse);
18+
const commandAdaptor = new CommandAdaptor(vscode.commands, vscode.Uri.parse, logger);
1919
const normalisationRuleStore = new NormalisationRuleStore(workspaceAdaptor);
2020
const commandFactory = new CommandFactory(
2121
selectionInfoRegistry,
@@ -26,6 +26,6 @@ export default class BootstrapperFactory {
2626
() => new Date()
2727
);
2828
const contentProvider = new ContentProvider(selectionInfoRegistry, normalisationRuleStore);
29-
return new Bootstrapper(commandFactory, contentProvider, workspaceAdaptor, commandAdaptor, logger);
29+
return new Bootstrapper(commandFactory, contentProvider, workspaceAdaptor, commandAdaptor);
3030
}
3131
}

src/lib/bootstrapper.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import CommandFactory from './command-factory';
22
import ContentProvider from './content-provider';
33
import {EXTENSION_NAMESPACE, EXTENSION_SCHEME} from './const';
44
import {ExecutionContextLike} from './types/vscode';
5-
import CommandWrapper from './command-wrapper';
6-
import {Logger} from './types/logger';
7-
import {Command} from './commands/command';
85
import WorkspaceAdaptor from './adaptors/workspace';
96
import CommandAdaptor, {CommandItem} from './adaptors/command';
107

@@ -13,18 +10,15 @@ export default class Bootstrapper {
1310
private readonly contentProvider: ContentProvider;
1411
private readonly workspaceAdaptor: WorkspaceAdaptor;
1512
private readonly commandAdaptor: CommandAdaptor;
16-
private readonly logger: Logger;
1713

1814
constructor(commandFactory: CommandFactory,
1915
contentProvider: ContentProvider,
2016
workspaceAdaptor: WorkspaceAdaptor,
21-
commandAdaptor: CommandAdaptor,
22-
logger: Logger) {
17+
commandAdaptor: CommandAdaptor) {
2318
this.commandFactory = commandFactory;
2419
this.contentProvider = contentProvider;
2520
this.workspaceAdaptor = workspaceAdaptor;
2621
this.commandAdaptor = commandAdaptor;
27-
this.logger = logger;
2822
}
2923

3024
initiate(context: ExecutionContextLike) {
@@ -52,32 +46,28 @@ export default class Bootstrapper {
5246
{
5347
name: `${EXTENSION_NAMESPACE}.diffVisibleEditors`,
5448
type: 'GENERAL',
55-
command: this.wrapCommand(this.commandFactory.createCompareVisibleEditorsCommand())
49+
command: this.commandFactory.createCompareVisibleEditorsCommand()
5650
},
5751
{
5852
name: `${EXTENSION_NAMESPACE}.markSection1`,
5953
type: 'TEXT_EDITOR',
60-
command: this.wrapCommand(this.commandFactory.crateSaveText1Command())
54+
command: this.commandFactory.crateSaveText1Command()
6155
},
6256
{
6357
name: `${EXTENSION_NAMESPACE}.markSection2AndTakeDiff`,
6458
type: 'TEXT_EDITOR',
65-
command: this.wrapCommand(this.commandFactory.createCompareSelectionWithText1Command())
59+
command: this.commandFactory.createCompareSelectionWithText1Command()
6660
},
6761
{
6862
name: `${EXTENSION_NAMESPACE}.diffSelectionWithClipboard`,
6963
type: 'TEXT_EDITOR',
70-
command: this.wrapCommand(this.commandFactory.createCompareSelectionWithClipboardCommand())
64+
command: this.commandFactory.createCompareSelectionWithClipboardCommand()
7165
},
7266
{
7367
name: `${EXTENSION_NAMESPACE}.togglePreComparisonTextNormalizationRules`,
7468
type: 'GENERAL',
75-
command: this.wrapCommand(this.commandFactory.createToggleNormalisationRulesCommand())
69+
command: this.commandFactory.createToggleNormalisationRulesCommand()
7670
}
7771
];
7872
}
79-
80-
private wrapCommand(command: Command) {
81-
return new CommandWrapper(command, this.logger);
82-
}
8373
}

0 commit comments

Comments
 (0)