Skip to content

Commit

Permalink
Commands to trash all connections to server (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Oct 23, 2024
1 parent 89f66c6 commit ad97e50
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 9 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@
"view/item/context": [
{
"command": "vscode-deephaven.connectToServer",
"when": "view == vscode-deephaven.serverTree && (viewItem == isManagedServerDisconnected || viewItem == isServerRunningDisconnected || viewItem == isDHEServerRunning)",
"when": "view == vscode-deephaven.serverTree && (viewItem == isManagedServerDisconnected || viewItem == isServerRunningDisconnected || viewItem == isDHEServerRunningConnected || viewItem == isDHEServerRunningDisconnected)",
"group": "inline"
},
{
Expand All @@ -740,17 +740,17 @@
},
{
"command": "vscode-deephaven.disconnectFromServer",
"when": "view == vscode-deephaven.serverConnectionTree && viewItem == isConnection",
"when": "(view == vscode-deephaven.serverTree && (viewItem == isServerRunningConnected || viewItem == isDHEServerRunningConnected)) || (view == vscode-deephaven.serverConnectionTree && viewItem == isConnection)",
"group": "inline@2"
},
{
"command": "vscode-deephaven.generateDHEKeyPair",
"when": "view == vscode-deephaven.serverTree && viewItem == isDHEServerRunning",
"when": "view == vscode-deephaven.serverTree && (viewItem == isDHEServerRunningConnected || viewItem == isDHEServerRunningDisconnected)",
"group": "inline"
},
{
"command": "vscode-deephaven.openInBrowser",
"when": "view == vscode-deephaven.serverTree && (viewItem == isManagedServerConnected || viewItem == isServerRunningConnected || viewItem == isServerRunningDisconnected || viewItem == isManagedServerDisconnected || viewItem == isDHEServerRunning)",
"when": "view == vscode-deephaven.serverTree && (viewItem == isManagedServerConnected || viewItem == isManagedServerDisconnected || viewItem == isServerRunningConnected || viewItem == isServerRunningDisconnected || viewItem == isDHEServerRunningConnected || viewItem == isDHEServerRunningDisconnected)",
"group": "inline"
},
{
Expand Down
3 changes: 2 additions & 1 deletion src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ export const PIP_SERVER_STATUS_DIRECTORY = 'pip-server-status';

export const SERVER_TREE_ITEM_CONTEXT = {
canStartServer: 'canStartServer',
isDHEServerRunning: 'isDHEServerRunning',
isDHEServerRunningConnected: 'isDHEServerRunningConnected',
isDHEServerRunningDisconnected: 'isDHEServerRunningDisconnected',
isManagedServerConnected: 'isManagedServerConnected',
isManagedServerConnecting: 'isManagedServerConnecting',
isManagedServerDisconnected: 'isManagedServerDisconnected',
Expand Down
21 changes: 19 additions & 2 deletions src/controllers/ExtensionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,26 @@ export class ExtensionController implements Disposable {
* Handle disconnecting from a server.
*/
onDisconnectFromServer = async (
connectionState: ConnectionState
serverOrConnectionState: ServerState | ConnectionState
): Promise<void> => {
this._serverManager?.disconnectFromServer(connectionState.serverUrl);
// ConnectionState
if ('serverUrl' in serverOrConnectionState) {
this._serverManager?.disconnectFromServer(
serverOrConnectionState.serverUrl
);
return;
}

// DHC ServerState
if (serverOrConnectionState.type === 'DHC') {
this._coreCredentialsCache?.delete(serverOrConnectionState.url);
this._serverManager?.disconnectFromServer(serverOrConnectionState.url);
return;
}

// DHE ServerState
this._dheCredentialsCache?.delete(serverOrConnectionState.url);
this._serverManager?.disconnectFromDHEServer(serverOrConnectionState.url);
};

/**
Expand Down
31 changes: 31 additions & 0 deletions src/services/ServerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,37 @@ export class ServerManager implements IServerManager {
this._onDidUpdate.fire();
};

/**
* Completely disconnect from a DHE server. This including all workers plus
* the primary DHE client connection.
* @param dheServerUrl The URL of the DHE server to disconnect from.
* @returns Promise that resolves when all connections have been discarded.
*/
disconnectFromDHEServer = async (dheServerUrl: URL): Promise<void> => {
const workerUrls = [...this._workerURLToServerURLMap.entries()].filter(
([, url]) => url.toString() === dheServerUrl.toString()
);

for (const [workerUrl] of workerUrls) {
await this.disconnectFromServer(workerUrl);
}

this._dheServiceCache.invalidate(dheServerUrl);

const serverState = this._serverMap.get(dheServerUrl);
if (serverState == null) {
return;
}

this._serverMap.set(dheServerUrl, {
...serverState,
isConnected: false,
connectionCount: 0,
});

this._onDidUpdate.fire();
};

disconnectFromServer = async (
serverOrWorkerUrl: URL | WorkerURL
): Promise<void> => {
Expand Down
1 change: 1 addition & 0 deletions src/types/serviceTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export interface IServerManager extends Disposable {
workerConsoleType?: ConsoleType
) => Promise<ConnectionState | null>;
disconnectEditor: (uri: vscode.Uri) => void;
disconnectFromDHEServer: (dheServerUrl: URL) => Promise<void>;
disconnectFromServer: (serverUrl: URL) => Promise<void>;
loadServerConfig: () => Promise<void>;

Expand Down
7 changes: 5 additions & 2 deletions src/util/treeViewUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ export function getServerContextValue({

if (isRunning) {
if (isDHE) {
return SERVER_TREE_ITEM_CONTEXT.isDHEServerRunning;
return isConnected
? SERVER_TREE_ITEM_CONTEXT.isDHEServerRunningConnected
: SERVER_TREE_ITEM_CONTEXT.isDHEServerRunningDisconnected;
}

return isConnected
Expand Down Expand Up @@ -252,7 +254,8 @@ export function getServerTreeItem(server: ServerState): vscode.TreeItem {
const canConnect =
contextValue === SERVER_TREE_ITEM_CONTEXT.isManagedServerDisconnected ||
contextValue === SERVER_TREE_ITEM_CONTEXT.isServerRunningDisconnected ||
contextValue === SERVER_TREE_ITEM_CONTEXT.isDHEServerRunning;
contextValue === SERVER_TREE_ITEM_CONTEXT.isDHEServerRunningConnected ||
contextValue === SERVER_TREE_ITEM_CONTEXT.isDHEServerRunningDisconnected;

return {
label: new URL(urlStr).host,
Expand Down

0 comments on commit ad97e50

Please sign in to comment.