Skip to content

Commit

Permalink
Fix leaking commands from the connections extension to the command pa…
Browse files Browse the repository at this point in the history
…llete (#3853)

This PR makes a few commands that are internal to the connections pane
extension to not appear in the command pallete. Which addresses #3841

Also adds command to expand connections, which will make testing easier.
We shouldn' need to rely on specifics of the TreeView API for smoke
testing the connections pane. Addresses #3840
  • Loading branch information
dfalbel authored Jul 4, 2024
1 parent b750305 commit d8da3ec
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
23 changes: 17 additions & 6 deletions extensions/positron-connections/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,37 +47,48 @@
"command": "positron.connections.previewTable",
"title": "%commands.previewTable.title%",
"category": "%commands.previewTable.category%",
"icon": "$(eye)"
"icon": "$(eye)",
"enablement": "view == connections"
},
{
"command": "positron.connections.closeConnection",
"title": "%commands.closeConnection.title%",
"icon": "$(debug-disconnect)"
"icon": "$(debug-disconnect)",
"enablement": "view == connections"
},
{
"command": "positron.connections.refresh",
"title": "%commands.refresh.title%",
"icon": "$(refresh)"
"icon": "$(refresh)",
"enablement": "view == connections"
},
{
"command": "positron.connections.removeFromHistory",
"title": "%commands.removeFromHistory.title%",
"icon": "$(trash)"
"icon": "$(trash)",
"enablement": "view == connections"
},
{
"command": "positron.connections.reopenConnection",
"title": "%commands.reopenConnection.title%",
"icon": "$(open-preview)"
"icon": "$(open-preview)",
"enablement": "view == connections"
},
{
"command": "positron.connections.copyCodeToClipboard",
"title": "%commands.copyCodeToClipboard.title%",
"icon": "$(clippy)"
"icon": "$(clippy)",
"enablement": "view == connections"
},
{
"command": "positron.connections.clearConnectionsHistory",
"title": "%commands.clearConnectionsHistory.title%",
"icon": "$(clear-all)"
},
{
"command": "positron.connections.expandAll",
"title": "%commands.expandAll.title%",
"icon": "$(clear-all)"
}
],
"menus": {
Expand Down
3 changes: 2 additions & 1 deletion extensions/positron-connections/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"commands.removeFromHistory.title": "Remove connection from history",
"commands.reopenConnection.title": "Execute connection code in the console",
"commands.copyCodeToClipboard.title": "Copy connection code to clipboard",
"commands.clearConnectionsHistory.title": "Clear connections history"
"commands.clearConnectionsHistory.title": "Clear connections history",
"commands.expandAll.title": "Connections: Expand All"
}
22 changes: 22 additions & 0 deletions extensions/positron-connections/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,17 @@ export class ConnectionItemsProvider
});
}

//* getParent is required for `reveal` to work
async getParent(item: ConnectionItem): Promise<ConnectionItem | null> {
if (isDisconnectedConnectionItem(item) || isDatabaseConnectionItem(item)) {
return null;
}

// We are currently only interested in expanding the root connection nodes,
// thus we don't need to further implement this for now.
throw new Error(`Can't find the parent of this item`);
}

public refresh() {
this.fireOnDidChangeTreeData();
}
Expand Down Expand Up @@ -526,6 +537,17 @@ export class ConnectionItemsProvider
this.fireOnDidChangeTreeData();
}


/**
* Expand all connection nodes
* The maximum depth is 3 due to limitations in the TreeView API
*/
expandConnectionNodes(treeView: vscode.TreeView<ConnectionItem>) {
this._connections.forEach((connection) => {
treeView.reveal(connection, { expand: 3 });
});
}

fireOnDidChangeTreeData() {
this._onDidChangeTreeData.fire(undefined);
this.treeItemDecorationProvider.updateFileDecorations([]);
Expand Down
12 changes: 8 additions & 4 deletions extensions/positron-connections/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ import { PositronConnectionsComm } from './comms/ConnectionsComms';
export function activate(context: vscode.ExtensionContext) {
const viewId = 'connections';
const connectionProvider = new ConnectionItemsProvider(context);

// Register the tree data provider that will provide the connections
context.subscriptions.push(
vscode.window.registerTreeDataProvider(viewId, connectionProvider));
const connectionTreeView = vscode.window.createTreeView(viewId, { treeDataProvider: connectionProvider });

// Register a handler for the positron.connection client type. This client
// represents an active, queryable database connection.
Expand Down Expand Up @@ -97,4 +94,11 @@ export function activate(context: vscode.ExtensionContext) {
() => {
connectionProvider.refresh();
}));

/* This is mostly used for testing purposes, to avoid requiring clicks in the UI */
context.subscriptions.push(
vscode.commands.registerCommand('positron.connections.expandAll',
() => {
connectionProvider.expandConnectionNodes(connectionTreeView);
}));
}

0 comments on commit d8da3ec

Please sign in to comment.