diff --git a/.vscode/Discloud.code-snippets b/.vscode/Discloud.code-snippets index 2c2f35f9..2f959451 100644 --- a/.vscode/Discloud.code-snippets +++ b/.vscode/Discloud.code-snippets @@ -15,6 +15,17 @@ // ], // "description": "Log output to console" // } + "event" :{ + "body": [ + "import type ExtensionCore from \"../core/extension\";", + "", + "export default async function (core: ExtensionCore) {", + "\t$0", + "}" + ], + "prefix": "event", + "scope": "typescript" + }, "extcmd": { "body": [ "import { TaskData } from \"../@types\";", diff --git a/src/@types/event.ts b/src/@types/event.ts new file mode 100644 index 00000000..c4fdb891 --- /dev/null +++ b/src/@types/event.ts @@ -0,0 +1,4 @@ +export interface IEventModule, K extends keyof E, V extends E[K] = E[K]> { + readonly once?: boolean + default(...args: V): void +} diff --git a/src/@types/index.ts b/src/@types/index.ts index d89f47dc..67418332 100644 --- a/src/@types/index.ts +++ b/src/@types/index.ts @@ -1,4 +1,5 @@ export * from "./api"; +export * from "./event"; export * from "./rest"; export * from "./structures"; export * from "./vscode"; diff --git a/src/@types/structures.ts b/src/@types/structures.ts index 5cb8dba4..d71a052f 100644 --- a/src/@types/structures.ts +++ b/src/@types/structures.ts @@ -1,10 +1,11 @@ import type { CancellationToken, ExtensionContext, LogOutputChannel, ProgressOptions, TreeItem, Uri } from "vscode"; +import type ExtensionCore from "../core/extension"; import type BaseChildTreeItem from "../structures/BaseChildTreeItem"; import type TeamAppTreeItem from "../structures/TeamAppTreeItem"; import type UserAppTreeItem from "../structures/UserAppTreeItem"; import type VSUser from "../structures/VSUser"; import type { RateLimitData } from "./rest"; -import { type ProgressTaskParameters, type VscodeProgressReporter } from "./vscode"; +import type { ProgressTaskParameters, VscodeProgressReporter } from "./vscode"; export interface GetWorkspaceFolderOptions { /** @default true */ @@ -89,15 +90,15 @@ export interface UserTreeItemData extends BaseTreeItemData { } export interface Events { - activate: [context: ExtensionContext] - appUpdate: [oldApp: UserAppTreeItem, newApp: UserAppTreeItem] - authorized: [] - debug: Parameters - error: [error: Error | unknown] - missingConnection: [] - missingToken: [] - rateLimited: [rateLimitData: RateLimitData] - teamAppUpdate: [oldTeamApp: TeamAppTreeItem, newTeamApp: TeamAppTreeItem] - unauthorized: [] - vscode: [user: VSUser] + activate: [core: ExtensionCore, context: ExtensionContext] + appUpdate: [core: ExtensionCore, oldApp: UserAppTreeItem, newApp: UserAppTreeItem] + authorized: [core: ExtensionCore] + debug: [core: ExtensionCore, ...Parameters] + error: [core: ExtensionCore, error: Error | unknown] + missingConnection: [core: ExtensionCore] + missingToken: [core: ExtensionCore] + rateLimited: [core: ExtensionCore, rateLimitData: RateLimitData] + teamAppUpdate: [core: ExtensionCore, oldTeamApp: TeamAppTreeItem, newTeamApp: TeamAppTreeItem] + unauthorized: [core: ExtensionCore] + vscode: [core: ExtensionCore, user: VSUser] } diff --git a/src/authentication/pat/provider.ts b/src/authentication/pat/provider.ts index 134de692..9e39063b 100644 --- a/src/authentication/pat/provider.ts +++ b/src/authentication/pat/provider.ts @@ -1,7 +1,7 @@ import { type RESTGetApiUserResult, RouteBases, Routes } from "@discloudapp/api-types/v2"; import { t } from "@vscode/l10n"; import { authentication, type AuthenticationProvider, type AuthenticationProviderAuthenticationSessionsChangeEvent, type AuthenticationProviderSessionOptions, type AuthenticationSession, type AuthenticationSessionAccountInformation, type EventEmitter, type SecretStorage, window } from "vscode"; -import { type IGlobalStateStorage } from "../../@types"; +import type { IGlobalStateStorage } from "../../@types"; import { tokenIsDiscloudJwt } from "../../services/discloud/utils"; import { GlobalStorageKeys } from "../../utils/constants"; import { AuthenticationProviderId } from "../enum/providers"; diff --git a/src/authentication/providers.ts b/src/authentication/providers.ts index 5d52e7f3..2e1d22c4 100644 --- a/src/authentication/providers.ts +++ b/src/authentication/providers.ts @@ -3,7 +3,7 @@ import { authentication, type AuthenticationProvider, type AuthenticationProvide import type ExtensionCore from "../core/extension"; import { GlobalStorageKeys } from "../utils/constants"; import { AuthenticationProviderId } from "./enum/providers"; -import { type IPatAuthenticationProvider } from "./interfaces/pat"; +import type { IPatAuthenticationProvider } from "./interfaces/pat"; import DiscloudPatAuthenticationProvider from "./pat/provider"; export default class AuthenticationProviderContainer implements AuthenticationProvider { diff --git a/src/authentication/session.ts b/src/authentication/session.ts index d63d85bb..a4a5dd58 100644 --- a/src/authentication/session.ts +++ b/src/authentication/session.ts @@ -1,4 +1,4 @@ -import { type AuthenticationSession, type AuthenticationSessionAccountInformation } from "vscode"; +import type { AuthenticationSession, AuthenticationSessionAccountInformation } from "vscode"; export default class DiscloudAuthenticationSession implements AuthenticationSession { constructor( diff --git a/src/commands.ts b/src/commands.ts index 1f256862..ae62edba 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -1,9 +1,9 @@ -/* eslint-disable no-duplicate-imports */ + import { t } from "@vscode/l10n"; import { commands, window } from "vscode"; import type ExtensionCore from "./core/extension"; import type Command from "./structures/Command"; -import { type CommandConstructor } from "./structures/Command"; +import type { CommandConstructor } from "./structures/Command"; export async function commandsRegister(core: ExtensionCore) { // root @@ -147,7 +147,7 @@ function commandRegister( return await command.run(null, ...args); } catch (error) { - core.emit("error", error); + core.emit("error", core, error); } finally { core.statusBar.reset(); } diff --git a/src/commands/apps/backup.ts b/src/commands/apps/backup.ts index 2d22275a..09f76de4 100644 --- a/src/commands/apps/backup.ts +++ b/src/commands/apps/backup.ts @@ -3,7 +3,7 @@ import { t } from "@vscode/l10n"; import { existsSync } from "fs"; import { basename } from "path"; import { ProgressLocation, Uri, window, workspace } from "vscode"; -import { type TaskData } from "../../@types"; +import type { TaskData } from "../../@types"; import type ExtensionCore from "../../core/extension"; import Command from "../../structures/Command"; import type UserAppTreeItem from "../../structures/UserAppTreeItem"; diff --git a/src/commands/apps/commit.ts b/src/commands/apps/commit.ts index 16faae6e..4d7f3b5a 100644 --- a/src/commands/apps/commit.ts +++ b/src/commands/apps/commit.ts @@ -1,7 +1,7 @@ import { type RESTPutApiAppCommitResult, Routes } from "@discloudapp/api-types/v2"; import { t } from "@vscode/l10n"; import { CancellationError, ProgressLocation } from "vscode"; -import { type TaskData } from "../../@types"; +import type { TaskData } from "../../@types"; import type ExtensionCore from "../../core/extension"; import { socketCommit } from "../../services/discloud/socket/actions/commit"; import Command from "../../structures/Command"; diff --git a/src/commands/apps/copy.id.ts b/src/commands/apps/copy.id.ts index 692d17db..d50c63f2 100644 --- a/src/commands/apps/copy.id.ts +++ b/src/commands/apps/copy.id.ts @@ -1,6 +1,6 @@ import { t } from "@vscode/l10n"; import { env, window } from "vscode"; -import { type TaskData } from "../../@types"; +import type { TaskData } from "../../@types"; import type ExtensionCore from "../../core/extension"; import Command from "../../structures/Command"; import type UserAppTreeItem from "../../structures/UserAppTreeItem"; diff --git a/src/commands/apps/delete.ts b/src/commands/apps/delete.ts index 0b25bacb..637e632d 100644 --- a/src/commands/apps/delete.ts +++ b/src/commands/apps/delete.ts @@ -1,7 +1,7 @@ import { type RESTDeleteApiAppDeleteResult, Routes } from "@discloudapp/api-types/v2"; import { t } from "@vscode/l10n"; import { CancellationError, ProgressLocation } from "vscode"; -import { type TaskData } from "../../@types"; +import type { TaskData } from "../../@types"; import type ExtensionCore from "../../core/extension"; import Command from "../../structures/Command"; import type UserAppTreeItem from "../../structures/UserAppTreeItem"; diff --git a/src/commands/apps/import.ts b/src/commands/apps/import.ts index d5fd7874..ae61a332 100644 --- a/src/commands/apps/import.ts +++ b/src/commands/apps/import.ts @@ -3,7 +3,7 @@ import { t } from "@vscode/l10n"; import AdmZip from "adm-zip"; import { existsSync } from "fs"; import { ProgressLocation, Uri, commands, window, workspace } from "vscode"; -import { type TaskData } from "../../@types"; +import type { TaskData } from "../../@types"; import type ExtensionCore from "../../core/extension"; import Command from "../../structures/Command"; import type UserAppTreeItem from "../../structures/UserAppTreeItem"; diff --git a/src/commands/apps/logs.ts b/src/commands/apps/logs.ts index a94282ea..84d35d63 100644 --- a/src/commands/apps/logs.ts +++ b/src/commands/apps/logs.ts @@ -1,7 +1,7 @@ import { type RESTGetApiAppLogResult, Routes } from "@discloudapp/api-types/v2"; import { t } from "@vscode/l10n"; import { ProgressLocation } from "vscode"; -import { type TaskData } from "../../@types"; +import type { TaskData } from "../../@types"; import type ExtensionCore from "../../core/extension"; import Command from "../../structures/Command"; import type UserAppTreeItem from "../../structures/UserAppTreeItem"; diff --git a/src/commands/apps/mods/edit.ts b/src/commands/apps/mods/edit.ts index 0e1d9a2c..5b04784b 100644 --- a/src/commands/apps/mods/edit.ts +++ b/src/commands/apps/mods/edit.ts @@ -1,7 +1,7 @@ import { type RESTPutApiAppTeamResult, Routes } from "@discloudapp/api-types/v2"; import { ModPermissionsBF } from "@discloudapp/util"; import { t } from "@vscode/l10n"; -import { CancellationError, ProgressLocation, type QuickPickItem, window } from "vscode"; +import { type QuickPickItem, CancellationError, ProgressLocation, window } from "vscode"; import { type TaskData } from "../../../@types"; import type ExtensionCore from "../../../core/extension"; import Command from "../../../structures/Command"; diff --git a/src/commands/apps/ram.ts b/src/commands/apps/ram.ts index 55f7b630..150c916e 100644 --- a/src/commands/apps/ram.ts +++ b/src/commands/apps/ram.ts @@ -2,7 +2,7 @@ import { type RESTPutApiAppRamResult, Routes } from "@discloudapp/api-types/v2"; import { t } from "@vscode/l10n"; import { CancellationError, ProgressLocation } from "vscode"; import { AppType } from "../../@enum"; -import { type TaskData } from "../../@types"; +import type { TaskData } from "../../@types"; import type ExtensionCore from "../../core/extension"; import Command from "../../structures/Command"; import type UserAppTreeItem from "../../structures/UserAppTreeItem"; diff --git a/src/commands/apps/restart.ts b/src/commands/apps/restart.ts index 04057374..7ca3a2c8 100644 --- a/src/commands/apps/restart.ts +++ b/src/commands/apps/restart.ts @@ -1,7 +1,7 @@ import { type RESTPutApiAppRestartResult, Routes } from "@discloudapp/api-types/v2"; import { t } from "@vscode/l10n"; import { CancellationError, ProgressLocation } from "vscode"; -import { type TaskData } from "../../@types"; +import type { TaskData } from "../../@types"; import type ExtensionCore from "../../core/extension"; import Command from "../../structures/Command"; import type UserAppTreeItem from "../../structures/UserAppTreeItem"; diff --git a/src/commands/apps/start.ts b/src/commands/apps/start.ts index 983b4482..502782a1 100644 --- a/src/commands/apps/start.ts +++ b/src/commands/apps/start.ts @@ -1,7 +1,7 @@ import { type RESTPutApiAppStartResult, Routes } from "@discloudapp/api-types/v2"; import { t } from "@vscode/l10n"; import { ProgressLocation } from "vscode"; -import { type TaskData } from "../../@types"; +import type { TaskData } from "../../@types"; import type ExtensionCore from "../../core/extension"; import Command from "../../structures/Command"; import type UserAppTreeItem from "../../structures/UserAppTreeItem"; diff --git a/src/commands/apps/status.ts b/src/commands/apps/status.ts index 363e94a9..1a119f24 100644 --- a/src/commands/apps/status.ts +++ b/src/commands/apps/status.ts @@ -1,6 +1,6 @@ import { t } from "@vscode/l10n"; import { ProgressLocation } from "vscode"; -import { type TaskData } from "../../@types"; +import type { TaskData } from "../../@types"; import type ExtensionCore from "../../core/extension"; import Command from "../../structures/Command"; import type UserAppTreeItem from "../../structures/UserAppTreeItem"; diff --git a/src/commands/apps/stop.ts b/src/commands/apps/stop.ts index 930179b2..af2a737b 100644 --- a/src/commands/apps/stop.ts +++ b/src/commands/apps/stop.ts @@ -1,7 +1,7 @@ import { type RESTPutApiAppStartResult, Routes } from "@discloudapp/api-types/v2"; import { t } from "@vscode/l10n"; import { CancellationError, ProgressLocation } from "vscode"; -import { type TaskData } from "../../@types"; +import type { TaskData } from "../../@types"; import type ExtensionCore from "../../core/extension"; import Command from "../../structures/Command"; import type UserAppTreeItem from "../../structures/UserAppTreeItem"; diff --git a/src/commands/apps/terminal.ts b/src/commands/apps/terminal.ts index d87f58f0..b465ce68 100644 --- a/src/commands/apps/terminal.ts +++ b/src/commands/apps/terminal.ts @@ -1,5 +1,5 @@ import { type Uri, window } from "vscode"; -import { type TaskData } from "../../@types"; +import type { TaskData } from "../../@types"; import type ExtensionCore from "../../core/extension"; import Command from "../../structures/Command"; import type UserAppTreeItem from "../../structures/UserAppTreeItem"; diff --git a/src/commands/commit.ts b/src/commands/commit.ts index ab3e7d9b..c48b91c8 100644 --- a/src/commands/commit.ts +++ b/src/commands/commit.ts @@ -1,7 +1,7 @@ import { type RESTPutApiAppCommitResult, Routes } from "@discloudapp/api-types/v2"; import { t } from "@vscode/l10n"; import { CancellationError, ProgressLocation } from "vscode"; -import { type TaskData } from "../@types"; +import type { TaskData } from "../@types"; import type ExtensionCore from "../core/extension"; import { socketCommit } from "../services/discloud/socket/actions/commit"; import Command from "../structures/Command"; diff --git a/src/commands/login.ts b/src/commands/login.ts index b7273602..0fe6c559 100644 --- a/src/commands/login.ts +++ b/src/commands/login.ts @@ -1,7 +1,7 @@ import { t } from "@vscode/l10n"; import { setTimeout as sleep } from "timers/promises"; import { authentication, window, type AuthenticationSession } from "vscode"; -import { type TaskData } from "../@types"; +import type { TaskData } from "../@types"; import UnauthorizedError from "../authentication/errors/unauthorized"; import { pickAuthenticationProviderId } from "../authentication/pick/AuthenticationProviderPicker"; import type ExtensionCore from "../core/extension"; @@ -31,7 +31,7 @@ export default class extends Command { void window.showInformationMessage(t("valid.token")); } - this.core.emit("authorized"); + this.core.emit("authorized", this.core); await sleep(); diff --git a/src/commands/logout.ts b/src/commands/logout.ts index 2e22edce..190a71f5 100644 --- a/src/commands/logout.ts +++ b/src/commands/logout.ts @@ -1,4 +1,4 @@ -import { type AuthenticationSessionAccountInformation } from "vscode"; +import type { AuthenticationSessionAccountInformation } from "vscode"; import type ExtensionCore from "../core/extension"; import Command from "../structures/Command"; import type UserTreeItem from "../structures/UserTreeItem"; diff --git a/src/commands/logs.ts b/src/commands/logs.ts index 30d58a4e..9e94cd83 100644 --- a/src/commands/logs.ts +++ b/src/commands/logs.ts @@ -2,7 +2,7 @@ import { DiscloudConfigScopes, type RESTGetApiAppLogResult, Routes } from "@disc import { DiscloudConfig } from "@discloudapp/util"; import { t } from "@vscode/l10n"; import { ProgressLocation } from "vscode"; -import { type TaskData } from "../@types"; +import type { TaskData } from "../@types"; import type ExtensionCore from "../core/extension"; import Command from "../structures/Command"; import type TeamAppTreeItem from "../structures/TeamAppTreeItem"; diff --git a/src/commands/upload.ts b/src/commands/upload.ts index e273e02e..383bca85 100644 --- a/src/commands/upload.ts +++ b/src/commands/upload.ts @@ -2,7 +2,7 @@ import { type RESTPostApiUploadResult, Routes } from "@discloudapp/api-types/v2" import { DiscloudConfig } from "@discloudapp/util"; import { t } from "@vscode/l10n"; import { CancellationError, ProgressLocation, Uri } from "vscode"; -import { type TaskData } from "../@types"; +import type { TaskData } from "../@types"; import type ExtensionCore from "../core/extension"; import { socketUpload } from "../services/discloud/socket/actions/upload"; import Command from "../structures/Command"; diff --git a/src/core/extension.ts b/src/core/extension.ts index 140defde..7ff85222 100644 --- a/src/core/extension.ts +++ b/src/core/extension.ts @@ -85,7 +85,7 @@ export default class ExtensionCore extends EventEmitter implements Dispo } debug(...args: Parameters) { - this.emit("debug", ...args); + this.emit("debug", this, ...args); } dispose() { @@ -207,6 +207,6 @@ export default class ExtensionCore extends EventEmitter implements Dispo userTree: { value: userTree }, }); - this.emit("activate", context); + this.emit("activate", this, context); } } diff --git a/src/events.ts b/src/events.ts index a8fb7019..78d93c24 100644 --- a/src/events.ts +++ b/src/events.ts @@ -1,17 +1,30 @@ +import type { Events, IEventModule } from "./@types"; import type ExtensionCore from "./core/extension"; export async function loadEvents(core: ExtensionCore) { - await import("./events/activate"); - await import("./events/appUpdate"); - await import("./events/authorized"); - await import("./events/debug"); - await import("./events/error"); - await import("./events/missingConnection"); - await import("./events/missingToken"); - await import("./events/rateLimited"); - await import("./events/teamAppUpdate"); - await import("./events/unauthorized"); - await import("./events/vscode"); + await Promise.all([ + loadEvent(core, "activate", import("./events/activate")), + loadEvent(core, "appUpdate", import("./events/appUpdate")), + loadEvent(core, "authorized", import("./events/authorized")), + loadEvent(core, "debug", import("./events/debug")), + loadEvent(core, "error", import("./events/error")), + loadEvent(core, "missingConnection", import("./events/missingConnection")), + loadEvent(core, "missingToken", import("./events/missingToken")), + loadEvent(core, "rateLimited", import("./events/rateLimited")), + loadEvent(core, "teamAppUpdate", import("./events/teamAppUpdate")), + loadEvent(core, "unauthorized", import("./events/unauthorized")), + loadEvent(core, "vscode", import("./events/vscode")), + ]); core.debug("Events loaded"); } + +async function loadEvent( + core: ExtensionCore, + name: K, + eventPromise: Promise>, +) { + const event = await eventPromise; + const invoker = event.once ? "once" : "on"; + core[invoker](name, event.default as any); +} diff --git a/src/events/activate.ts b/src/events/activate.ts index f3a10eea..0eb84629 100644 --- a/src/events/activate.ts +++ b/src/events/activate.ts @@ -1,13 +1,12 @@ -import { type AuthenticationSessionAccountInformation, commands, workspace } from "vscode"; +import { type AuthenticationSessionAccountInformation, commands, type ExtensionContext, workspace } from "vscode"; import { AuthenticationProviderId } from "../authentication/enum/providers"; import type ExtensionCore from "../core/extension"; -import core from "../extension"; import BaseLanguageProvider from "../language/BaseLanguageProvider"; import CompletionItemProvider from "../language/CompletionItemProvider"; import LanguageConfigurationProvider from "../language/LanguageConfigurationProvider"; import { DISCLOUD_CONFIG_SCHEMA_FILE_NAME, GlobalStorageKeys } from "../utils/constants"; -core.on("activate", async function (context) { +export default async function (core: ExtensionCore, context: ExtensionContext) { queueMicrotask(async function () { try { const path = context.asAbsolutePath(DISCLOUD_CONFIG_SCHEMA_FILE_NAME); @@ -43,7 +42,7 @@ core.on("activate", async function (context) { const disposableAuthenticationEvent = core.auth.onDidChangeSessions(async (event) => { if (event.removed?.length) { const session = await core.auth.getSession(); - if (!session) core.emit("missingToken"); + if (!session) core.emit("missingToken", core); return; } }); @@ -63,7 +62,7 @@ core.on("activate", async function (context) { } await commands.executeCommand("setContext", "discloudInitialized", true); -}); +} async function migrateAuthenticationProvider(core: ExtensionCore) { const oldSessionIdList = core.globalStorage.get("sessionIdList", []); diff --git a/src/events/appUpdate.ts b/src/events/appUpdate.ts index 5b265ebd..3fdbb526 100644 --- a/src/events/appUpdate.ts +++ b/src/events/appUpdate.ts @@ -1,9 +1,10 @@ import { t } from "@vscode/l10n"; import { window } from "vscode"; -import core from "../extension"; +import type ExtensionCore from "../core/extension"; +import type UserAppTreeItem from "../structures/UserAppTreeItem"; import { ConfigKeys } from "../utils/constants"; -core.on("appUpdate", async function (oldApp, newApp) { +export default async function (core: ExtensionCore, oldApp: UserAppTreeItem, newApp: UserAppTreeItem) { if (!core.config.get(ConfigKeys.appNotificationStatus)) return; const messageList: string[] = []; @@ -19,4 +20,4 @@ core.on("appUpdate", async function (oldApp, newApp) { if (messageList.length) void window.showInformationMessage(messageList.join("\n")); -}); +} diff --git a/src/events/authorized.ts b/src/events/authorized.ts index a5001e7c..28f420ad 100644 --- a/src/events/authorized.ts +++ b/src/events/authorized.ts @@ -1,7 +1,7 @@ import { commands } from "vscode"; -import core from "../extension"; +import type ExtensionCore from "../core/extension"; -core.on("authorized", async function () { +export default async function (core: ExtensionCore) { await Promise.all([ commands.executeCommand("setContext", "discloudAuthorized", true), commands.executeCommand("setContext", "discloudUnauthorized", false), @@ -12,4 +12,4 @@ core.on("authorized", async function () { core.statusBar.reset(); core.logger.info("Authorized"); -}); +} diff --git a/src/events/debug.ts b/src/events/debug.ts index 985b15b9..991c244e 100644 --- a/src/events/debug.ts +++ b/src/events/debug.ts @@ -1,7 +1,7 @@ import { format } from "util"; -import core from "../extension"; +import type ExtensionCore from "../core/extension"; -core.on("debug", async function (message, ...args) { +export default async function (core: ExtensionCore, message: string, ...args: any[]) { if (core.isDebug) core.logger.appendLine(format(message, ...args)); else core.logger.debug(format(message, ...args)); -}); +} diff --git a/src/events/error.ts b/src/events/error.ts index db543e5f..2baf5067 100644 --- a/src/events/error.ts +++ b/src/events/error.ts @@ -1,10 +1,10 @@ import { t } from "@vscode/l10n"; import { CancellationError, commands, version, window } from "vscode"; +import type ExtensionCore from "../core/extension"; import WarningError from "../errors/warning"; -import core from "../extension"; import DiscloudAPIError from "../services/discloud/errors/api"; -core.on("error", async function (error: any) { +export default async function (core: ExtensionCore, error: any) { if (!error) return; if (error instanceof CancellationError) @@ -39,4 +39,4 @@ core.on("error", async function (error: any) { } void window.showErrorMessage(message); -}); +} diff --git a/src/events/missingConnection.ts b/src/events/missingConnection.ts index f2095917..381c9093 100644 --- a/src/events/missingConnection.ts +++ b/src/events/missingConnection.ts @@ -1,5 +1,5 @@ -import core from "../extension"; +import type ExtensionCore from "../core/extension"; -core.on("missingConnection", async function () { +export default async function (core: ExtensionCore) { core.statusBar.reset(); -}); +} diff --git a/src/events/missingToken.ts b/src/events/missingToken.ts index 933cfc37..f3f65171 100644 --- a/src/events/missingToken.ts +++ b/src/events/missingToken.ts @@ -1,8 +1,8 @@ import { t } from "@vscode/l10n"; import { commands } from "vscode"; -import core from "../extension"; +import type ExtensionCore from "../core/extension"; -core.on("missingToken", async function () { +export default async function (core: ExtensionCore) { await Promise.all([ commands.executeCommand("setContext", "discloudAuthorized", false), commands.executeCommand("setContext", "discloudUnauthorized", false), @@ -14,4 +14,4 @@ core.on("missingToken", async function () { core.statusBar.setLogin(); core.logger.warn(t("missing.token")); -}); +} diff --git a/src/events/rateLimited.ts b/src/events/rateLimited.ts index 1e258c61..5ea990ce 100644 --- a/src/events/rateLimited.ts +++ b/src/events/rateLimited.ts @@ -1,10 +1,11 @@ import { t } from "@vscode/l10n"; import { window } from "vscode"; -import core from "../extension"; +import { type RateLimitData } from "../@types"; +import type ExtensionCore from "../core/extension"; const eventName = "rateLimited"; -core.on(eventName, async function (rateLimitData) { +export default async function (core: ExtensionCore, rateLimitData: RateLimitData) { if (core.timers.has(eventName) || isNaN(rateLimitData.reset) || isNaN(rateLimitData.time)) return; const reset = rateLimitData.reset * 1000 + rateLimitData.time - Date.now(); @@ -21,4 +22,4 @@ core.on(eventName, async function (rateLimitData) { core.statusBar.setRateLimited(true); void window.showInformationMessage(t(eventName, { s: time })); -}); +} diff --git a/src/events/teamAppUpdate.ts b/src/events/teamAppUpdate.ts index 3f9eb98a..1fc2b84c 100644 --- a/src/events/teamAppUpdate.ts +++ b/src/events/teamAppUpdate.ts @@ -1,9 +1,10 @@ import { t } from "@vscode/l10n"; import { window } from "vscode"; -import core from "../extension"; +import type ExtensionCore from "../core/extension"; +import type TeamAppTreeItem from "../structures/TeamAppTreeItem"; import { ConfigKeys } from "../utils/constants"; -core.on("teamAppUpdate", async function (oldApp, newApp) { +export default async function (core: ExtensionCore, oldApp: TeamAppTreeItem, newApp: TeamAppTreeItem) { if (!core.config.get(ConfigKeys.teamAppNotificationStatus)) return; const messageList: string[] = []; @@ -19,4 +20,4 @@ core.on("teamAppUpdate", async function (oldApp, newApp) { if (messageList.length) void window.showInformationMessage(messageList.join("\n")); -}); +} diff --git a/src/events/unauthorized.ts b/src/events/unauthorized.ts index 52101eee..59a0b17d 100644 --- a/src/events/unauthorized.ts +++ b/src/events/unauthorized.ts @@ -1,7 +1,7 @@ import { commands } from "vscode"; -import core from "../extension"; +import type ExtensionCore from "../core/extension"; -core.on("unauthorized", async function () { +export default async function (core: ExtensionCore) { await Promise.all([ commands.executeCommand("setContext", "discloudAuthorized", false), commands.executeCommand("setContext", "discloudUnauthorized", true), @@ -14,4 +14,4 @@ core.on("unauthorized", async function () { core.statusBar.setLogin(); core.logger.warn("Unauthorized"); -}); +} \ No newline at end of file diff --git a/src/events/vscode.ts b/src/events/vscode.ts index 6b75f848..e5741c52 100644 --- a/src/events/vscode.ts +++ b/src/events/vscode.ts @@ -1,6 +1,7 @@ -import core from "../extension"; +import type ExtensionCore from "../core/extension"; +import type VSUser from "../structures/VSUser"; -core.on("vscode", async function (user) { +export default async function (core: ExtensionCore, user: VSUser) { if (!user) return; core.userTree.set(user); @@ -16,4 +17,4 @@ core.on("vscode", async function (user) { if ("customdomains" in user) core.customDomainTree.update(user.customdomains); -}); +} \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index f6a75dd4..76c8d68a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,4 +1,4 @@ -import { type ExtensionContext } from "vscode"; +import type { ExtensionContext } from "vscode"; import ExtensionCore from "./core/extension"; import { localize } from "./localize"; diff --git a/src/language/BaseLanguageProvider.ts b/src/language/BaseLanguageProvider.ts index 6abd03a5..8288db94 100644 --- a/src/language/BaseLanguageProvider.ts +++ b/src/language/BaseLanguageProvider.ts @@ -3,7 +3,7 @@ import { readFile } from "fs/promises"; import type { JSONSchema7 } from "json-schema"; import { compileSchema, type SchemaNode } from "json-schema-library"; import { parseEnv } from "util"; -import { Position, Range, type ExtensionContext, type TextDocument } from "vscode"; +import { type ExtensionContext, Position, Range, type TextDocument } from "vscode"; import { MAX_LANGUAGE_PROVIDER_READ_LINES } from "../utils/constants"; const STRING_BOOLEAN = new Set(["false", "true"]); diff --git a/src/language/LanguageConfigurationProvider.ts b/src/language/LanguageConfigurationProvider.ts index 225876bd..58dc9e2f 100644 --- a/src/language/LanguageConfigurationProvider.ts +++ b/src/language/LanguageConfigurationProvider.ts @@ -1,6 +1,6 @@ import { t } from "@vscode/l10n"; -import { type JSONSchema7 } from "json-schema"; -import { type AnnotationData, type JsonError } from "json-schema-library"; +import type { JSONSchema7 } from "json-schema"; +import type { AnnotationData, JsonError } from "json-schema-library"; import { type Diagnostic, type DiagnosticCollection, DiagnosticSeverity, type ExtensionContext, Position, Range, type TextDocument, Uri, languages, window, workspace } from "vscode"; import BaseLanguageProvider from "./BaseLanguageProvider"; diff --git a/src/output/LogOutputChannel.ts b/src/output/LogOutputChannel.ts index a96174ec..4d64eedc 100644 --- a/src/output/LogOutputChannel.ts +++ b/src/output/LogOutputChannel.ts @@ -1,3 +1,4 @@ + import { type Event, type ExtensionContext, type LogLevel, type LogOutputChannel, window } from "vscode"; export default class DiscloudLogOutputChannel implements LogOutputChannel { diff --git a/src/providers/CustomDomainTreeDataProvider.ts b/src/providers/CustomDomainTreeDataProvider.ts index 46dac5bb..86f91607 100644 --- a/src/providers/CustomDomainTreeDataProvider.ts +++ b/src/providers/CustomDomainTreeDataProvider.ts @@ -1,4 +1,4 @@ -import { type ExtensionContext } from "vscode"; +import type { ExtensionContext } from "vscode"; import CustomDomainTreeItem from "../structures/CustomDomainTreeItem"; import { TreeViewIds } from "../utils/constants"; import BaseTreeDataProvider from "./BaseTreeDataProvider"; diff --git a/src/providers/SubDomainTreeDataProvider.ts b/src/providers/SubDomainTreeDataProvider.ts index 6e8097ac..a7193a9a 100644 --- a/src/providers/SubDomainTreeDataProvider.ts +++ b/src/providers/SubDomainTreeDataProvider.ts @@ -1,4 +1,4 @@ -import { type ExtensionContext } from "vscode"; +import type { ExtensionContext } from "vscode"; import SubDomainTreeItem from "../structures/SubDomainTreeItem"; import { TreeViewIds } from "../utils/constants"; import BaseTreeDataProvider from "./BaseTreeDataProvider"; diff --git a/src/providers/TeamAppTreeDataProvider.ts b/src/providers/TeamAppTreeDataProvider.ts index cec04e8f..4dd5f810 100644 --- a/src/providers/TeamAppTreeDataProvider.ts +++ b/src/providers/TeamAppTreeDataProvider.ts @@ -1,6 +1,6 @@ -import { type ApiStatusApp, type ApiTeamApp, type BaseApiApp, type RESTGetApiAppStatusResult, type RESTGetApiTeamResult, Routes } from "@discloudapp/api-types/v2"; +import { Routes, type ApiStatusApp, type ApiTeamApp, type BaseApiApp, type RESTGetApiAppStatusResult, type RESTGetApiTeamResult } from "@discloudapp/api-types/v2"; import { t } from "@vscode/l10n"; -import { type ProviderResult, type TreeItem, commands, window } from "vscode"; +import { commands, window, type ProviderResult, type TreeItem } from "vscode"; import type ExtensionCore from "../core/extension"; import EmptyAppListTreeItem from "../structures/EmptyAppListTreeItem"; import TeamAppTreeItem from "../structures/TeamAppTreeItem"; @@ -140,7 +140,7 @@ export default class TeamAppTreeDataProvider extends BaseTreeDataProvider this.refresh(existing); - this.core.emit("teamAppUpdate", clone, existing); + this.core.emit("teamAppUpdate", this.core, clone, existing); if (returnBoolean) return false; } else { @@ -163,7 +163,7 @@ export default class TeamAppTreeDataProvider extends BaseTreeDataProvider // @ts-expect-error ts(2445) const clone = app._update(data); - this.core.emit("teamAppUpdate", clone, app); + this.core.emit("teamAppUpdate", this.core, clone, app); this.refresh(app); diff --git a/src/providers/UserAppTreeDataProvider.ts b/src/providers/UserAppTreeDataProvider.ts index 04140182..0f805b85 100644 --- a/src/providers/UserAppTreeDataProvider.ts +++ b/src/providers/UserAppTreeDataProvider.ts @@ -1,6 +1,6 @@ -import { type ApiStatusApp, type BaseApiApp, type RESTGetApiAppStatusResult, Routes } from "@discloudapp/api-types/v2"; +import { Routes, type ApiStatusApp, type BaseApiApp, type RESTGetApiAppStatusResult } from "@discloudapp/api-types/v2"; import { t } from "@vscode/l10n"; -import { type ProviderResult, type TreeItem, commands, window } from "vscode"; +import { commands, window, type ProviderResult, type TreeItem } from "vscode"; import { type AppType } from "../@enum"; import { type ApiVscodeApp } from "../@types"; import type ExtensionCore from "../core/extension"; @@ -189,7 +189,7 @@ export default class UserAppTreeDataProvider extends BaseTreeDataProvider this.refresh(existing); - this.core.emit("appUpdate", clone, existing); + this.core.emit("appUpdate", this.core, clone, existing); if (returnBoolean) return false; } else { @@ -216,7 +216,7 @@ export default class UserAppTreeDataProvider extends BaseTreeDataProvider // @ts-expect-error ts(2445) const clone = app._update(data); - this.core.emit("appUpdate", clone, app); + this.core.emit("appUpdate", this.core, clone, app); this.refresh(app); diff --git a/src/providers/UserTreeDataProvider.ts b/src/providers/UserTreeDataProvider.ts index 79a5227a..96980a18 100644 --- a/src/providers/UserTreeDataProvider.ts +++ b/src/providers/UserTreeDataProvider.ts @@ -1,4 +1,4 @@ -import { type ExtensionContext } from "vscode"; +import type { ExtensionContext } from "vscode"; import { type ApiVscodeUser } from "../@types"; import UserTreeItem from "../structures/UserTreeItem"; import { TreeViewIds } from "../utils/constants"; diff --git a/src/services/discloud/REST.ts b/src/services/discloud/REST.ts index 717bf948..4caa6ca9 100644 --- a/src/services/discloud/REST.ts +++ b/src/services/discloud/REST.ts @@ -81,7 +81,7 @@ export default class REST extends EventEmitter { if (!this.authorized) return null; if (this.limited) { - this.core.emit("rateLimited", { reset: this.reset, time: this.time }); + this.core.emit("rateLimited", this.core, { reset: this.reset, time: this.time }); return null; } @@ -103,6 +103,7 @@ export default class REST extends EventEmitter { } queueMicrotask(() => this.core.emit("debug", + this.core, "Request:", pathname, "Headers:", Object.entries(config.headers!).map(([k, v]) => `${k}:${typeof v}(${`${v}`.length})`).join(" "), )); @@ -112,7 +113,7 @@ export default class REST extends EventEmitter { try { response = await fetch(url, config); } catch { - this.core.emit("missingConnection"); + this.core.emit("missingConnection", this.core); throw Error(t("missing.connection")); } finally { if (inQueue) { @@ -129,7 +130,7 @@ export default class REST extends EventEmitter { if (!response.ok) { switch (response.status) { case 401: - this.core.emit("unauthorized"); + this.core.emit("unauthorized", this.core); break; } diff --git a/src/services/discloud/socket/actions/upload.ts b/src/services/discloud/socket/actions/upload.ts index 8788acc4..3a594236 100644 --- a/src/services/discloud/socket/actions/upload.ts +++ b/src/services/discloud/socket/actions/upload.ts @@ -1,5 +1,5 @@ import { Routes } from "@discloudapp/api-types/v2"; -import { type DiscloudConfig } from "@discloudapp/util"; +import type { DiscloudConfig } from "@discloudapp/util"; import { t } from "@vscode/l10n"; import bytes from "bytes"; import { stripVTControlCharacters } from "util"; diff --git a/src/services/discloud/types.ts b/src/services/discloud/types.ts index 3b80ecc8..9ee9dfd1 100644 --- a/src/services/discloud/types.ts +++ b/src/services/discloud/types.ts @@ -1,6 +1,6 @@ -import { type LogOutputChannel } from "vscode"; +import type { LogOutputChannel } from "vscode"; import { type RateLimitData } from "../../@types"; -import { type RequestMethod } from "./enum"; +import type { RequestMethod } from "./enum"; export type RouteLike = `/${string}` diff --git a/src/structures/BaseChildTreeItem.ts b/src/structures/BaseChildTreeItem.ts index c37ce5af..feb548e4 100644 --- a/src/structures/BaseChildTreeItem.ts +++ b/src/structures/BaseChildTreeItem.ts @@ -1,4 +1,4 @@ -import { type Disposable, TreeItem, type TreeItemCollapsibleState, type TreeItemLabel } from "vscode"; +import { TreeItem, type TreeItemCollapsibleState, type TreeItemLabel } from "vscode"; import { type BaseChildTreeItemData } from "../@types"; export default abstract class BaseChildTreeItem extends TreeItem implements Disposable { @@ -8,6 +8,9 @@ export default abstract class BaseChildTreeItem extends TreeItem implements Disp constructor(label: string | TreeItemLabel, collapsibleState?: TreeItemCollapsibleState) { super(label, collapsibleState); } + [Symbol.dispose](): void { + throw new Error("Method not implemented."); + } get contextJSON(): Record { return {}; diff --git a/src/structures/BaseStatusBarItem.ts b/src/structures/BaseStatusBarItem.ts index 86361525..3a0aaf0f 100644 --- a/src/structures/BaseStatusBarItem.ts +++ b/src/structures/BaseStatusBarItem.ts @@ -1,4 +1,4 @@ -import { type ExtensionContext, type StatusBarItem, window } from "vscode"; +import { window, type ExtensionContext, type StatusBarItem } from "vscode"; import { type CreateStatusBarItemOptions, type StatusBarItemData, type StatusBarItemOptions } from "../@types"; export default abstract class BaseStatusBarItem implements StatusBarItem { diff --git a/src/structures/BaseTreeItem.ts b/src/structures/BaseTreeItem.ts index 5b20e829..d5aa0d2c 100644 --- a/src/structures/BaseTreeItem.ts +++ b/src/structures/BaseTreeItem.ts @@ -1,4 +1,4 @@ -import { type Disposable, TreeItem, type TreeItemCollapsibleState, type TreeItemLabel } from "vscode"; +import { TreeItem, type Disposable, type TreeItemCollapsibleState, type TreeItemLabel } from "vscode"; import DisposableMap from "./DisposableMap"; export default abstract class BaseTreeItem extends TreeItem implements Disposable { diff --git a/src/structures/Command.ts b/src/structures/Command.ts index d8260acf..8e685a47 100644 --- a/src/structures/Command.ts +++ b/src/structures/Command.ts @@ -1,7 +1,7 @@ -import { type RESTGetApiAppTeamResult, Routes } from "@discloudapp/api-types/v2"; +import { Routes, type RESTGetApiAppTeamResult } from "@discloudapp/api-types/v2"; import { t } from "@vscode/l10n"; import { stripVTControlCharacters } from "util"; -import { type LogOutputChannel, type QuickPickItem, window } from "vscode"; +import { window, type LogOutputChannel, type QuickPickItem } from "vscode"; import { type CommandData, type TaskData } from "../@types"; import type ExtensionCore from "../core/extension"; diff --git a/src/structures/DisposableMap.ts b/src/structures/DisposableMap.ts index c1e111f2..750270bb 100644 --- a/src/structures/DisposableMap.ts +++ b/src/structures/DisposableMap.ts @@ -1,4 +1,4 @@ -import { type Disposable } from "vscode"; +import type { Disposable } from "vscode"; export default class DisposableMap extends Map implements Disposable { dispose(): void; diff --git a/src/structures/TeamAppChildTreeItem.ts b/src/structures/TeamAppChildTreeItem.ts index 6acca580..3bb886b1 100644 --- a/src/structures/TeamAppChildTreeItem.ts +++ b/src/structures/TeamAppChildTreeItem.ts @@ -1,4 +1,4 @@ -import { type Disposable, type TreeItem } from "vscode"; +import type { Disposable, TreeItem } from "vscode"; import { type AppType } from "../@enum"; import { type TeamAppChildTreeItemData } from "../@types"; import BaseChildTreeItem from "./BaseChildTreeItem"; diff --git a/src/structures/TeamAppTreeItem.ts b/src/structures/TeamAppTreeItem.ts index 4f88e82b..b4c87a94 100644 --- a/src/structures/TeamAppTreeItem.ts +++ b/src/structures/TeamAppTreeItem.ts @@ -1,7 +1,7 @@ import { type ApiStatusApp, type ApiTeamApp, type BaseApiApp } from "@discloudapp/api-types/v2"; import { calculatePercentage, ModPermissionsBF, type ModPermissionsResolvable } from "@discloudapp/util"; import { t } from "@vscode/l10n"; -import { type LogOutputChannel, TreeItemCollapsibleState } from "vscode"; +import { TreeItemCollapsibleState, type LogOutputChannel } from "vscode"; import { AppType } from "../@enum"; import { type TeamAppChildTreeItemData, type TeamAppTreeItemData } from "../@types"; import core from "../extension"; diff --git a/src/structures/TimerMap.ts b/src/structures/TimerMap.ts index 055ad69f..32ebf955 100644 --- a/src/structures/TimerMap.ts +++ b/src/structures/TimerMap.ts @@ -1,4 +1,4 @@ -import { type Disposable } from "vscode"; +import type { Disposable } from "vscode"; const MAX_TIMER_DELAY = 2147483647; diff --git a/src/structures/UserAppTreeItem.ts b/src/structures/UserAppTreeItem.ts index 40dd0ce6..ca1131ef 100644 --- a/src/structures/UserAppTreeItem.ts +++ b/src/structures/UserAppTreeItem.ts @@ -1,7 +1,7 @@ import { type ApiStatusApp } from "@discloudapp/api-types/v2"; import { calculatePercentage } from "@discloudapp/util"; import { t } from "@vscode/l10n"; -import { type LogOutputChannel, TreeItemCollapsibleState, Uri } from "vscode"; +import { TreeItemCollapsibleState, Uri, type LogOutputChannel } from "vscode"; import { AppType } from "../@enum"; import { type ApiVscodeApp, type UserAppChildTreeItemData, type UserAppTreeItemData } from "../@types"; import core from "../extension"; diff --git a/src/structures/VSUser.ts b/src/structures/VSUser.ts index dc5b29fc..21158e28 100644 --- a/src/structures/VSUser.ts +++ b/src/structures/VSUser.ts @@ -38,7 +38,7 @@ export default class VSUser implements ApiVscodeUser { if (cachedUser) { Object.assign(this, cachedUser); - core.emit("vscode", this); + core.emit("vscode", core, this); if (isFetchTimeLessThanOneMinuteAgo) return this; } @@ -57,7 +57,7 @@ export default class VSUser implements ApiVscodeUser { Object.assign(this, response.user); - core.emit("vscode", this); + core.emit("vscode", core, this); } return this; diff --git a/src/utils/FileSystem.ts b/src/utils/FileSystem.ts index a0d85cb8..3bc8aa5d 100644 --- a/src/utils/FileSystem.ts +++ b/src/utils/FileSystem.ts @@ -1,5 +1,5 @@ import { dirname, join } from "path"; -import { type CancellationToken, FileType, type Uri, commands, env, workspace } from "vscode"; +import { commands, env, FileType, workspace, type CancellationToken, type Uri } from "vscode"; import { BLOCKED_FILES } from "./constants"; import lazy from "./lazy"; diff --git a/src/utils/Input.ts b/src/utils/Input.ts index 4898ef38..20ce8c90 100644 --- a/src/utils/Input.ts +++ b/src/utils/Input.ts @@ -1,5 +1,5 @@ import { t } from "@vscode/l10n"; -import { type InputBoxOptions, window } from "vscode"; +import { window, type InputBoxOptions } from "vscode"; import { clamp } from "./math"; export default class InputBox { diff --git a/src/utils/Zip.ts b/src/utils/Zip.ts index 1973d420..ad60291e 100644 --- a/src/utils/Zip.ts +++ b/src/utils/Zip.ts @@ -1,5 +1,5 @@ import AdmZip from "adm-zip"; -import { FileType, type Uri, workspace } from "vscode"; +import { FileType, workspace, type Uri } from "vscode"; export default class Zip { declare readonly zip: AdmZip; diff --git a/src/utils/events.ts b/src/utils/events.ts index 4e3906bf..29189137 100644 --- a/src/utils/events.ts +++ b/src/utils/events.ts @@ -1,4 +1,4 @@ -import { type EventEmitter, once } from "events"; +import { once, type EventEmitter } from "events"; export function multiListener , K extends keyof T = keyof T> diff --git a/src/utils/utils.ts b/src/utils/utils.ts index ee9208db..b48d5fbb 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,5 +1,5 @@ import { join } from "path"; -import { type TreeItem, Uri } from "vscode"; +import { Uri, type TreeItem } from "vscode"; import core from "../extension"; import { RESOURCES_DIR } from "./constants"; import { scapeRegExp } from "./regexp";