diff --git a/webview-ui/src/diagnostics_panel/DiagnosticsSchema.ts b/src/diagnostics-schema.ts similarity index 93% rename from webview-ui/src/diagnostics_panel/DiagnosticsSchema.ts rename to src/diagnostics-schema.ts index 45811aa..f888df7 100644 --- a/webview-ui/src/diagnostics_panel/DiagnosticsSchema.ts +++ b/src/diagnostics-schema.ts @@ -1,4 +1,5 @@ // Copyright (C) Microsoft Corporation. All rights reserved. + // TypeScript mirror of ScriptDiagnosticsDescriptor (C++) and its Cereal based wire format. export type DiagnosticsDataSource = 'server' | 'client' | 'server_script'; @@ -26,4 +27,5 @@ export interface DiagnosticsTabDescriptor { value_labels?: string[]; statistic_id?: string; statistic_ids?: string[]; + is_empty_tab?: boolean; } diff --git a/src/panels/minecraft-diagnostics.ts b/src/panels/minecraft-diagnostics.ts index 64d704c..b680d19 100644 --- a/src/panels/minecraft-diagnostics.ts +++ b/src/panels/minecraft-diagnostics.ts @@ -5,7 +5,8 @@ import { EventEmitter } from 'stream'; import { getUri } from '../utilities/getUri'; import { getNonce } from '../utilities/getNonce'; import { DebuggerRequestHandler } from '../requests/debugger-request-handler'; -import { DiagnosticsTabDescriptor, StatData, StatsListener, StatsProvider } from '../stats/stats-provider'; +import { StatData, StatsListener, StatsProvider } from '../stats/stats-provider'; +import { DiagnosticsTabDescriptor } from '../diagnostics-schema'; export class MinecraftDiagnosticsPanel { private static activeDiagnosticsPanels: MinecraftDiagnosticsPanel[] = []; diff --git a/src/protocol-events.ts b/src/protocol-events.ts index 8a1d113..b56f24f 100644 --- a/src/protocol-events.ts +++ b/src/protocol-events.ts @@ -2,7 +2,8 @@ import { LogLevel } from '@vscode/debugadapter/lib/logger'; import { DebugProtocol } from '@vscode/debugprotocol'; -import { DiagnosticsTabDescriptor, StatMessageModel } from './stats/stats-provider'; +import { StatMessageModel } from './stats/stats-provider'; +import { DiagnosticsTabDescriptor } from './diagnostics-schema'; // protocol version history // 1 - initial version @@ -14,6 +15,7 @@ import { DiagnosticsTabDescriptor, StatMessageModel } from './stats/stats-provid // 7 - support for debugger requests, MC can reject or respond with args // 8 - New serialization tech (use Cereal) // 9 - Added support for MC C++/native driven stat descriptors/schemas for UI display +// 10 - Added is_empty_tab to DiagnosticsTabDescriptor export enum ProtocolVersion { _Unknown = 0, @@ -26,9 +28,10 @@ export enum ProtocolVersion { SupportDebuggerRequests = 7, SupportCerealSerialization = 8, SupportNativeDescriptors = 9, + SupportEmptyTabs = 10, } -export const DEBUGGER_PROTOCOL_VERSION = ProtocolVersion.SupportNativeDescriptors; +export const DEBUGGER_PROTOCOL_VERSION = ProtocolVersion.SupportEmptyTabs; // ------------------------------------------------------------------------- // Interfaces for event message payloads (received from the debugee) diff --git a/src/session.ts b/src/session.ts index 9812c0f..3310538 100644 --- a/src/session.ts +++ b/src/session.ts @@ -385,7 +385,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender { args: IAttachRequestArguments, ): Promise { this.closeSession(); - + this._statsProvider.clearSchema(); this.resolveEnvironmentVariables(args); const host = args.host || 'localhost'; @@ -878,6 +878,7 @@ export class Session extends DebugSession implements IDebuggeeMessageSender { private terminateSession(reason: string, logLevel: LogLevel = LogLevel.Log) { this.closeServer(); this.closeSession(); + this._statsProvider.clearSchema(); this._connected = false; this._clientProtocolVersion = ProtocolVersion._Unknown; diff --git a/src/stats/stats-provider.ts b/src/stats/stats-provider.ts index 613f862..ab0a6fc 100644 --- a/src/stats/stats-provider.ts +++ b/src/stats/stats-provider.ts @@ -1,5 +1,7 @@ // Copyright (C) Microsoft Corporation. All rights reserved. +import { DiagnosticsTabDescriptor } from "../diagnostics-schema"; + export interface StatData { name: string; parent_name: string; @@ -26,33 +28,6 @@ export interface StatMessageModel { stats: StatDataModel[]; } -export type DiagnosticsDataSource = 'server' | 'client' | 'server_script'; - -export type DiagnosticsDisplayType = - | 'line_chart' - | 'stacked_line_chart' - | 'stacked_bar_chart' - | 'table' - | 'multi_column_table' - | 'dynamic_properties_table'; - -// Mirrors ScriptDiagnosticsDescriptor from C++. Sent once on connect via SchemaEvent. -export interface DiagnosticsTabDescriptor { - name: string; - stat_group_id: string; - data_source: DiagnosticsDataSource; - display_type: DiagnosticsDisplayType; - title?: string; - y_label?: string; - tick_range?: number; - value_scalar?: number; - target_value?: number; - key_label?: string; - value_labels?: string[]; - statistic_id?: string; - statistic_ids?: string[]; -} - export interface StatsListener { onStatUpdated?: (stat: StatData) => void; onSpeedUpdated?: (speed: number) => void; @@ -83,6 +58,10 @@ export class StatsProvider { }); } + public clearSchema(): void { + this.setSchema([]); + } + public start(): void { throw new Error('Method not implemented.'); } @@ -164,7 +143,7 @@ export class StatsProvider { } private _fireStatUpdated(stat: StatDataModel, tick: number, parent?: StatData) { - const statId = stat.name.toLowerCase(); + const statId = stat.name; const statData: StatData = { ...stat, diff --git a/webview-ui/src/diagnostics_panel/App.tsx b/webview-ui/src/diagnostics_panel/App.tsx index 127bed9..eaa23ac 100644 --- a/webview-ui/src/diagnostics_panel/App.tsx +++ b/webview-ui/src/diagnostics_panel/App.tsx @@ -9,8 +9,8 @@ import tabPrefabs from './prefabs'; import { TabPrefab, TabPrefabDataSource, TabPrefabParams } from './prefabs/TabPrefab'; import { handleDebuggerRequestResult } from './utilities/useDebuggerRequests'; import { vscode } from './utilities/vscode'; -import { DiagnosticsTabDescriptor } from './DiagnosticsSchema'; import DynamicTab from './DynamicTab'; +import { DiagnosticsTabDescriptor } from '../../../src/diagnostics-schema'; // Wraps each tab's content() as a proper React component so that any hooks // inside the content function are correctly isolated and not called conditionally @@ -175,7 +175,7 @@ function App() { )} - ) : ( + ) : (!tab.descriptor.is_empty_tab && ( <> {tab.descriptor.data_source === 'client' && ( - )} + ))} ))} diff --git a/webview-ui/src/diagnostics_panel/DynamicTab.tsx b/webview-ui/src/diagnostics_panel/DynamicTab.tsx index 3f3bfec..b1736d2 100644 --- a/webview-ui/src/diagnostics_panel/DynamicTab.tsx +++ b/webview-ui/src/diagnostics_panel/DynamicTab.tsx @@ -5,7 +5,6 @@ // and renders the matching control — no new tab files needed for new diagnostics. import { useMemo } from 'react'; -import { DiagnosticsTabDescriptor } from './DiagnosticsSchema'; import { SimpleStatisticProvider, MultipleStatisticProvider, @@ -18,6 +17,7 @@ import MinecraftStatisticStackedBarChart from './controls/MinecraftStatisticStac import MinecraftStatisticTable from './controls/MinecraftStatisticTable'; import MinecraftMultiColumnStatisticTable from './controls/MinecraftMultiColumnStatisticTable'; import { MinecraftDynamicPropertiesTable } from './controls/MinecraftDynamicPropertiesTable'; +import { DiagnosticsTabDescriptor } from '../../../src/diagnostics-schema'; type DynamicTabProps = { descriptor: DiagnosticsTabDescriptor;