Skip to content
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 src/events/activate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/language/CompletionItemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/providers/BaseTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default abstract class BaseTreeDataProvider<V extends BaseTreeItem<any>,
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<V | V[] | null | void>();
Expand Down
2 changes: 1 addition & 1 deletion src/providers/UserAppTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class UserAppTreeDataProvider extends BaseTreeDataProvider<Item>
constructor(readonly core: ExtensionCore) {
super(core, TreeViewIds.discloudUserApps);

this.core.context.subscriptions.push(this._views);
core.context.subscriptions.push(this._views);
}

get size() {
Expand Down
9 changes: 5 additions & 4 deletions src/services/discloud/UserAgent.ts
Original file line number Diff line number Diff line change
@@ -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; }

Expand Down
2 changes: 1 addition & 1 deletion src/services/discloud/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RESTOptions>;
Expand Down
19 changes: 8 additions & 11 deletions src/structures/BaseChildTreeItem.ts
Original file line number Diff line number Diff line change
@@ -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<any, any> = {};

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<any, any> {
return {};
}
readonly contextKey: string = "ChildTreeItem";

get contextJSON(): Record<any, any> { return _defaultContextJSON; }

dispose() { }

protected _patch(data: Partial<BaseChildTreeItemData>): this;
protected _patch(data: Partial<BaseChildTreeItemData>) {
if (!data) return this;
if (data == null) return this;

if (data.accessibilityInformation !== undefined) this.accessibilityInformation = data.accessibilityInformation;

Expand Down
4 changes: 1 addition & 3 deletions src/structures/BaseStatusBarItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<StatusBarItemData>) {
if (data.accessibilityInformation !== undefined) this.accessibilityInformation = data.accessibilityInformation;
Expand Down
14 changes: 9 additions & 5 deletions src/structures/BaseTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ import { TreeItem, type Disposable, type TreeItemCollapsibleState, type TreeItem
import type ExtensionCore from "../core";
import DisposableMap from "./DisposableMap";

const _defaultContextJSON: Record<any, any> = {};

export default abstract class BaseTreeItem<T extends TreeItem & Disposable> extends TreeItem implements Disposable {
constructor(readonly core: ExtensionCore, label: string | TreeItemLabel, collapsibleState?: TreeItemCollapsibleState) {
super(label, collapsibleState);
this.contextValue = this.contextKey;
}

readonly children = new DisposableMap<string, T>();
declare readonly data: unknown;
readonly contextKey: string = "TreeItem";
declare readonly data: unknown;
readonly children = new DisposableMap<string, T>();

get contextJSON(): Record<any, any> { return _defaultContextJSON; }

get contextJSON(): Record<any, any> {
return {};
protected _upgradeContextValue() {
this.contextValue = this.contextKey;
}

dispose() {
Expand All @@ -26,7 +30,7 @@ export default abstract class BaseTreeItem<T extends TreeItem & Disposable> exte

protected _patch(data: unknown): this;
protected _patch(data: any): this {
if (!data) return this;
if (data == null) return this;

Object.assign(<any>this.data, data);

Expand Down
6 changes: 3 additions & 3 deletions src/structures/CustomDomainTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import { getIconPath } from "../utils/vscode";
import BaseTreeItem from "./BaseTreeItem";

export default class CustomDomainTreeItem extends BaseTreeItem<any> {
declare domain: string;
declare iconName: string;

constructor(core: ExtensionCore, public data: CustomDomainTreeItemData) {
data.label ??= data.domain;

Expand All @@ -18,6 +15,9 @@ export default class CustomDomainTreeItem extends BaseTreeItem<any> {
this._patch(data);
}

declare domain: string;
declare iconName: string;

protected _patch(data: Partial<CustomDomainTreeItemData>): this {
if (!data) return this;

Expand Down
2 changes: 1 addition & 1 deletion src/structures/EmptyAppListTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/structures/SubDomainTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class SubDomainTreeItem extends BaseTreeItem<any> {
}

protected _patch(data: Partial<SubDomainTreeItemData>): this {
if (!data) return this;
if (data == null) return this;

super._patch(data);

Expand Down
4 changes: 2 additions & 2 deletions src/structures/TeamAppChildTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export default class TeamAppChildTreeItem extends BaseChildTreeItem {
};
}

_patch(data: Partial<TeamAppChildTreeItemData>) {
if (!data) return this;
protected _patch(data: Partial<TeamAppChildTreeItemData>) {
if (data == null) return this;

super._patch(data);

Expand Down
5 changes: 3 additions & 2 deletions src/structures/TeamAppTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export default class TeamAppTreeItem extends BaseTreeItem<TeamAppChildTreeItem>
return this.data.type ?? null;
}

_patch(data: Partial<TeamAppTreeItemData & ApiTeamApp & ApiStatusApp>): this {
if (!data) return this;
protected _patch(data: Partial<TeamAppTreeItemData & ApiTeamApp & ApiStatusApp>): this {
if (data == null) return this;

super._patch(data);

Expand Down Expand Up @@ -159,6 +159,7 @@ export default class TeamAppTreeItem extends BaseTreeItem<TeamAppChildTreeItem>
const existing = this.children.get(id);

if (existing) {
// @ts-expect-error ts(2445)
existing._patch(data);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/structures/UserAppChildTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export default class UserAppChildTreeItem extends BaseChildTreeItem {
};
}

_patch(data: Partial<UserAppChildTreeItemData>) {
if (!data) return this;
protected _patch(data: Partial<UserAppChildTreeItemData>) {
if (data == null) return this;

super._patch(data);

Expand Down
5 changes: 3 additions & 2 deletions src/structures/UserAppTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export default class UserAppTreeItem extends BaseTreeItem<UserAppChildTreeItem>
return this.data.online;
}

_patch(data: Partial<UserAppTreeItemData & ApiVscodeApp & ApiStatusApp>): this {
if (!data) return this;
protected _patch(data: Partial<UserAppTreeItemData & ApiVscodeApp & ApiStatusApp>): this {
if (data == null) return this;

super._patch(data);

Expand Down Expand Up @@ -159,6 +159,7 @@ export default class UserAppTreeItem extends BaseTreeItem<UserAppChildTreeItem>
const existing = this.children.get(id);

if (existing) {
// @ts-expect-error ts(2445)
existing._patch(data);
return;
}
Expand Down
3 changes: 0 additions & 3 deletions src/structures/UserAppTypeTreeItemView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ import type UserAppTreeItem from "./UserAppTreeItem";
export default class AppTypeTreeItemView extends BaseTreeItem<UserAppTreeItem> {
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) {
Expand Down
4 changes: 2 additions & 2 deletions src/structures/UserChildTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export default class UserChildTreeItem extends BaseChildTreeItem {

readonly userID: string;

_patch(data: Partial<UserTreeItemData>) {
if (!data) return this;
protected _patch(data: Partial<UserTreeItemData>) {
if (data == null) return this;

super._patch(data);

Expand Down
3 changes: 2 additions & 1 deletion src/structures/UserTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class UserTreeItem extends BaseTreeItem<UserChildTreeItem> {
readonly userID: string;

protected _patch(data: Partial<UserTreeItemData & ApiVscodeUser>): this {
if (!data) return this;
if (data == null) return this;

if (data.avatar)
try { this.iconPath = Uri.parse(data.avatar); } catch { }
Expand Down Expand Up @@ -106,6 +106,7 @@ export default class UserTreeItem extends BaseTreeItem<UserChildTreeItem> {
const existing = this.children.get(id);

if (existing) {
// @ts-expect-error ts(2445)
existing._patch(data);
return;
}
Expand Down
Loading