Skip to content
Merged
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
2 changes: 0 additions & 2 deletions extensions/mssql/l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1986,9 +1986,7 @@
"Keep in query pane": "Keep in query pane",
"Max row count for filtering/sorting has been exceeded. To update it, navigate to User Settings and change the setting: mssql.resultsGrid.inMemoryDataProcessingThreshold": "Max row count for filtering/sorting has been exceeded. To update it, navigate to User Settings and change the setting: mssql.resultsGrid.inMemoryDataProcessingThreshold",
"New Deployment": "New Deployment",
"MSSQL: Not connected": "MSSQL: Not connected",
"MSSQL: Click to change database": "MSSQL: Click to change database",
"MSSQL: Click to connect": "MSSQL: Click to connect",
"Connection failed": "Connection failed",
"Query execution failed": "Query execution failed",
"No active notebook.": "No active notebook.",
Expand Down
2 changes: 0 additions & 2 deletions extensions/mssql/src/constants/locConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,7 @@ export let newDeployment = l10n.t("New Deployment");

export class Notebooks {
// Status bar
public static statusBarNotConnected = l10n.t("MSSQL: Not connected");
public static statusBarClickToChangeDatabase = l10n.t("MSSQL: Click to change database");
public static statusBarClickToConnect = l10n.t("MSSQL: Click to connect");

// Errors
public static connectionFailed = l10n.t("Connection failed");
Expand Down
20 changes: 20 additions & 0 deletions extensions/mssql/src/controllers/sqlDocumentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ export default class SqlDocumentService implements vscode.Disposable {
// Avoid processing events before initialization is complete
return;
}

// Notebook cells are managed by SqlNotebookController, not the
// global ConnectionManager / StatusView. Skip to avoid duplicate
// status bar items and unwanted auto-connect attempts.
if (this.isNotebookCell(doc)) {
return;
}

this._connectionMgr.onDidOpenTextDocument(doc);
const docUri = getUriKey(doc.uri);

Expand Down Expand Up @@ -374,6 +382,14 @@ export default class SqlDocumentService implements vscode.Disposable {
return;
}

// Notebook cells have their own connection status bar managed by
// SqlNotebookController. Skip StatusView updates so we don't show
// duplicate connection status bar items for both the query editor
// and the notebook.
if (this.isNotebookCell(editor.document)) {
return;
}

const activeDocumentUri = getUriKey(editor.document.uri);
const connectionInfo = this._connectionMgr?.getConnectionInfo(activeDocumentUri);

Expand Down Expand Up @@ -595,6 +611,10 @@ export default class SqlDocumentService implements vscode.Disposable {
// Update the URI in the output content provider, which will transfer query runner and webview state to the new URI
await this._outputContentProvider?.updateQueryRunnerUri(oldUri, newUri);
}

private isNotebookCell(doc: vscode.TextDocument): boolean {
return doc.uri.scheme === "vscode-notebook-cell";
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions extensions/mssql/src/notebooks/sqlNotebookController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,14 @@ export class SqlNotebookController implements vscode.Disposable {
}
const mgr = this.connections.get(notebook.uri.toString());
if (mgr?.isConnected()) {
this.statusBarItem.text = `$(database) ${mgr.getConnectionLabel()}`;
this.statusBarItem.text = `$(check) ${mgr.getConnectionLabel()}`;
this.statusBarItem.tooltip =
LocalizedConstants.Notebooks.statusBarClickToChangeDatabase;
this.statusBarItem.command = Constants.cmdNotebooksChangeDatabase;
this.statusBarItem.show();
} else {
this.statusBarItem.text = `$(database) ${LocalizedConstants.Notebooks.statusBarNotConnected}`;
this.statusBarItem.tooltip = LocalizedConstants.Notebooks.statusBarClickToConnect;
this.statusBarItem.text = `$(plug) ${LocalizedConstants.StatusBar.disconnectedLabel}`;
this.statusBarItem.tooltip = LocalizedConstants.StatusBar.notConnectedTooltip;
Comment thread
lewis-sanchez marked this conversation as resolved.
this.statusBarItem.command = Constants.cmdNotebooksChangeConnection;
this.statusBarItem.show();
}
Expand Down
32 changes: 32 additions & 0 deletions extensions/mssql/test/unit/sqlDocumentService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,14 @@ suite("SqlDocumentService Tests", () => {
expect(docUriCallback).to.equal(document.uri.toString());
});

test("onDidOpenTextDocument should skip notebook cell documents", async () => {
const notebookCellDoc = mockTextDocument("vscode-notebook-cell://notebook/cell1");

await sqlDocumentService.onDidOpenTextDocument(notebookCellDoc);

expect(connectionManager.onDidOpenTextDocument).to.not.have.been.called;
});

test("newQuery should call the new query method", async () => {
let editor: vscode.TextEditor = {
document: {
Expand Down Expand Up @@ -758,6 +766,30 @@ suite("SqlDocumentService Tests", () => {
sqlDocumentService["_connectionMgr"] = originalConnectionMgr;
});

test("onDidChangeActiveTextEditor should skip StatusView for notebook cells", async () => {
const hideStatusBarStub = sandbox.stub();
const updateStatusBarStub = sandbox.stub();
const updateResultsOnActiveEditorChangeStub = sandbox.stub();
sqlDocumentService["_statusview"] = {
hideLastShownStatusBar: hideStatusBarStub,
updateStatusBarForEditor: updateStatusBarStub,
} as any;
sqlDocumentService["_outputContentProvider"] = {
queryResultWebviewController: {
updateResultsOnActiveEditorChange: updateResultsOnActiveEditorChangeStub,
},
} as any;

const notebookCellEditor = {
document: mockTextDocument("vscode-notebook-cell://notebook/cell1"),
} as vscode.TextEditor;

await sqlDocumentService.onDidChangeActiveTextEditor(notebookCellEditor);

expect(hideStatusBarStub).to.have.been.calledOnce;
expect(updateStatusBarStub).to.not.have.been.called;
});

function setupConnectionManagerMocks(
connectionManager: sinon.SinonStubbedInstance<ConnectionManager>,
): void {
Expand Down
6 changes: 0 additions & 6 deletions localization/xliff/vscode-mssql.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -3641,12 +3641,6 @@
<trans-unit id="++CODE++a2b41c1abaf1dcf9e0e3f2dfadc4649810e9b986a3c53eaed96f510ec49d0ccd">
<source xml:lang="en">MSSQL: Click to change database</source>
</trans-unit>
<trans-unit id="++CODE++f993c79609a3d00c82d5214040869fd0b15ab7404074bc3fcf8111fcc88c5d45">
<source xml:lang="en">MSSQL: Click to connect</source>
</trans-unit>
<trans-unit id="++CODE++99a3297c47d9336c0c32fe572074cba7cd53bf9b0d5988c14d3335dd468e2c37">
<source xml:lang="en">MSSQL: Not connected</source>
</trans-unit>
<trans-unit id="++CODE++845cd20358ee1964f66ca8b28c6df89c00d0f59d43a3e8e3f3d65a515194a1da">
<source xml:lang="en">MSSQL: Welcome &amp; What&apos;s New</source>
</trans-unit>
Expand Down
Loading