Skip to content

vscode extension: migrate from any to unknown where possible #2989

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 3 commits into from
Feb 2, 2020
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
2 changes: 1 addition & 1 deletion editors/code/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ PATH=${process.env.PATH}
// This also requires considering our settings strategy, which is work which needs doing
// @ts-ignore The tracer is private to vscode-languageclient, but we need access to it to not log publishDecorations requests
res._tracer = {
log: (messageOrDataObject: string | any, data?: string) => {
log: (messageOrDataObject: string | unknown, data?: string) => {
if (typeof messageOrDataObject === 'string') {
if (
messageOrDataObject.includes(
Expand Down
2 changes: 1 addition & 1 deletion editors/code/src/color_theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class ColorTheme {
}

function loadThemeNamed(themeName: string): ColorTheme {
function isTheme(extension: vscode.Extension<any>): boolean {
function isTheme(extension: vscode.Extension<unknown>): boolean {
return (
extension.extensionKind === vscode.ExtensionKind.UI &&
extension.packageJSON.contributes &&
Expand Down
2 changes: 1 addition & 1 deletion editors/code/src/commands/syntax_tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function syntaxTree(ctx: Ctx): Cmd {

// We need to order this after LS updates, but there's no API for that.
// Hence, good old setTimeout.
function afterLs(f: () => any) {
function afterLs(f: () => void) {
setTimeout(f, 10);
}

Expand Down
16 changes: 10 additions & 6 deletions editors/code/src/ctx.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from 'vscode';
import * as lc from 'vscode-languageclient';

import { Config } from './config';
import { createClient } from './client';

Expand Down Expand Up @@ -52,12 +53,12 @@ export class Ctx {
overrideCommand(name: string, factory: (ctx: Ctx) => Cmd) {
const defaultCmd = `default:${name}`;
const override = factory(this);
const original = (...args: any[]) =>
const original = (...args: unknown[]) =>
vscode.commands.executeCommand(defaultCmd, ...args);
try {
const d = vscode.commands.registerCommand(
name,
async (...args: any[]) => {
async (...args: unknown[]) => {
if (!(await override(...args))) {
return await original(...args);
}
Expand All @@ -73,11 +74,11 @@ export class Ctx {
}
}

get subscriptions(): { dispose(): any }[] {
get subscriptions(): Disposable[] {
return this.extCtx.subscriptions;
}

pushCleanup(d: { dispose(): any }) {
pushCleanup(d: Disposable) {
this.extCtx.subscriptions.push(d);
}

Expand All @@ -86,12 +87,15 @@ export class Ctx {
}
}

export type Cmd = (...args: any[]) => any;
export interface Disposable {
dispose(): void;
}
export type Cmd = (...args: any[]) => unknown;

export async function sendRequestWithRetry<R>(
client: lc.LanguageClient,
method: string,
param: any,
param: unknown,
token?: vscode.CancellationToken,
): Promise<R> {
for (const delay of [2, 4, 6, 8, 10, null]) {
Expand Down
4 changes: 2 additions & 2 deletions editors/code/src/status_display.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';

import { WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressReport, WorkDoneProgressEnd } from 'vscode-languageclient';
import { WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressReport, WorkDoneProgressEnd, Disposable } from 'vscode-languageclient';

import { Ctx } from './ctx';

Expand All @@ -14,7 +14,7 @@ export function activateStatusDisplay(ctx: Ctx) {
});
}

class StatusDisplay implements vscode.Disposable {
class StatusDisplay implements vscode.Disposable, Disposable {
packageName?: string;

private i: number = 0;
Expand Down