-
Notifications
You must be signed in to change notification settings - Fork 90
feat(tree-explorer): add ability to set preset connections in settings.json VSCODE-665 #909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
db87e39
06b1e90
d2d58e6
bf9cd64
0128835
0850375
bf39230
a72bad8
6cf0f1c
63c719d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,6 +162,8 @@ export default class ConnectionController { | |
| } | ||
|
|
||
| async loadSavedConnections(): Promise<void> { | ||
| this._connections = Object.create(null); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this fixing a bug where deleted saved connections would show up because they're not overridden in the for loop? Couldn't spot a test that verifies the behavior before was incorrect - am I just blind or should we add one?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this hasn't been an issue because we'd only run |
||
|
|
||
| const loadedConnections = await this._connectionStorage.loadConnections(); | ||
|
|
||
| for (const connection of loadedConnections) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,10 +12,9 @@ | |
| import type TreeItemParent from './treeItemParentInterface'; | ||
| import StreamProcessorTreeItem from './streamProcessorTreeItem'; | ||
|
|
||
| export enum ConnectionItemContextValues { | ||
| disconnected = 'disconnectedConnectionTreeItem', | ||
| connected = 'connectedConnectionTreeItem', | ||
| } | ||
| export type ConnectionItemContextValue = `${'disconnected' | 'connected'}${ | ||
| | '' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [extreme nit] The leading
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This gets automatically added by the linter 🤷 |
||
| | 'Immutable'}ConnectionTreeItem`; | ||
|
|
||
| function getIconPath(isActiveConnection: boolean): { | ||
| light: string; | ||
|
|
@@ -39,7 +38,7 @@ | |
| extends vscode.TreeItem | ||
| implements TreeItemParent, vscode.TreeDataProvider<ConnectionTreeItem> | ||
| { | ||
| contextValue = ConnectionItemContextValues.disconnected; | ||
| contextValue: ConnectionItemContextValue = 'disconnectedConnectionTreeItem'; | ||
|
|
||
| private _childrenCache: { | ||
| [key: string]: DatabaseTreeItem | StreamProcessorTreeItem; | ||
|
|
@@ -50,6 +49,7 @@ | |
| connectionId: string; | ||
|
|
||
| isExpanded: boolean; | ||
| isMutable: boolean; | ||
|
|
||
| constructor({ | ||
| connectionId, | ||
|
|
@@ -58,6 +58,7 @@ | |
| connectionController, | ||
| cacheIsUpToDate, | ||
| childrenCache, | ||
| isMutable, | ||
| }: { | ||
| connectionId: string; | ||
| collapsibleState: vscode.TreeItemCollapsibleState; | ||
|
|
@@ -67,21 +68,24 @@ | |
| childrenCache: { | ||
| [key: string]: DatabaseTreeItem | StreamProcessorTreeItem; | ||
| }; // Existing cache. | ||
| isMutable: boolean; | ||
| }) { | ||
| super( | ||
| connectionController.getSavedConnectionName(connectionId), | ||
| collapsibleState | ||
| ); | ||
|
|
||
| if ( | ||
| const isConnected = | ||
| connectionController.getActiveConnectionId() === connectionId && | ||
| !connectionController.isDisconnecting() && | ||
| !connectionController.isConnecting() | ||
| ) { | ||
| this.contextValue = ConnectionItemContextValues.connected; | ||
| } | ||
| !connectionController.isConnecting(); | ||
|
|
||
| this.contextValue = `${isConnected ? 'connected' : 'disconnected'}${ | ||
| isMutable ? '' : 'Immutable' | ||
|
||
| }ConnectionTreeItem`; | ||
|
|
||
| this.connectionId = connectionId; | ||
| this.isMutable = isMutable; | ||
| this._connectionController = connectionController; | ||
| this.isExpanded = isExpanded; | ||
| this._childrenCache = childrenCache; | ||
gagik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
@@ -204,7 +208,7 @@ | |
| return Object.values(this._childrenCache); | ||
| } | ||
|
|
||
| private async _buildChildrenCacheForDatabases(dataService: DataService) { | ||
|
Check warning on line 211 in src/explorer/connectionTreeItem.ts
|
||
| const databases = await this.listDatabases(); | ||
| databases.sort((a: string, b: string) => a.localeCompare(b)); | ||
|
|
||
|
|
@@ -226,7 +230,7 @@ | |
| return newChildrenCache; | ||
| } | ||
|
|
||
| private async _buildChildrenCacheForStreams(dataService: DataService) { | ||
|
Check warning on line 233 in src/explorer/connectionTreeItem.ts
|
||
| const processors = await this.listStreamProcessors(); | ||
| processors.sort((a, b) => a.name.localeCompare(b.name)); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,6 +160,15 @@ export default class MDBExtensionController implements vscode.Disposable { | |
| this._editorsController.registerProviders(); | ||
| } | ||
|
|
||
| subscribeToConfigurationChanges(): void { | ||
| const subscription = vscode.workspace.onDidChangeConfiguration((event) => { | ||
| if (event.affectsConfiguration('mdb.presetSavedConnections')) { | ||
| void this._connectionController.loadSavedConnections(); | ||
| } | ||
| }); | ||
| this._context.subscriptions.push(subscription); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand correctly, if I add this subscription to the context, it'll auto-dispose right so no further manual handling needed? @alenakhineika
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is how I understand this as well. |
||
| } | ||
|
|
||
| async activate(): Promise<void> { | ||
| this._explorerController.activateConnectionsTreeView(); | ||
| this._helpExplorer.activateHelpTreeView(this._telemetryService); | ||
|
|
@@ -172,6 +181,7 @@ export default class MDBExtensionController implements vscode.Disposable { | |
|
|
||
| this.registerCommands(); | ||
| this.showOverviewPageIfRecentlyInstalled(); | ||
| this.subscribeToConfigurationChanges(); | ||
|
|
||
| const copilot = vscode.extensions.getExtension(COPILOT_EXTENSION_ID); | ||
| void vscode.commands.executeCommand( | ||
|
|
@@ -480,6 +490,16 @@ export default class MDBExtensionController implements vscode.Disposable { | |
| return true; | ||
| } | ||
| ); | ||
| this.registerCommand( | ||
| EXTENSION_COMMANDS.MDB_OPEN_WORKSPACE_SETTINGS_FILE, | ||
| async () => { | ||
| await vscode.commands.executeCommand( | ||
| 'workbench.action.openWorkspaceSettingsFile' | ||
| ); | ||
|
|
||
| return true; | ||
| } | ||
| ); | ||
| this.registerCommand( | ||
| EXTENSION_COMMANDS.MDB_COPY_CONNECTION_STRING, | ||
| async (element: ConnectionTreeItem): Promise<boolean> => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be nice to include ability to quickly open workspace settings here when the item is preset (piggybacking on an existing VSCode action).
We can't easily detect where this preset comes from (i.e. it could also come from user settings) so we could also include a shortcut to open user settings, but maybe we don't want to encourage that and assume they know what they're doing by that point?
If someone that defined this in their user settings (as opposed to workspace) and clicks the Open Workspace Settings, it'd open or create a
.vscode/settings.jsonfile in the workspace, and setting things there would override user settings, which seems reasonable.