Skip to content

Commit c4978ea

Browse files
committed
Refactor and typing to make the compiler happy
1 parent 253d2f4 commit c4978ea

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

quickinput-sample/package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

quickinput-sample/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"postinstall": "node ./node_modules/vscode/bin/install"
3030
},
3131
"devDependencies": {
32+
"@types/lodash": "^4.14.116",
3233
"@types/node": "10.3.6",
3334
"tslint": "5.10.0",
3435
"typescript": "2.9.2",

quickinput-sample/src/promptCommandWithHistory.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as fs from 'fs';
2-
import * as path from 'path';
3-
import { Uri, window, Disposable } from 'vscode';
2+
import { window, Disposable } from 'vscode';
43
import { QuickPickItem } from 'vscode';
5-
import { workspace } from 'vscode';
64
import * as _ from 'lodash';
75

86
export const historyPath = `${process.env.HOME}/.vscode-cmd-history`;
@@ -18,23 +16,29 @@ export async function promptCommand() {
1816
}
1917
}
2018

21-
class CommandItem implements QuickPickItem { }
19+
class CommandItem implements QuickPickItem {
20+
public label: string;
21+
public description?: string;
22+
constructor(label: string, description?: string) {
23+
this.label = label;
24+
this.description = description;
25+
}
26+
}
2227
class HistoryItem extends CommandItem {
23-
constructor(public label: string, public description: string?) {
24-
super();
28+
constructor(label: string, description?: string) {
29+
super(label, description);
2530
}
2631
}
2732
class InputItem extends CommandItem {
28-
public description = '(current input)';
2933
constructor(public label: string) {
30-
super();
34+
super(label, '(current input)');
3135
};
3236
}
3337

3438
async function pickCommand() {
3539
const disposables: Disposable[] = [];
36-
let commandsItems = [];
37-
let currentValue = undefined;
40+
let commandsItems: CommandItem[] = [];
41+
let currentValue: string | undefined = undefined;
3842
let historyShouldBeUpdated = false;
3943

4044
try {
@@ -43,7 +47,7 @@ async function pickCommand() {
4347
input.placeholder = 'Type a command';
4448
input.items = commandsItems;
4549

46-
const updateQuickPick = value => {
50+
const updateQuickPick = (value?: string): void => {
4751
if (!value) {
4852
input.items = commandsItems;
4953
return;
@@ -57,11 +61,11 @@ async function pickCommand() {
5761
}
5862

5963
disposables.push(
60-
input.onDidChangeValue(value => {
64+
input.onDidChangeValue((value?: string) => {
6165
currentValue = value;
6266
updateQuickPick(value);
6367
}),
64-
input.onDidChangeSelection(items => {
68+
input.onDidChangeSelection((items: CommandItem[]) => {
6569
const item = items[0];
6670
if (item instanceof HistoryItem) {
6771
resolve(item.label);
@@ -92,7 +96,7 @@ async function pickCommand() {
9296
}
9397
historyShouldBeUpdated = true;
9498
const commands = content.toString().trimRight().split('\n').reverse();
95-
commandsItems = _.map(commands, (cmd, index) => new HistoryItem(cmd, `(history item ${index})`));
99+
commandsItems = _.map(commands, (cmd: string, index: number) => new HistoryItem(cmd, `(history item ${index})`));
96100
updateQuickPick(currentValue);
97101
});
98102
} else {

0 commit comments

Comments
 (0)