Skip to content

Enable strict TypeScript mode #4206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 0 additions & 145 deletions src/controls/animatedStatusBar.ts

This file was deleted.

77 changes: 33 additions & 44 deletions src/controls/checkboxQuickPick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,17 @@ export interface ICheckboxQuickPickOptions {
confirmPlaceHolder: string;
}

const defaultOptions: ICheckboxQuickPickOptions = { confirmPlaceHolder: defaultPlaceHolder};
const defaultOptions: ICheckboxQuickPickOptions = { confirmPlaceHolder: defaultPlaceHolder };

export function showCheckboxQuickPick(
export async function showCheckboxQuickPick(
items: ICheckboxQuickPickItem[],
options: ICheckboxQuickPickOptions = defaultOptions): Thenable<ICheckboxQuickPickItem[]> {

return showInner(items, options).then(
(selectedItem) => {
// We're mutating the original item list so just return it for now.
// If 'selectedItem' is undefined it means the user cancelled the
// inner showQuickPick UI so pass the undefined along.
return selectedItem !== undefined ? items : undefined;
});
options: ICheckboxQuickPickOptions = defaultOptions): Promise<ICheckboxQuickPickItem[] | undefined> {

const selectedItem = await showInner(items, options);
return selectedItem !== undefined ? items : undefined;
}

function getQuickPickItems(items: ICheckboxQuickPickItem[]): vscode.QuickPickItem[] {

const quickPickItems: vscode.QuickPickItem[] = [];
quickPickItems.push({ label: confirmItemLabel, description: "" });

Expand All @@ -48,40 +42,35 @@ function getQuickPickItems(items: ICheckboxQuickPickItem[]): vscode.QuickPickIte
return quickPickItems;
}

function showInner(
async function showInner(
items: ICheckboxQuickPickItem[],
options: ICheckboxQuickPickOptions): Thenable<vscode.QuickPickItem> {

const quickPickThenable: Thenable<vscode.QuickPickItem> =
vscode.window.showQuickPick(
getQuickPickItems(items),
{
ignoreFocusOut: true,
matchOnDescription: true,
placeHolder: options.confirmPlaceHolder,
});

return quickPickThenable.then(
(selection) => {
if (!selection) {
return Promise.resolve<vscode.QuickPickItem>(undefined);
}

if (selection.label === confirmItemLabel) {
return selection;
}

const index: number = getItemIndex(items, selection.label);

if (index >= 0) {
toggleSelection(items[index]);
} else {
// tslint:disable-next-line:no-console
console.log(`Couldn't find CheckboxQuickPickItem for label '${selection.label}'`);
}

return showInner(items, options);
options: ICheckboxQuickPickOptions): Promise<vscode.QuickPickItem | undefined> {

const selection = await vscode.window.showQuickPick(
getQuickPickItems(items),
{
ignoreFocusOut: true,
matchOnDescription: true,
placeHolder: options.confirmPlaceHolder,
});

if (selection === undefined) {
return undefined;
}

if (selection.label === confirmItemLabel) {
return selection;
}

const index: number = getItemIndex(items, selection.label);
if (index >= 0) {
toggleSelection(items[index]);
} else {
// tslint:disable-next-line:no-console
console.log(`Couldn't find CheckboxQuickPickItem for label '${selection.label}'`);
}

return showInner(items, options);
}

function getItemIndex(items: ICheckboxQuickPickItem[], itemLabel: string): number {
Expand Down
2 changes: 1 addition & 1 deletion src/features/CodeActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class CodeActionsFeature implements vscode.Disposable {

constructor(private log: ILogger) {
this.applyEditsCommand = vscode.commands.registerCommand("PowerShell.ApplyCodeActionEdits", (edit: any) => {
Window.activeTextEditor.edit((editBuilder) => {
Window.activeTextEditor?.edit((editBuilder) => {
editBuilder.replace(
new vscode.Range(
edit.StartLineNumber - 1,
Expand Down
33 changes: 17 additions & 16 deletions src/features/Console.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

"use strict";

import vscode = require("vscode");
import { NotificationType, RequestType } from "vscode-languageclient";
import { LanguageClient } from "vscode-languageclient/node";
Expand Down Expand Up @@ -50,19 +48,17 @@ interface IShowChoicePromptRequestArgs {
}

interface IShowChoicePromptResponseBody {
responseText: string;
responseText: string | undefined;
promptCancelled: boolean;
}

interface IShowInputPromptResponseBody {
responseText: string;
responseText: string | undefined;
promptCancelled: boolean;
}


function showChoicePrompt(
promptDetails: IShowChoicePromptRequestArgs,
client: LanguageClient): Thenable<IShowChoicePromptResponseBody> {
function showChoicePrompt(promptDetails: IShowChoicePromptRequestArgs): Thenable<IShowChoicePromptResponseBody> {

let resultThenable: Thenable<IShowChoicePromptResponseBody>;

Expand Down Expand Up @@ -121,11 +117,12 @@ function showChoicePrompt(
return resultThenable;
}

function showInputPrompt(promptDetails: IShowInputPromptRequestArgs): Thenable<IShowInputPromptResponseBody> {
return vscode.window.showInputBox({ placeHolder: promptDetails.name + ": " }).then(onInputEntered);
async function showInputPrompt(promptDetails: IShowInputPromptRequestArgs): Promise<IShowInputPromptResponseBody> {
const responseText = await vscode.window.showInputBox({ placeHolder: promptDetails.name + ": " });
return onInputEntered(responseText);
}

function onItemsSelected(chosenItems: ICheckboxQuickPickItem[]): IShowChoicePromptResponseBody {
function onItemsSelected(chosenItems: ICheckboxQuickPickItem[] | undefined): IShowChoicePromptResponseBody {
if (chosenItems !== undefined) {
return {
promptCancelled: false,
Expand All @@ -140,7 +137,7 @@ function onItemsSelected(chosenItems: ICheckboxQuickPickItem[]): IShowChoiceProm
}
}

function onItemSelected(chosenItem: vscode.QuickPickItem): IShowChoicePromptResponseBody {
function onItemSelected(chosenItem: vscode.QuickPickItem | undefined): IShowChoicePromptResponseBody {
if (chosenItem !== undefined) {
return {
promptCancelled: false,
Expand All @@ -155,7 +152,7 @@ function onItemSelected(chosenItem: vscode.QuickPickItem): IShowChoicePromptResp
}
}

function onInputEntered(responseText: string): IShowInputPromptResponseBody {
function onInputEntered(responseText: string | undefined): IShowInputPromptResponseBody {
if (responseText !== undefined) {
return {
promptCancelled: false,
Expand All @@ -171,7 +168,7 @@ function onInputEntered(responseText: string): IShowInputPromptResponseBody {

export class ConsoleFeature extends LanguageClientConsumer {
private commands: vscode.Disposable[];
private handlers: vscode.Disposable[];
private handlers: vscode.Disposable[] = [];

constructor(private log: Logger) {
super();
Expand All @@ -192,6 +189,10 @@ export class ConsoleFeature extends LanguageClientConsumer {
}

const editor = vscode.window.activeTextEditor;
if (editor === undefined) {
return;
}

let selectionRange: vscode.Range;

if (!editor.selection.isEmpty) {
Expand All @@ -200,7 +201,7 @@ export class ConsoleFeature extends LanguageClientConsumer {
selectionRange = editor.document.lineAt(editor.selection.start.line).range;
}

await this.languageClient.sendRequest(EvaluateRequestType, {
await this.languageClient?.sendRequest(EvaluateRequestType, {
expression: editor.document.getText(selectionRange),
});

Expand All @@ -221,12 +222,12 @@ export class ConsoleFeature extends LanguageClientConsumer {
}
}

public setLanguageClient(languageClient: LanguageClient) {
public override setLanguageClient(languageClient: LanguageClient) {
this.languageClient = languageClient;
this.handlers = [
this.languageClient.onRequest(
ShowChoicePromptRequestType,
(promptDetails) => showChoicePrompt(promptDetails, this.languageClient)),
(promptDetails) => showChoicePrompt(promptDetails)),

this.languageClient.onRequest(
ShowInputPromptRequestType,
Expand Down
Loading