diff --git a/firebase-vscode/CHANGELOG.md b/firebase-vscode/CHANGELOG.md index dd3ed825a44..74a4e82a9ed 100644 --- a/firebase-vscode/CHANGELOG.md +++ b/firebase-vscode/CHANGELOG.md @@ -1,5 +1,8 @@ ## NEXT +- [Fixed] Data Connect emulator issues properly streamed on startup +- [Fixed] Data Connect schema reloads consistently + ## 0.4.0 - Updated internal firebase-tools dependency to 13.13.0 diff --git a/firebase-vscode/src/data-connect/emulator-stream.ts b/firebase-vscode/src/data-connect/emulator-stream.ts index 840bf8ea106..aaba3180d37 100644 --- a/firebase-vscode/src/data-connect/emulator-stream.ts +++ b/firebase-vscode/src/data-connect/emulator-stream.ts @@ -10,6 +10,7 @@ enum Kind { SQL_CONNECTION = "SQL_CONNECTION", SQL_MIGRATION = "SQL_MIGRATION", VERTEX_AI = "VERTEX_AI", + FILE_RELOAD = "FILE_RELOAD", } enum Severity { SEVERITY_UNSPECIFIED = "SEVERITY_UNSPECIFIED", @@ -36,13 +37,15 @@ export async function runEmulatorIssuesStream( configs: ResolvedDataConnectConfigs, fdcEndpoint: string, isPostgresEnabled: Signal, + schemaReloadFunc: () => void, ) { const obsErrors = await getEmulatorIssuesStream(configs, fdcEndpoint); const obsConverter = { next(nextResponse: EmulatorIssueResponse) { if (nextResponse.result?.issues?.length) { for (const issue of nextResponse.result.issues) { - displayAndHandleIssue(issue, isPostgresEnabled); + console.log("HAROLD: ", issue) + displayAndHandleIssue(issue, isPostgresEnabled, schemaReloadFunc); } } }, @@ -59,12 +62,14 @@ export async function runEmulatorIssuesStream( /** * Based on the severity of the issue, either log, display notification, or display interactive popup to the user */ -export function displayAndHandleIssue(issue: EmulatorIssue, isPostgresEnabled: Signal) { +export function displayAndHandleIssue( + issue: EmulatorIssue, + isPostgresEnabled: Signal, + schemaReloadFunc: () => void, +) { const issueMessage = `Data Connect Emulator: ${issue.kind.toString()} - ${issue.message}`; if (issue.severity === Severity.ALERT) { vscode.window.showErrorMessage(issueMessage); - } else if (issue.severity === Severity.NOTICE) { - vscode.window.showWarningMessage(issueMessage); } emulatorOutputChannel.appendLine(issueMessage); @@ -72,6 +77,9 @@ export function displayAndHandleIssue(issue: EmulatorIssue, isPostgresEnabled: S if (issue.kind === Kind.SQL_CONNECTION) { isPostgresEnabled.value = false; } + if (issue.kind === Kind.FILE_RELOAD) { + schemaReloadFunc(); + } } /** diff --git a/firebase-vscode/src/data-connect/emulator.ts b/firebase-vscode/src/data-connect/emulator.ts index 69f30a30406..2e1dbad0b61 100644 --- a/firebase-vscode/src/data-connect/emulator.ts +++ b/firebase-vscode/src/data-connect/emulator.ts @@ -12,8 +12,6 @@ import { dataConnectConfigs } from "./config"; import { runEmulatorIssuesStream } from "./emulator-stream"; import { runDataConnectCompiler } from "./core-compiler"; import { pluginLogger } from "../logger-wrapper"; -import { Emulators, getEmulatorDetails, listRunningEmulators } from "../cli"; -import { emulatorOutputChannel } from "./emulator-stream"; /** FDC-specific emulator logic */ export class DataConnectEmulatorController implements vscode.Disposable { @@ -27,14 +25,19 @@ export class DataConnectEmulatorController implements vscode.Disposable { // on emulator restart, re-connect dataConnectEmulatorEvents.on("restart", () => { - pluginLogger.log("Emulator started"); + pluginLogger.log("Emulator restarted"); this.isPostgresEnabled.value = false; this.connectToEmulator(); }); this.subs.push( broker.on("connectToPostgres", () => this.connectToPostgres()), - + // TODO: This is assuming only dataconnect emulator will run + effect(() => { + if (this.emulatorsController.emulators.value.status === "running") { + this.connectToEmulator(); + } + }), // Notify webviews when the emulator status changes effect(() => { if (this.isPostgresEnabled.value) { @@ -119,47 +122,18 @@ export class DataConnectEmulatorController implements vscode.Disposable { // Commands to run after the emulator is started successfully private async connectToEmulator() { - this.schemaReload(); const configs = dataConnectConfigs.value?.tryReadValue; runEmulatorIssuesStream( configs, this.emulatorsController.getLocalEndpoint().value, this.isPostgresEnabled, + this.schemaReload, ); runDataConnectCompiler( configs, this.emulatorsController.getLocalEndpoint().value, ); - - this.setupOutputChannel(); - } - - private setupOutputChannel() { - if ( - listRunningEmulators().filter((emulatorInfos) => { - emulatorInfos.name === Emulators.DATACONNECT; - }) - ) { - const dataConnectEmulatorDetails = getEmulatorDetails( - Emulators.DATACONNECT, - ); - - // Child process is only available when emulator is started through vscode - if (dataConnectEmulatorDetails.instance) { - dataConnectEmulatorDetails.instance.stdout?.on("data", (data) => { - emulatorOutputChannel.appendLine("DEBUG: " + data.toString()); - }); - // TODO: Utilize streaming api to iniate schema reloads - dataConnectEmulatorDetails.instance.stderr?.on("data", (data) => { - if (data.toString().includes("Finished reloading")) { - this.schemaReload(); - } else { - emulatorOutputChannel.appendLine("ERROR: " + data.toString()); - } - }); - } - } } dispose() {