Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/controllers/mainController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,7 @@ export default class MainController implements vscode.Disposable {
}

let editor = self._vscodeWrapper.activeTextEditor;
let uri = self._vscodeWrapper.activeTextEditorUri;
let editorInstanceKey = self._vscodeWrapper.activeTextEditorInstanceKey;
let title = path.basename(editor.document.fileName);

// return early if the document does contain any text
Expand All @@ -2334,9 +2334,10 @@ export default class MainController implements vscode.Disposable {
endColumn: 0,
};

// Run query using editor instance key so each editor has its own execution context
await self._outputContentProvider.runCurrentStatement(
self._statusview,
uri,
editorInstanceKey,
querySelection,
title,
);
Expand All @@ -2361,6 +2362,7 @@ export default class MainController implements vscode.Disposable {

let editor = this._vscodeWrapper.activeTextEditor;
let uri = this._vscodeWrapper.activeTextEditorUri;
let editorInstanceKey = this._vscodeWrapper.activeTextEditorInstanceKey;

// Do not execute when there are multiple selections in the editor until it can be properly handled.
// Otherwise only the first selection will be executed and cause unexpected issues.
Expand Down Expand Up @@ -2392,7 +2394,7 @@ export default class MainController implements vscode.Disposable {
};
}

// create new connection
// create new connection - connections are shared per document URI
if (!this.connectionManager.isConnected(uri)) {
await this.onNewConnection();
sendActionEvent(TelemetryViews.QueryEditor, TelemetryActions.CreateConnection);
Expand All @@ -2401,11 +2403,12 @@ export default class MainController implements vscode.Disposable {
await this._connectionMgr.refreshAzureAccountToken(uri);

// Delete stored filters and dimension states for result grid when a new query is executed
store.deleteUriState(uri);
store.deleteUriState(editorInstanceKey);

// Run query using editor instance key so each editor has its own execution context
await this._outputContentProvider.runQuery(
this._statusview,
uri,
editorInstanceKey,
querySelection,
title,
executionPlanOptions,
Expand Down
26 changes: 20 additions & 6 deletions src/controllers/queryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export default class QueryRunner {
private _client?: SqlToolsServerClient,
private _notificationHandler?: QueryNotificationHandler,
private _vscodeWrapper?: VscodeWrapper,
private _editorInstanceKey?: string,
) {
if (!_client) {
this._client = SqlToolsServerClient.instance;
Expand All @@ -169,6 +170,11 @@ export default class QueryRunner {
this._vscodeWrapper = new VscodeWrapper();
}

// If no editor instance key provided, use the owner URI
if (!_editorInstanceKey) {
this._editorInstanceKey = _ownerUri;
}

// Store the state
this._isExecuting = false;
this._totalElapsedMilliseconds = 0;
Expand All @@ -185,6 +191,14 @@ export default class QueryRunner {
this._ownerUri = uri;
}

get editorInstanceKey(): string {
return this._editorInstanceKey;
}

set editorInstanceKey(key: string) {
this._editorInstanceKey = key;
}

get title(): string {
return this._editorTitle;
}
Expand Down Expand Up @@ -352,7 +366,7 @@ export default class QueryRunner {
this._isExecuting = true;
this._totalElapsedMilliseconds = 0;
// Update the status view to show that we're executing
this._statusView.executingQuery(this.uri);
this._statusView.executingQuery(this._editorInstanceKey);

QueryRunner.addRunningQuery(this._ownerUri);

Expand Down Expand Up @@ -383,9 +397,9 @@ export default class QueryRunner {
promise.resolve();
this._uriToQueryPromiseMap.delete(result.ownerUri);
}
this._statusView.executedQuery(result.ownerUri);
this._statusView.executedQuery(this._editorInstanceKey);
this._statusView.setExecutionTime(
result.ownerUri,
this._editorInstanceKey,
Utils.parseNumAsTimeString(this._totalElapsedMilliseconds),
);
let hasError = this._batchSets.some((batch) => batch.hasError === true);
Expand Down Expand Up @@ -495,9 +509,9 @@ export default class QueryRunner {

// Set row count on status bar if there are no errors
if (!obj.message.isError) {
this._statusView.showRowCount(obj.ownerUri, obj.message.message);
this._statusView.showRowCount(this._editorInstanceKey, obj.message.message);
} else {
this._statusView.hideRowCount(obj.ownerUri, true);
this._statusView.hideRowCount(this._editorInstanceKey, true);
}
}

Expand Down Expand Up @@ -542,7 +556,7 @@ export default class QueryRunner {
totalMilliseconds: Utils.parseNumAsTimeString(this._totalElapsedMilliseconds),
hasError: !!error,
});
this._statusView.executedQuery(this._ownerUri);
this._statusView.executedQuery(this._editorInstanceKey);

this._notificationHandler.unregisterRunner(this._ownerUri);

Expand Down
10 changes: 10 additions & 0 deletions src/controllers/vscodeWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as vscode from "vscode";
import { TextDocumentShowOptions } from "vscode";
import { AzureLoginStatus } from "../models/interfaces";
import * as Constants from "./../constants/constants";
import { getEditorInstanceKey } from "../utils/utils";

export import TextEditor = vscode.TextEditor;
export import ConfigurationTarget = vscode.ConfigurationTarget;
Expand Down Expand Up @@ -70,6 +71,15 @@ export default class VscodeWrapper {
return undefined;
}

/**
* Get the unique editor instance key for the current active text editor.
* This key includes the document URI and the view column, allowing multiple
* editors of the same document to have independent execution contexts.
*/
public get activeTextEditorInstanceKey(): string | undefined {
return getEditorInstanceKey(vscode.window.activeTextEditor);
}

/**
* Create an output channel in vscode.
*/
Expand Down
Loading