From d22689ca7153fe0469750af3a6971bac6383e2ba Mon Sep 17 00:00:00 2001 From: Wes McKinney Date: Tue, 20 Feb 2024 17:13:09 -0600 Subject: [PATCH 1/2] Add frontend change RPCs Update submodule update submodule Revert submodule --- .../comms/data_explorer-backend-openrpc.json | 7 ---- .../comms/data_explorer-frontend-openrpc.json | 29 ++++++++++++++ .../classes/dataGridInstance.ts | 4 +- .../languageRuntimeDataExplorerClient.ts | 36 ++++++++++++++++-- .../common/positronDataExplorerComm.ts | 38 ++++++++++++++++++- .../browser/tableDataDataGridInstance.tsx | 38 +++++++++++++++---- 6 files changed, 129 insertions(+), 23 deletions(-) create mode 100644 positron/comms/data_explorer-frontend-openrpc.json diff --git a/positron/comms/data_explorer-backend-openrpc.json b/positron/comms/data_explorer-backend-openrpc.json index d67fed8bd3c..946eed0a64d 100644 --- a/positron/comms/data_explorer-backend-openrpc.json +++ b/positron/comms/data_explorer-backend-openrpc.json @@ -374,13 +374,6 @@ } } }, - "column_formatted_data": { - "type": "array", - "description": "Column values formatted as strings", - "items": { - "type": "string" - } - }, "column_filter": { "type": "object", "description": "Specifies a table row filter based on a column's values", diff --git a/positron/comms/data_explorer-frontend-openrpc.json b/positron/comms/data_explorer-frontend-openrpc.json new file mode 100644 index 00000000000..a73a97241bf --- /dev/null +++ b/positron/comms/data_explorer-frontend-openrpc.json @@ -0,0 +1,29 @@ +{ + "openrpc": "1.3.0", + "info": { + "title": "Data Explorer Frontend", + "version": "1.0.0" + }, + "methods": [ + { + "name": "schema_update", + "summary": "Reset after a schema change", + "description": "Fully reset and redraw the data explorer after a schema change.", + "params": [ + { + "name": "discard_state", + "description": "If true, the UI should discard the filter/sort state.", + "schema": { + "type": "boolean" + } + } + ] + }, + { + "name": "data_update", + "summary": "Clear cache and request fresh data", + "description": "Triggered when there is any data change detected, clearing cache data and triggering a refresh/redraw.", + "params": [] + } + ] +} diff --git a/src/vs/base/browser/ui/positronDataGrid/classes/dataGridInstance.ts b/src/vs/base/browser/ui/positronDataGrid/classes/dataGridInstance.ts index 1871ecfbc40..a15c7c57d96 100644 --- a/src/vs/base/browser/ui/positronDataGrid/classes/dataGridInstance.ts +++ b/src/vs/base/browser/ui/positronDataGrid/classes/dataGridInstance.ts @@ -373,12 +373,12 @@ export abstract class DataGridInstance extends Disposable { /** * Gets or sets the first column index. */ - private _firstColumnIndex = 0; + protected _firstColumnIndex = 0; /** * Gets or sets the first row index. */ - private _firstRowIndex = 0; + protected _firstRowIndex = 0; /** * Gets or sets the cursor column index. diff --git a/src/vs/workbench/services/languageRuntime/common/languageRuntimeDataExplorerClient.ts b/src/vs/workbench/services/languageRuntime/common/languageRuntimeDataExplorerClient.ts index 6aaebfdb59a..6db8d8f5fe0 100644 --- a/src/vs/workbench/services/languageRuntime/common/languageRuntimeDataExplorerClient.ts +++ b/src/vs/workbench/services/languageRuntime/common/languageRuntimeDataExplorerClient.ts @@ -2,11 +2,11 @@ * Copyright (C) 2023-2024 Posit Software, PBC. All rights reserved. *--------------------------------------------------------------------------------------------*/ -import { Event } from 'vs/base/common/event'; +import { Emitter, Event } from 'vs/base/common/event'; import { Disposable } from 'vs/base/common/lifecycle'; import { generateUuid } from 'vs/base/common/uuid'; import { IRuntimeClientInstance } from 'vs/workbench/services/languageRuntime/common/languageRuntimeClientInstance'; -import { ColumnSortKey, PositronDataExplorerComm, TableData, TableSchema } from 'vs/workbench/services/languageRuntime/common/positronDataExplorerComm'; +import { ColumnSortKey, PositronDataExplorerComm, SchemaUpdateEvent, TableData, TableSchema } from 'vs/workbench/services/languageRuntime/common/positronDataExplorerComm'; /** * A data explorer client instance. @@ -40,8 +40,22 @@ export class DataExplorerClientInstance extends Disposable { this._positronDataExplorerComm = new PositronDataExplorerComm(client); this._register(this._positronDataExplorerComm); - // Setup events. + // Close emitter this.onDidClose = this._positronDataExplorerComm.onDidClose; + + // Connect schema update emitter + this.onDidSchemaUpdate = this._schemaUpdateEmitter.event; + + // Connect data update emitter + this.onDidDataUpdate = this._dataUpdateEmitter.event; + + this._positronDataExplorerComm.onDidSchemaUpdate(async (e: SchemaUpdateEvent) => { + this._schemaUpdateEmitter.fire(e); + }); + + this._positronDataExplorerComm.onDidDataUpdate(async (_evt) => { + this._dataUpdateEmitter.fire(); + }); } //#endregion Constructor & Dispose @@ -95,10 +109,24 @@ export class DataExplorerClientInstance extends Disposable { //#region Public Events + /** - * The onDidClose event. + * Event that fires when the data explorer is closed on the runtime side, as a result of + * a dataset being deallocated or overwritten with a non-dataset. */ onDidClose: Event; + /** + * Event that fires when the schema has been updated. + */ + onDidSchemaUpdate: Event; + private readonly _schemaUpdateEmitter = new Emitter(); + + /** + * Event that fires when the data has been updated. + */ + onDidDataUpdate: Event; + private readonly _dataUpdateEmitter = new Emitter(); + //#endregion Public Events } diff --git a/src/vs/workbench/services/languageRuntime/common/positronDataExplorerComm.ts b/src/vs/workbench/services/languageRuntime/common/positronDataExplorerComm.ts index 04d0d19edf4..b663716ab01 100644 --- a/src/vs/workbench/services/languageRuntime/common/positronDataExplorerComm.ts +++ b/src/vs/workbench/services/languageRuntime/common/positronDataExplorerComm.ts @@ -6,6 +6,7 @@ // AUTO-GENERATED from data_explorer.json; do not edit. // +import { Event } from 'vs/base/common/event'; import { PositronBaseComm } from 'vs/workbench/services/languageRuntime/common/positronBaseComm'; import { IRuntimeClientInstance } from 'vs/workbench/services/languageRuntime/common/languageRuntimeClientInstance'; @@ -342,13 +343,32 @@ export enum ColumnFilterSearchType { } /** - * Column values formatted as strings + * Event: Reset after a schema change */ -export type ColumnFormattedData = Array; +export interface SchemaUpdateEvent { + /** + * If true, the UI should discard the filter/sort state. + */ + discard_state: boolean; + +} + +/** + * Event: Clear cache and request fresh data + */ +export interface DataUpdateEvent { +} + +export enum DataExplorerFrontendEvent { + SchemaUpdate = 'schema_update', + DataUpdate = 'data_update' +} export class PositronDataExplorerComm extends PositronBaseComm { constructor(instance: IRuntimeClientInstance) { super(instance); + this.onDidSchemaUpdate = super.createEventEmitter('schema_update', ['discard_state']); + this.onDidDataUpdate = super.createEventEmitter('data_update', []); } /** @@ -436,5 +456,19 @@ export class PositronDataExplorerComm extends PositronBaseComm { return super.performRpc('get_state', [], []); } + + /** + * Reset after a schema change + * + * Fully reset and redraw the data explorer after a schema change. + */ + onDidSchemaUpdate: Event; + /** + * Clear cache and request fresh data + * + * Triggered when there is any data change detected, clearing cache data + * and triggering a refresh/redraw. + */ + onDidDataUpdate: Event; } diff --git a/src/vs/workbench/services/positronDataExplorer/browser/tableDataDataGridInstance.tsx b/src/vs/workbench/services/positronDataExplorer/browser/tableDataDataGridInstance.tsx index c97b90def76..198e7ea9c9d 100644 --- a/src/vs/workbench/services/positronDataExplorer/browser/tableDataDataGridInstance.tsx +++ b/src/vs/workbench/services/positronDataExplorer/browser/tableDataDataGridInstance.tsx @@ -12,7 +12,7 @@ import { TableDataCell } from 'vs/workbench/services/positronDataExplorer/browse import { TableDataRowHeader } from 'vs/workbench/services/positronDataExplorer/browser/components/tableDataRowHeader'; import { PositronDataExplorerColumn } from 'vs/workbench/services/positronDataExplorer/browser/positronDataExplorerColumn'; import { DataExplorerClientInstance } from 'vs/workbench/services/languageRuntime/common/languageRuntimeDataExplorerClient'; -import { ColumnSortKey } from 'vs/workbench/services/languageRuntime/common/positronDataExplorerComm'; +import { ColumnSortKey, SchemaUpdateEvent } from 'vs/workbench/services/languageRuntime/common/positronDataExplorerComm'; import { DataFetchRange, FetchedData, @@ -36,7 +36,7 @@ export class TableDataDataGridInstance extends DataGridInstance { private _dataCache?: TableDataCache; private _lastFetchedData?: FetchedData; - private _schemaCache?: TableSchemaCache; + private _schemaCache: TableSchemaCache; private _lastFetchedSchema?: FetchedSchema; //#endregion Private Properties @@ -72,8 +72,35 @@ export class TableDataDataGridInstance extends DataGridInstance { cellBorder: true }); + this._schemaCache = new TableSchemaCache( + async (req: SchemaFetchRange) => { + return this._dataExplorerClientInstance.getSchema(req.startIndex, + req.endIndex - req.startIndex); + } + ); + // Set the data explorer client instance. this._dataExplorerClientInstance = dataExplorerClientInstance; + + this._dataExplorerClientInstance.onDidSchemaUpdate(async (e: SchemaUpdateEvent) => { + this._lastFetchedData = undefined; + this._lastFetchedSchema = undefined; + + // Reset cursor to top left + // TODO: These attributes were made protected to allow this. Add a method to + // reset these without firing an update request which we don't want here yet. + this._firstColumnIndex = 0; + this._firstRowIndex = 0; + + // Resets data schema, fetches initial schema and data + this.initialize(); + }); + + this._dataExplorerClientInstance.onDidDataUpdate(async (_evt) => { + this._lastFetchedData = undefined; + this._dataCache?.clear(); + this.fetchData(); + }); } //#endregion Constructor @@ -96,12 +123,7 @@ export class TableDataDataGridInstance extends DataGridInstance { * */ initialize() { - this._schemaCache = new TableSchemaCache( - async (req: SchemaFetchRange) => { - return this._dataExplorerClientInstance.getSchema(req.startIndex, - req.endIndex - req.startIndex); - } - ); + this._schemaCache.clear(); this._schemaCache.initialize().then(async (_) => { this._lastFetchedSchema = await this._schemaCache?.fetch({ startIndex: 0, endIndex: 1000 }); From f3156c5e09266bae81becfb83c00568bebdf987e Mon Sep 17 00:00:00 2001 From: Wes McKinney Date: Tue, 27 Feb 2024 13:41:21 -0600 Subject: [PATCH 2/2] update submodule --- extensions/positron-python | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/positron-python b/extensions/positron-python index d819465dea7..2dbe6c88835 160000 --- a/extensions/positron-python +++ b/extensions/positron-python @@ -1 +1 @@ -Subproject commit d819465dea75f297971019ea7a2085a9354c8fef +Subproject commit 2dbe6c888358b3fc53107a8f0b2ab72815edc638