Skip to content

Commit

Permalink
Make HistoricalCommandReader the only reader
Browse files Browse the repository at this point in the history
  • Loading branch information
ryu1kn committed Dec 4, 2016
1 parent e20a885 commit 9619a24
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 89 deletions.
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ Levarage your favourite shell commands to edit text.

* `EditWithShell: Run command` (**Command ID:** `editWithShell.runCommand`)

Open an input box to enter shell command

* `EditWithShell: Reuse command` (**Command ID:** `editWithShell.reuseCommand`)

Show command history and let you modify before you execute them
Show command history and let you select, modify & run a command

## Keyboard Shortcuts

Expand All @@ -31,8 +27,6 @@ You can quickly open a command input box by registering the extension command to
```json
{ "key": "ctrl+r ctrl+r", "command": "editWithShell.runCommand",
"when": "editorTextFocus" }
{ "key": "ctrl+r ctrl+u", "command": "editWithShell.reuseCommand",
"when": "editorTextFocus" }
```

## Request Features or Report Bugs
Expand Down
18 changes: 3 additions & 15 deletions lib/app-integrator-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ const vscode = require('vscode');

const AppIntegrator = require('./app-integrator');
const ShellCommandService = require('./shell-command-service');
const SimpleCommandReader = require('./command-readers/simple');
const HistoricalCommandReader = require('./command-readers/historical');
const CommandReader = require('./command-reader');
const HistoryStore = require('./history-store');
const ProcessRunner = require('./process-runner');
const RunCommand = require('./run-command');
Expand All @@ -19,8 +18,7 @@ class AppIntegratorFactory {
create() {
return new AppIntegrator({
vscode,
runCommand: this._runCommand,
reuseCommand: this._reuseCommand
runCommand: this._runCommand
});
}

Expand All @@ -31,17 +29,7 @@ class AppIntegratorFactory {
get _runCommand() {
return new RunCommand({
logger: this._logger,
commandReader: new SimpleCommandReader({vsWindow: vscode.window}),
historyStore: this._historyStore,
shellCommandService: this._shellCommandService,
showErrorMessage: message => vscode.window.showErrorMessage(message)
});
}

get _reuseCommand() {
return new RunCommand({
logger: this._logger,
commandReader: new HistoricalCommandReader({
commandReader: new CommandReader({
vsWindow: vscode.window,
historyStore: this._historyStore
}),
Expand Down
28 changes: 6 additions & 22 deletions lib/app-integrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,19 @@ class AppIntegrator {
constructor(params) {
this._vscode = params.vscode;
this._runCommand = params.runCommand;
this._reuseCommand = params.reuseCommand;
}

integrate(context) {
this._registerTextEditorCommands(context);
}

_registerTextEditorCommands(context) {
this._commandList.forEach(commandDef => {
const disposable = this._vscode.commands.registerTextEditorCommand(
`${Const.EXTENSION_NAME}.${commandDef.name}`,
commandDef.command.execute,
commandDef.command
);
context.subscriptions.push(disposable);
});
}

get _commandList() {
return [
{
name: 'runCommand',
command: this._runCommand
},
{
name: 'reuseCommand',
command: this._reuseCommand
}
];
const disposable = this._vscode.commands.registerTextEditorCommand(
`${Const.EXTENSION_NAME}.runCommand`,
this._runCommand.execute,
this._runCommand
);
context.subscriptions.push(disposable);
}

}
Expand Down
4 changes: 2 additions & 2 deletions lib/command-readers/historical.js → lib/command-reader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

class HistoricalCommandReader {
class CommandReader {

constructor(params) {
this._historyStore = params.historyStore;
Expand Down Expand Up @@ -47,4 +47,4 @@ class HistoricalCommandReader {

}

module.exports = HistoricalCommandReader;
module.exports = CommandReader;
14 changes: 0 additions & 14 deletions lib/command-readers/simple.js

This file was deleted.

5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"filter"
],
"activationEvents": [
"onCommand:editWithShell.reuseCommand",
"onCommand:editWithShell.runCommand"
],
"main": "./extension",
Expand All @@ -35,10 +34,6 @@
{
"command": "editWithShell.runCommand",
"title": "EditWithShell: Run command"
},
{
"command": "editWithShell.reuseCommand",
"title": "EditWithShell: Reuse command"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

const HistoricalCommandReader = require('../../../lib/command-readers/historical');
const CommandReader = require('../../lib/command-reader');

describe('HistoricalCommandReader', () => {
describe('CommandReader', () => {

it('allows user to pick and modify a past command. Commands shown last one first', () => {
const vscodeWindow = {
showInputBox: sinon.stub().returns(Promise.resolve('COMMAND_FINAL')),
showQuickPick: sinon.stub().returns(Promise.resolve('COMMAND_1'))
};
const historyStore = {getAll: () => ['COMMAND_1', 'COMMAND_2']};
const reader = new HistoricalCommandReader({historyStore, vsWindow: vscodeWindow});
const reader = new CommandReader({historyStore, vsWindow: vscodeWindow});
return reader.read().then(command => {
expect(command).to.eql('COMMAND_FINAL');
expect(vscodeWindow.showQuickPick).to.have.been.calledWith(
Expand All @@ -30,7 +30,7 @@ describe('HistoricalCommandReader', () => {
showQuickPick: sinon.spy()
};
const historyStore = {getAll: () => []};
const reader = new HistoricalCommandReader({historyStore, vsWindow: vscodeWindow});
const reader = new CommandReader({historyStore, vsWindow: vscodeWindow});
return reader.read().then(command => {
expect(command).to.eql('COMMAND');
expect(vscodeWindow.showQuickPick).to.not.have.been.called;
Expand All @@ -47,7 +47,7 @@ describe('HistoricalCommandReader', () => {
showQuickPick: () => Promise.resolve()
};
const historyStore = {getAll: () => ['COMMAND_1', 'COMMAND_2']};
const reader = new HistoricalCommandReader({historyStore, vsWindow: vscodeWindow});
const reader = new CommandReader({historyStore, vsWindow: vscodeWindow});
return reader.read().then(command => {
expect(command).to.eql('COMMAND');
expect(vscodeWindow.showInputBox).to.have.been.calledWith({
Expand Down
19 changes: 0 additions & 19 deletions test/lib/command-readers/simple.test.js

This file was deleted.

0 comments on commit 9619a24

Please sign in to comment.