diff --git a/quickinput-sample/package-lock.json b/quickinput-sample/package-lock.json index 1925811196..39d1facda2 100644 --- a/quickinput-sample/package-lock.json +++ b/quickinput-sample/package-lock.json @@ -4,6 +4,12 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@types/lodash": { + "version": "4.14.116", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.116.tgz", + "integrity": "sha512-lRnAtKnxMXcYYXqOiotTmJd74uawNWuPnsnPrrO7HiFuE3npE2iQhfABatbYDyxTNqZNuXzcKGhw37R7RjBFLg==", + "dev": true + }, "@types/node": { "version": "10.3.6", "resolved": "https://registry.npmjs.org/@types/node/-/node-10.3.6.tgz", diff --git a/quickinput-sample/package.json b/quickinput-sample/package.json index c7678b9721..956f386e2a 100644 --- a/quickinput-sample/package.json +++ b/quickinput-sample/package.json @@ -29,6 +29,7 @@ "postinstall": "node ./node_modules/vscode/bin/install" }, "devDependencies": { + "@types/lodash": "^4.14.116", "@types/node": "10.3.6", "tslint": "5.10.0", "typescript": "2.9.2", diff --git a/quickinput-sample/src/promptCommandWithHistory.ts b/quickinput-sample/src/promptCommandWithHistory.ts index 484f03497c..8818be8d2b 100644 --- a/quickinput-sample/src/promptCommandWithHistory.ts +++ b/quickinput-sample/src/promptCommandWithHistory.ts @@ -1,8 +1,6 @@ import * as fs from 'fs'; -import * as path from 'path'; -import { Uri, window, Disposable } from 'vscode'; +import { window, Disposable } from 'vscode'; import { QuickPickItem } from 'vscode'; -import { workspace } from 'vscode'; import * as _ from 'lodash'; export const historyPath = `${process.env.HOME}/.vscode-cmd-history`; @@ -18,23 +16,29 @@ export async function promptCommand() { } } -class CommandItem implements QuickPickItem { } +class CommandItem implements QuickPickItem { + public label: string; + public description?: string; + constructor(label: string, description?: string) { + this.label = label; + this.description = description; + } +} class HistoryItem extends CommandItem { - constructor(public label: string, public description: string?) { - super(); + constructor(label: string, description?: string) { + super(label, description); } } class InputItem extends CommandItem { - public description = '(current input)'; constructor(public label: string) { - super(); + super(label, '(current input)'); }; } async function pickCommand() { const disposables: Disposable[] = []; - let commandsItems = []; - let currentValue = undefined; + let commandsItems: CommandItem[] = []; + let currentValue: string | undefined = undefined; let historyShouldBeUpdated = false; try { @@ -43,7 +47,7 @@ async function pickCommand() { input.placeholder = 'Type a command'; input.items = commandsItems; - const updateQuickPick = value => { + const updateQuickPick = (value?: string): void => { if (!value) { input.items = commandsItems; return; @@ -57,11 +61,11 @@ async function pickCommand() { } disposables.push( - input.onDidChangeValue(value => { + input.onDidChangeValue((value?: string) => { currentValue = value; updateQuickPick(value); }), - input.onDidChangeSelection(items => { + input.onDidChangeSelection((items: CommandItem[]) => { const item = items[0]; if (item instanceof HistoryItem) { resolve(item.label); @@ -92,7 +96,7 @@ async function pickCommand() { } historyShouldBeUpdated = true; const commands = content.toString().trimRight().split('\n').reverse(); - commandsItems = _.map(commands, (cmd, index) => new HistoryItem(cmd, `(history item ${index})`)); + commandsItems = _.map(commands, (cmd: string, index: number) => new HistoryItem(cmd, `(history item ${index})`)); updateQuickPick(currentValue); }); } else {