diff --git a/sema4ai/vscode-client/src/robo/dataSourceHandling.ts b/sema4ai/vscode-client/src/robo/dataSourceHandling.ts index 77829bef..c72cc390 100644 --- a/sema4ai/vscode-client/src/robo/dataSourceHandling.ts +++ b/sema4ai/vscode-client/src/robo/dataSourceHandling.ts @@ -1,6 +1,6 @@ import { Uri, window, commands, ProgressLocation, Progress, CancellationToken } from "vscode"; import { logError, OUTPUT_CHANNEL } from "../channel"; -import { RobotEntry } from "../viewsCommon"; +import { RobotEntry, treeViewIdToTreeDataProvider } from "../viewsCommon"; import { DatasourceInfo, DataSourceState } from "../protocols"; import { langServer } from "../extension"; import { @@ -13,6 +13,8 @@ import { sleep } from "../time"; import { findActionPackagePath } from "../actionServer"; import { SEMA4AI_LIST_ACTIONS_INTERNAL } from "../robocorpCommands"; import { QuickPickItemWithAction, showSelectOneQuickPick } from "../ask"; +import { TREE_VIEW_SEMA4AI_TASK_PACKAGES_TREE } from "../robocorpViews"; +import { RobotsTreeDataProvider } from "../viewsRobots"; function isExternalDatasource(datasource: DatasourceInfo): boolean { const externalEngines = ["custom", "files", "models"]; @@ -253,6 +255,11 @@ export const setupDataSource = async (entry?: RobotEntry) => { } await setupSingleDataSource(datasource, dataServerInfo, Uri.file(entry.robot.directory).toString()); + + const dataProvider = treeViewIdToTreeDataProvider.get( + TREE_VIEW_SEMA4AI_TASK_PACKAGES_TREE + ) as RobotsTreeDataProvider; + dataProvider.updateDatasourceStatuses(); }; export async function dropDataSource(entry?: RobotEntry) { @@ -333,6 +340,11 @@ export async function dropDataSource(entry?: RobotEntry) { return; } + const dataProvider = treeViewIdToTreeDataProvider.get( + TREE_VIEW_SEMA4AI_TASK_PACKAGES_TREE + ) as RobotsTreeDataProvider; + dataProvider.updateDatasourceStatuses(); + window.showInformationMessage(result["message"]); } @@ -420,6 +432,11 @@ export async function dropAllDataSources(entry?: RobotEntry) { window.showInformationMessage("Data Sources dropped succesfully."); } ); + + const dataProvider = treeViewIdToTreeDataProvider.get( + TREE_VIEW_SEMA4AI_TASK_PACKAGES_TREE + ) as RobotsTreeDataProvider; + dataProvider.updateDatasourceStatuses(); } export async function setupAllDataSources(entry?: RobotEntry) { @@ -512,4 +529,9 @@ export async function setupAllDataSources(entry?: RobotEntry) { } } ); + + const dataProvider = treeViewIdToTreeDataProvider.get( + TREE_VIEW_SEMA4AI_TASK_PACKAGES_TREE + ) as RobotsTreeDataProvider; + dataProvider.updateDatasourceStatuses(); } diff --git a/sema4ai/vscode-client/src/views.ts b/sema4ai/vscode-client/src/views.ts index 111f6345..4b52f2ef 100644 --- a/sema4ai/vscode-client/src/views.ts +++ b/sema4ai/vscode-client/src/views.ts @@ -232,11 +232,6 @@ export function registerViews(context: ExtensionContext) { "treeDataProvider": robotsTreeDataProvider, }); - // Periodic refresh every 60 seconds - setInterval(() => { - robotsTreeDataProvider.updateDatasourceStatuses(); - }, 5 * 1000); - treeViewIdToTreeView.set(TREE_VIEW_SEMA4AI_TASK_PACKAGES_TREE, robotsTree); treeViewIdToTreeDataProvider.set(TREE_VIEW_SEMA4AI_TASK_PACKAGES_TREE, robotsTreeDataProvider); diff --git a/sema4ai/vscode-client/src/viewsRobots.ts b/sema4ai/vscode-client/src/viewsRobots.ts index 7dd2f665..8b13fbd1 100644 --- a/sema4ai/vscode-client/src/viewsRobots.ts +++ b/sema4ai/vscode-client/src/viewsRobots.ts @@ -16,6 +16,37 @@ function empty(array: T[]) { return array === undefined || array.length === 0; } +function dataSourcesAreDifferent( + globalDataSourceState: Map>, + currentDatasources: Map> +): boolean { + if (globalDataSourceState.size !== currentDatasources.size) { + return true; + } + + for (const [actionPath, currentInnerMap] of currentDatasources) { + const globalInnerMap = globalDataSourceState.get(actionPath); + + if (!globalInnerMap) { + return true; + } + + if (globalInnerMap.size !== currentInnerMap.size) { + return true; + } + + for (const [sourceName, currentInfo] of currentInnerMap) { + const globalInfo = globalInnerMap.get(sourceName); + + if (!globalInfo || JSON.stringify(currentInfo) !== JSON.stringify(globalInfo)) { + return true; + } + } + } + + return false; +} + function getRobotLabel(robotInfo: LocalPackageMetadataInfo): string { let label: string = undefined; if (robotInfo.yamlContents) { @@ -69,7 +100,7 @@ export class RobotsTreeDataProvider implements vscode.TreeDataProvider> = new Map(); for (const actionPackage of localActionPackages) { const dataSourceStateResult = (await langServer.sendRequest("computeDataSourceState", { @@ -80,15 +111,18 @@ export class RobotsTreeDataProvider implements vscode.TreeDataProvider 0 && dataSourcesAreDifferent(this.globalDataSourceState, currentDatasources)) { + this.globalDataSourceState = currentDatasources; + this.fireRootChange(); + } } /** @@ -132,6 +166,7 @@ export class RobotsTreeDataProvider implements vscode.TreeDataProvider