Strict null check extHostQuickOpen

This commit is contained in:
Matt Bierner
2019-03-05 15:02:38 -08:00
parent 8f3cda12e4
commit 14c4fde6d6
5 changed files with 23 additions and 9 deletions

View File

@@ -15,6 +15,7 @@ import { URI } from 'vs/base/common/uri';
import { ThemeIcon, QuickInputButtons } from 'vs/workbench/api/node/extHostTypes';
import { isPromiseCanceledError } from 'vs/base/common/errors';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { coalesce } from 'vs/base/common/arrays';
export type Item = string | QuickPickItem;
@@ -24,7 +25,7 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {
private _workspace: IExtHostWorkspaceProvider;
private _commands: ExtHostCommands;
private _onDidSelectItem: (handle: number) => void;
private _onDidSelectItem?: (handle: number) => void;
private _validateInput?: (input: string) => string | undefined | null | Thenable<string | undefined | null>;
private _sessions = new Map<number, ExtHostQuickInput>();
@@ -158,12 +159,15 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {
// ---- workspace folder picker
showWorkspaceFolderPick(options?: WorkspaceFolderPickOptions, token = CancellationToken.None): Promise<WorkspaceFolder> {
showWorkspaceFolderPick(options?: WorkspaceFolderPickOptions, token = CancellationToken.None): Promise<WorkspaceFolder | undefined> {
return this._commands.executeCommand('_workbench.pickWorkspaceFolder', [options]).then(async (selectedFolder: WorkspaceFolder) => {
if (!selectedFolder) {
return undefined;
}
const workspaceFolders = await this._workspace.getWorkspaceFolders2();
if (!workspaceFolders) {
return undefined;
}
return workspaceFolders.filter(folder => folder.uri.toString() === selectedFolder.uri.toString())[0];
});
}
@@ -382,7 +386,9 @@ class ExtHostQuickInput implements QuickInput {
_fireDidTriggerButton(handle: number) {
const button = this._handlesToButtons.get(handle);
this._onDidTriggerButtonEmitter.fire(button);
if (button) {
this._onDidTriggerButtonEmitter.fire(button);
}
}
_fireDidHide() {
@@ -437,9 +443,13 @@ class ExtHostQuickInput implements QuickInput {
}
}
function getIconUris(iconPath: QuickInputButton['iconPath']) {
function getIconUris(iconPath: QuickInputButton['iconPath']): { dark: URI, light?: URI } | undefined {
const dark = getDarkIconUri(iconPath);
const light = getLightIconUri(iconPath);
return { dark: getDarkIconUri(iconPath) || light, light };
if (!light && !dark) {
return undefined;
}
return { dark: (dark || light)!, light };
}
function getLightIconUri(iconPath: QuickInputButton['iconPath']) {
@@ -563,13 +573,13 @@ class ExtHostQuickPick<T extends QuickPickItem> extends ExtHostQuickInput implem
onDidChangeSelection = this._onDidChangeSelectionEmitter.event;
_fireDidChangeActive(handles: number[]) {
const items = handles.map(handle => this._handlesToItems.get(handle));
const items = coalesce(handles.map(handle => this._handlesToItems.get(handle)));
this._activeItems = items;
this._onDidChangeActiveEmitter.fire(items);
}
_fireDidChangeSelection(handles: number[]) {
const items = handles.map(handle => this._handlesToItems.get(handle));
const items = coalesce(handles.map(handle => this._handlesToItems.get(handle)));
this._selectedItems = items;
this._onDidChangeSelectionEmitter.fire(items);
}