Skip to content

Commit e66f65a

Browse files
Remove duplicate status bar connect button (#21458)
* Fixes duplicate notebook status bar items * Fix status bar button appearance * Code review changes * Generated changes
1 parent 0370a76 commit e66f65a

6 files changed

Lines changed: 55 additions & 13 deletions

File tree

extensions/mssql/l10n/bundle.l10n.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,9 +1990,7 @@
19901990
"Keep in query pane": "Keep in query pane",
19911991
"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",
19921992
"New Deployment": "New Deployment",
1993-
"MSSQL: Not connected": "MSSQL: Not connected",
19941993
"MSSQL: Click to change database": "MSSQL: Click to change database",
1995-
"MSSQL: Click to connect": "MSSQL: Click to connect",
19961994
"Connection failed": "Connection failed",
19971995
"Query execution failed": "Query execution failed",
19981996
"No active notebook.": "No active notebook.",

extensions/mssql/src/constants/locConstants.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,9 +640,7 @@ export let newDeployment = l10n.t("New Deployment");
640640

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

647645
// Errors
648646
public static connectionFailed = l10n.t("Connection failed");

extensions/mssql/src/controllers/sqlDocumentService.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,14 @@ export default class SqlDocumentService implements vscode.Disposable {
299299
// Avoid processing events before initialization is complete
300300
return;
301301
}
302+
303+
// Notebook cells are managed by SqlNotebookController, not the
304+
// global ConnectionManager / StatusView. Skip to avoid duplicate
305+
// status bar items and unwanted auto-connect attempts.
306+
if (this.isNotebookCell(doc)) {
307+
return;
308+
}
309+
302310
this._connectionMgr.onDidOpenTextDocument(doc);
303311
const docUri = getUriKey(doc.uri);
304312

@@ -374,6 +382,14 @@ export default class SqlDocumentService implements vscode.Disposable {
374382
return;
375383
}
376384

385+
// Notebook cells have their own connection status bar managed by
386+
// SqlNotebookController. Skip StatusView updates so we don't show
387+
// duplicate connection status bar items for both the query editor
388+
// and the notebook.
389+
if (this.isNotebookCell(editor.document)) {
390+
return;
391+
}
392+
377393
const activeDocumentUri = getUriKey(editor.document.uri);
378394
const connectionInfo = this._connectionMgr?.getConnectionInfo(activeDocumentUri);
379395

@@ -595,6 +611,10 @@ export default class SqlDocumentService implements vscode.Disposable {
595611
// Update the URI in the output content provider, which will transfer query runner and webview state to the new URI
596612
await this._outputContentProvider?.updateQueryRunnerUri(oldUri, newUri);
597613
}
614+
615+
private isNotebookCell(doc: vscode.TextDocument): boolean {
616+
return doc.uri.scheme === "vscode-notebook-cell";
617+
}
598618
}
599619

600620
/**

extensions/mssql/src/notebooks/sqlNotebookController.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,14 @@ export class SqlNotebookController implements vscode.Disposable {
269269
}
270270
const mgr = this.connections.get(notebook.uri.toString());
271271
if (mgr?.isConnected()) {
272-
this.statusBarItem.text = `$(database) ${mgr.getConnectionLabel()}`;
272+
this.statusBarItem.text = `$(check) ${mgr.getConnectionLabel()}`;
273273
this.statusBarItem.tooltip =
274274
LocalizedConstants.Notebooks.statusBarClickToChangeDatabase;
275275
this.statusBarItem.command = Constants.cmdNotebooksChangeDatabase;
276276
this.statusBarItem.show();
277277
} else {
278-
this.statusBarItem.text = `$(database) ${LocalizedConstants.Notebooks.statusBarNotConnected}`;
279-
this.statusBarItem.tooltip = LocalizedConstants.Notebooks.statusBarClickToConnect;
278+
this.statusBarItem.text = `$(plug) ${LocalizedConstants.StatusBar.disconnectedLabel}`;
279+
this.statusBarItem.tooltip = LocalizedConstants.StatusBar.notConnectedTooltip;
280280
this.statusBarItem.command = Constants.cmdNotebooksChangeConnection;
281281
this.statusBarItem.show();
282282
}

extensions/mssql/test/unit/sqlDocumentService.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,14 @@ suite("SqlDocumentService Tests", () => {
480480
expect(docUriCallback).to.equal(document.uri.toString());
481481
});
482482

483+
test("onDidOpenTextDocument should skip notebook cell documents", async () => {
484+
const notebookCellDoc = mockTextDocument("vscode-notebook-cell://notebook/cell1");
485+
486+
await sqlDocumentService.onDidOpenTextDocument(notebookCellDoc);
487+
488+
expect(connectionManager.onDidOpenTextDocument).to.not.have.been.called;
489+
});
490+
483491
test("newQuery should call the new query method", async () => {
484492
let editor: vscode.TextEditor = {
485493
document: {
@@ -758,6 +766,30 @@ suite("SqlDocumentService Tests", () => {
758766
sqlDocumentService["_connectionMgr"] = originalConnectionMgr;
759767
});
760768

769+
test("onDidChangeActiveTextEditor should skip StatusView for notebook cells", async () => {
770+
const hideStatusBarStub = sandbox.stub();
771+
const updateStatusBarStub = sandbox.stub();
772+
const updateResultsOnActiveEditorChangeStub = sandbox.stub();
773+
sqlDocumentService["_statusview"] = {
774+
hideLastShownStatusBar: hideStatusBarStub,
775+
updateStatusBarForEditor: updateStatusBarStub,
776+
} as any;
777+
sqlDocumentService["_outputContentProvider"] = {
778+
queryResultWebviewController: {
779+
updateResultsOnActiveEditorChange: updateResultsOnActiveEditorChangeStub,
780+
},
781+
} as any;
782+
783+
const notebookCellEditor = {
784+
document: mockTextDocument("vscode-notebook-cell://notebook/cell1"),
785+
} as vscode.TextEditor;
786+
787+
await sqlDocumentService.onDidChangeActiveTextEditor(notebookCellEditor);
788+
789+
expect(hideStatusBarStub).to.have.been.calledOnce;
790+
expect(updateStatusBarStub).to.not.have.been.called;
791+
});
792+
761793
function setupConnectionManagerMocks(
762794
connectionManager: sinon.SinonStubbedInstance<ConnectionManager>,
763795
): void {

localization/xliff/vscode-mssql.xlf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3644,12 +3644,6 @@
36443644
<trans-unit id="++CODE++a2b41c1abaf1dcf9e0e3f2dfadc4649810e9b986a3c53eaed96f510ec49d0ccd">
36453645
<source xml:lang="en">MSSQL: Click to change database</source>
36463646
</trans-unit>
3647-
<trans-unit id="++CODE++f993c79609a3d00c82d5214040869fd0b15ab7404074bc3fcf8111fcc88c5d45">
3648-
<source xml:lang="en">MSSQL: Click to connect</source>
3649-
</trans-unit>
3650-
<trans-unit id="++CODE++99a3297c47d9336c0c32fe572074cba7cd53bf9b0d5988c14d3335dd468e2c37">
3651-
<source xml:lang="en">MSSQL: Not connected</source>
3652-
</trans-unit>
36533647
<trans-unit id="++CODE++845cd20358ee1964f66ca8b28c6df89c00d0f59d43a3e8e3f3d65a515194a1da">
36543648
<source xml:lang="en">MSSQL: Welcome &amp; What&apos;s New</source>
36553649
</trans-unit>

0 commit comments

Comments
 (0)