diff --git a/src/sql/parts/query/editor/queryResultsView.ts b/src/sql/parts/query/editor/queryResultsView.ts index 648e946893..4d898dc62b 100644 --- a/src/sql/parts/query/editor/queryResultsView.ts +++ b/src/sql/parts/query/editor/queryResultsView.ts @@ -200,18 +200,10 @@ export class QueryResultsView extends Disposable { public style() { } - public set input(input: QueryResultsInput) { - this._input = input; - dispose(this.runnerDisposables); - this.runnerDisposables = []; - this.resultsTab.view.state = this.input.state; - this.qpTab.view.state = this.input.state.queryPlanState; - this.topOperationsTab.view.state = this.input.state.topOperationsState; - this.chartTab.view.state = this.input.state.chartState; - let queryRunner = this.queryModelService._getQueryInfo(input.uri).queryRunner; - this.resultsTab.queryRunner = queryRunner; - this.chartTab.queryRunner = queryRunner; - this.runnerDisposables.push(queryRunner.onQueryStart(e => { + private setQueryRunner(runner: QueryRunner) { + this.resultsTab.queryRunner = runner; + this.chartTab.queryRunner = runner; + this.runnerDisposables.push(runner.onQueryStart(e => { this.hideChart(); this.hidePlan(); this.input.state.visibleTabs = new Set(); @@ -232,9 +224,9 @@ export class QueryResultsView extends Disposable { this._panelView.pushTab(this.topOperationsTab); } } - this.runnerDisposables.push(queryRunner.onQueryEnd(() => { - if (queryRunner.isQueryPlan) { - queryRunner.planXml.then(e => { + this.runnerDisposables.push(runner.onQueryEnd(() => { + if (runner.isQueryPlan) { + runner.planXml.then(e => { this.showPlan(e); }); } @@ -244,6 +236,29 @@ export class QueryResultsView extends Disposable { } } + public set input(input: QueryResultsInput) { + this._input = input; + dispose(this.runnerDisposables); + this.runnerDisposables = []; + this.resultsTab.view.state = this.input.state; + this.qpTab.view.state = this.input.state.queryPlanState; + this.topOperationsTab.view.state = this.input.state.topOperationsState; + this.chartTab.view.state = this.input.state.chartState; + + let info = this.queryModelService._getQueryInfo(input.uri); + if (info) { + this.setQueryRunner(info.queryRunner); + } else { + let disposeable = this.queryModelService.onRunQueryStart(c => { + if (c === input.uri) { + let info = this.queryModelService._getQueryInfo(input.uri); + this.setQueryRunner(info.queryRunner); + disposeable.dispose(); + } + }); + } + } + clearInput() { this._input = undefined; this.resultsTab.clear();