diff --git a/src/events/activate.ts b/src/events/activate.ts index f9b60edd..a040dadc 100644 --- a/src/events/activate.ts +++ b/src/events/activate.ts @@ -22,8 +22,8 @@ export default async function (core: ExtensionCore, context: ExtensionContext) { if (event.affectsConfiguration(_discloudAppSeparateByType)) return core.userAppTree.refresh(); if (event.affectsConfiguration(_discloudAppShowAvatarInsteadStatus)) { + // @ts-expect-error ts(2445) for (const app of core.userAppTree.children.values()) app._patch({}); - return core.userAppTree.refresh(); } diff --git a/src/language/CompletionItemProvider.ts b/src/language/CompletionItemProvider.ts index 99e26463..6730c00e 100644 --- a/src/language/CompletionItemProvider.ts +++ b/src/language/CompletionItemProvider.ts @@ -29,7 +29,7 @@ export default class CompletionItemProvider extends BaseLanguageProvider { ]).catch(() => []), }, _lineBreakSymbol, _arraySeparator, _assignSymbol, _pathSeparator); - this.context.subscriptions.push(disposable); + context.subscriptions.push(disposable); } async provideCompletionItems(document: TextDocument, position: Position, _token: CancellationToken, _context: CompletionContext) { diff --git a/src/providers/BaseTreeDataProvider.ts b/src/providers/BaseTreeDataProvider.ts index e1f54fab..fd83e1b2 100644 --- a/src/providers/BaseTreeDataProvider.ts +++ b/src/providers/BaseTreeDataProvider.ts @@ -7,7 +7,7 @@ export default abstract class BaseTreeDataProvider, constructor(readonly core: ExtensionCore, readonly viewId: string) { const disposable = window.registerTreeDataProvider(viewId, this); - this.core.context.subscriptions.push(disposable, this._onDidChangeTreeData, this.children); + core.context.subscriptions.push(disposable, this._onDidChangeTreeData, this.children); } protected readonly _onDidChangeTreeData = new EventEmitter(); diff --git a/src/providers/UserAppTreeDataProvider.ts b/src/providers/UserAppTreeDataProvider.ts index c3011784..b5dde422 100644 --- a/src/providers/UserAppTreeDataProvider.ts +++ b/src/providers/UserAppTreeDataProvider.ts @@ -18,7 +18,7 @@ export default class UserAppTreeDataProvider extends BaseTreeDataProvider constructor(readonly core: ExtensionCore) { super(core, TreeViewIds.discloudUserApps); - this.core.context.subscriptions.push(this._views); + core.context.subscriptions.push(this._views); } get size() { diff --git a/src/services/discloud/UserAgent.ts b/src/services/discloud/UserAgent.ts index 4c59333c..84625ba1 100644 --- a/src/services/discloud/UserAgent.ts +++ b/src/services/discloud/UserAgent.ts @@ -1,17 +1,18 @@ import { arch, platform, release, type } from "os"; import type { ExtensionContext } from "vscode"; -function _osProperties() { return `(${type()} ${_osRelease()}; ${platform()}; ${arch()})`; } +const _product = "vscode"; -function _osRelease() { return release().split?.(".").slice(0, 2).join(".") ?? release(); } +function _osProperties() { return `(${type()} ${_formatOsRelease(release())}; ${platform()}; ${arch()})`; } + +function _formatOsRelease(r: string) { return r.split?.(".").slice(0, 2).join(".") ?? r; } export default class UserAgent { constructor(readonly context: ExtensionContext) { } - readonly prefix: string = "vscode"; #userAgent!: string; - #getUserAgent() { return `${this.prefix}/${this.version} ${_osProperties()}`; } + #getUserAgent() { return `${_product}/${this.version} ${_osProperties()}`; } get version() { return this.context.extension.packageJSON.version; } diff --git a/src/services/discloud/api.ts b/src/services/discloud/api.ts index 2c7ca720..fea75d59 100644 --- a/src/services/discloud/api.ts +++ b/src/services/discloud/api.ts @@ -20,7 +20,7 @@ export default class DiscloudApi extends EventEmitter { this.options = options ?? {}; - this.options.userAgent ??= new UserAgent(this.core.context); + this.options.userAgent ??= new UserAgent(core.context); } declare readonly options: Partial; diff --git a/src/structures/BaseChildTreeItem.ts b/src/structures/BaseChildTreeItem.ts index 8cf0fb11..7b4fd95d 100644 --- a/src/structures/BaseChildTreeItem.ts +++ b/src/structures/BaseChildTreeItem.ts @@ -1,26 +1,23 @@ -import { type ExtensionContext, TreeItem, type TreeItemCollapsibleState, type TreeItemLabel } from "vscode"; +import { type Disposable, type ExtensionContext, TreeItem, type TreeItemCollapsibleState, type TreeItemLabel } from "vscode"; import type { BaseChildTreeItemData } from "../@types"; -export default abstract class BaseChildTreeItem extends TreeItem implements Disposable { - readonly contextKey = "ChildTreeItem"; - contextValue = this.contextKey; +const _defaultContextJSON: Record = {}; +export default abstract class BaseChildTreeItem extends TreeItem implements Disposable { constructor(readonly context: ExtensionContext, label: string | TreeItemLabel, collapsibleState?: TreeItemCollapsibleState) { super(label, collapsibleState); - } - [Symbol.dispose](): void { - throw new Error("Method not implemented."); + this.contextValue = this.contextKey; } - get contextJSON(): Record { - return {}; - } + readonly contextKey: string = "ChildTreeItem"; + + get contextJSON(): Record { return _defaultContextJSON; } dispose() { } protected _patch(data: Partial): this; protected _patch(data: Partial) { - if (!data) return this; + if (data == null) return this; if (data.accessibilityInformation !== undefined) this.accessibilityInformation = data.accessibilityInformation; diff --git a/src/structures/BaseStatusBarItem.ts b/src/structures/BaseStatusBarItem.ts index 3fa1ba98..4ca17fff 100644 --- a/src/structures/BaseStatusBarItem.ts +++ b/src/structures/BaseStatusBarItem.ts @@ -24,9 +24,7 @@ export default abstract class BaseStatusBarItem implements StatusBarItem { declare protected readonly defaults: StatusBarItemData; declare protected readonly item: StatusBarItem; - reset() { - this.set(this.defaults); - } + reset() { this.set(this.defaults); } set(data: Partial) { if (data.accessibilityInformation !== undefined) this.accessibilityInformation = data.accessibilityInformation; diff --git a/src/structures/BaseTreeItem.ts b/src/structures/BaseTreeItem.ts index e3be3806..e84d57eb 100644 --- a/src/structures/BaseTreeItem.ts +++ b/src/structures/BaseTreeItem.ts @@ -2,18 +2,22 @@ import { TreeItem, type Disposable, type TreeItemCollapsibleState, type TreeItem import type ExtensionCore from "../core"; import DisposableMap from "./DisposableMap"; +const _defaultContextJSON: Record = {}; + export default abstract class BaseTreeItem extends TreeItem implements Disposable { constructor(readonly core: ExtensionCore, label: string | TreeItemLabel, collapsibleState?: TreeItemCollapsibleState) { super(label, collapsibleState); this.contextValue = this.contextKey; } - readonly children = new DisposableMap(); - declare readonly data: unknown; readonly contextKey: string = "TreeItem"; + declare readonly data: unknown; + readonly children = new DisposableMap(); + + get contextJSON(): Record { return _defaultContextJSON; } - get contextJSON(): Record { - return {}; + protected _upgradeContextValue() { + this.contextValue = this.contextKey; } dispose() { @@ -26,7 +30,7 @@ export default abstract class BaseTreeItem exte protected _patch(data: unknown): this; protected _patch(data: any): this { - if (!data) return this; + if (data == null) return this; Object.assign(this.data, data); diff --git a/src/structures/CustomDomainTreeItem.ts b/src/structures/CustomDomainTreeItem.ts index add046b4..b90362ef 100644 --- a/src/structures/CustomDomainTreeItem.ts +++ b/src/structures/CustomDomainTreeItem.ts @@ -7,9 +7,6 @@ import { getIconPath } from "../utils/vscode"; import BaseTreeItem from "./BaseTreeItem"; export default class CustomDomainTreeItem extends BaseTreeItem { - declare domain: string; - declare iconName: string; - constructor(core: ExtensionCore, public data: CustomDomainTreeItemData) { data.label ??= data.domain; @@ -18,6 +15,9 @@ export default class CustomDomainTreeItem extends BaseTreeItem { this._patch(data); } + declare domain: string; + declare iconName: string; + protected _patch(data: Partial): this { if (!data) return this; diff --git a/src/structures/EmptyAppListTreeItem.ts b/src/structures/EmptyAppListTreeItem.ts index 75504095..e43c65f3 100644 --- a/src/structures/EmptyAppListTreeItem.ts +++ b/src/structures/EmptyAppListTreeItem.ts @@ -10,7 +10,7 @@ export default class EmptyAppListTreeItem extends TreeItem { constructor(readonly core: ExtensionCore) { super(t("no.app.found")); - this.iconPath = getIconPath(this.core.context, EMPTY_TREE_ITEM_ID); + this.iconPath = getIconPath(core.context, EMPTY_TREE_ITEM_ID); } readonly contextValue = _emptyContextValue; diff --git a/src/structures/SubDomainTreeItem.ts b/src/structures/SubDomainTreeItem.ts index 6b279ef5..6bafbd54 100644 --- a/src/structures/SubDomainTreeItem.ts +++ b/src/structures/SubDomainTreeItem.ts @@ -19,7 +19,7 @@ export default class SubDomainTreeItem extends BaseTreeItem { } protected _patch(data: Partial): this { - if (!data) return this; + if (data == null) return this; super._patch(data); diff --git a/src/structures/TeamAppChildTreeItem.ts b/src/structures/TeamAppChildTreeItem.ts index 64edd33f..455dc5e2 100644 --- a/src/structures/TeamAppChildTreeItem.ts +++ b/src/structures/TeamAppChildTreeItem.ts @@ -26,8 +26,8 @@ export default class TeamAppChildTreeItem extends BaseChildTreeItem { }; } - _patch(data: Partial) { - if (!data) return this; + protected _patch(data: Partial) { + if (data == null) return this; super._patch(data); diff --git a/src/structures/TeamAppTreeItem.ts b/src/structures/TeamAppTreeItem.ts index 70a37972..e896d627 100644 --- a/src/structures/TeamAppTreeItem.ts +++ b/src/structures/TeamAppTreeItem.ts @@ -54,8 +54,8 @@ export default class TeamAppTreeItem extends BaseTreeItem return this.data.type ?? null; } - _patch(data: Partial): this { - if (!data) return this; + protected _patch(data: Partial): this { + if (data == null) return this; super._patch(data); @@ -159,6 +159,7 @@ export default class TeamAppTreeItem extends BaseTreeItem const existing = this.children.get(id); if (existing) { + // @ts-expect-error ts(2445) existing._patch(data); return; } diff --git a/src/structures/UserAppChildTreeItem.ts b/src/structures/UserAppChildTreeItem.ts index 53183607..a051781c 100644 --- a/src/structures/UserAppChildTreeItem.ts +++ b/src/structures/UserAppChildTreeItem.ts @@ -28,8 +28,8 @@ export default class UserAppChildTreeItem extends BaseChildTreeItem { }; } - _patch(data: Partial) { - if (!data) return this; + protected _patch(data: Partial) { + if (data == null) return this; super._patch(data); diff --git a/src/structures/UserAppTreeItem.ts b/src/structures/UserAppTreeItem.ts index 86b03c24..4439a2d0 100644 --- a/src/structures/UserAppTreeItem.ts +++ b/src/structures/UserAppTreeItem.ts @@ -50,8 +50,8 @@ export default class UserAppTreeItem extends BaseTreeItem return this.data.online; } - _patch(data: Partial): this { - if (!data) return this; + protected _patch(data: Partial): this { + if (data == null) return this; super._patch(data); @@ -159,6 +159,7 @@ export default class UserAppTreeItem extends BaseTreeItem const existing = this.children.get(id); if (existing) { + // @ts-expect-error ts(2445) existing._patch(data); return; } diff --git a/src/structures/UserAppTypeTreeItemView.ts b/src/structures/UserAppTypeTreeItemView.ts index c3dbd217..f15b06ae 100644 --- a/src/structures/UserAppTypeTreeItemView.ts +++ b/src/structures/UserAppTypeTreeItemView.ts @@ -8,11 +8,8 @@ import type UserAppTreeItem from "./UserAppTreeItem"; export default class AppTypeTreeItemView extends BaseTreeItem { constructor(core: ExtensionCore, readonly type: AppType) { super(core, t(AppType[type]), TreeItemCollapsibleState.Expanded); - this.contextValue = this.contextKey; } - readonly contextKey = "TreeView"; - dispose(): void; dispose(key: string): boolean; dispose(key?: string) { diff --git a/src/structures/UserChildTreeItem.ts b/src/structures/UserChildTreeItem.ts index bd4253e9..7b390171 100644 --- a/src/structures/UserChildTreeItem.ts +++ b/src/structures/UserChildTreeItem.ts @@ -13,8 +13,8 @@ export default class UserChildTreeItem extends BaseChildTreeItem { readonly userID: string; - _patch(data: Partial) { - if (!data) return this; + protected _patch(data: Partial) { + if (data == null) return this; super._patch(data); diff --git a/src/structures/UserTreeItem.ts b/src/structures/UserTreeItem.ts index 8a495319..ad35cf47 100644 --- a/src/structures/UserTreeItem.ts +++ b/src/structures/UserTreeItem.ts @@ -19,7 +19,7 @@ export default class UserTreeItem extends BaseTreeItem { readonly userID: string; protected _patch(data: Partial): this { - if (!data) return this; + if (data == null) return this; if (data.avatar) try { this.iconPath = Uri.parse(data.avatar); } catch { } @@ -106,6 +106,7 @@ export default class UserTreeItem extends BaseTreeItem { const existing = this.children.get(id); if (existing) { + // @ts-expect-error ts(2445) existing._patch(data); return; }