diff --git a/src/flowr/diagrams/diagram.ts b/src/flowr/diagrams/diagram.ts index 9b6b209..68c8d7e 100644 --- a/src/flowr/diagrams/diagram.ts +++ b/src/flowr/diagrams/diagram.ts @@ -68,6 +68,12 @@ class DiagramUpdateCoordinator { const options = optionsFromDiagramType(type); const mermaid = await definition.retrieve(options as never, editor); + // Don't show a panel if generation failed + if(mermaid === '') { + await vscode.window.showErrorMessage('Failed to generate diagram - FlowR Analyzer Session is not ready. Check if flowrR is connected and try again.'); + return; + } + const panel = createDiagramWebview({ mermaid: mermaid, options: options, diff --git a/src/flowr/internal-session.ts b/src/flowr/internal-session.ts index 9f7acf1..7806d0f 100644 --- a/src/flowr/internal-session.ts +++ b/src/flowr/internal-session.ts @@ -105,11 +105,28 @@ export class FlowrInternalSession implements FlowrSession { } private async startWorkWithProgressBar(document: vscode.TextDocument, actionFn: (analyzer: FlowrAnalyzer) => Promise, action: WorkActions, showErrorMessage: boolean, defaultOnErr = {} as T): Promise { + this.setWorking(true); + + // Wait for the flowr session if(!this.parser) { - return defaultOnErr; + const times = [3000, 2000, 1000]; + while(times.length !== 0) { + const timeout = times.pop(); + this.outputChannel.appendLine(`FlowR Session not available - retrying in ${timeout}ms`); + await new Promise(res => setTimeout(res, timeout)); + + if(this.parser) { + break; + } + } + + if(!this.parser) { + this.setWorking(false); + return defaultOnErr; + } } - this.setWorking(true); + const analyzer = await analyzerFromDocument(document, this.parser); // update the vscode ui