Skip to content

Commit

Permalink
Allow panel names to be re-used on different servers. (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Aug 6, 2024
1 parent 4476297 commit b5d579c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function activate(context: vscode.ExtensionContext) {

const dhcServiceRegistry = new DhServiceRegistry(
DhcService,
new ExtendedMap<string, vscode.WebviewPanel>(),
new ExtendedMap<string, ExtendedMap<string, vscode.WebviewPanel>>(),
diagnosticsCollection,
outputChannel,
toaster
Expand Down
18 changes: 17 additions & 1 deletion src/services/DhService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,23 @@ type CommandResultBase = {
error: string;
};

export abstract class DhService<TDH, TClient>
/**
* Helper type to make it easier to use `DhService` derived classes as newable
* factory functions. This type should mirror the constructor of `DhService`.
*/
export type DhServiceConstructor<
T extends DhService<TDH, TClient>,
TDH = unknown,
TClient = unknown,
> = new (
serverUrl: string,
panelRegistry: ExtendedMap<string, vscode.WebviewPanel>,
diagnosticsCollection: vscode.DiagnosticCollection,
outputChannel: vscode.OutputChannel,
toaster: Toaster
) => T;

export abstract class DhService<TDH = unknown, TClient = unknown>
extends EventDispatcher<'disconnect'>
implements Disposable
{
Expand Down
18 changes: 14 additions & 4 deletions src/services/DhServiceRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import * as vscode from 'vscode';
import { CacheService } from './CacheService';
import { DhcService, DhcServiceConstructor } from './DhcService';
import { DhcService } from './DhcService';
import { ensureHasTrailingSlash, ExtendedMap, Toaster } from '../util';
import { DhServiceConstructor } from './DhService';

export class DhServiceRegistry<T extends DhcService> extends CacheService<
T,
'disconnect'
> {
constructor(
serviceFactory: DhcServiceConstructor<T>,
panelRegistry: ExtendedMap<string, vscode.WebviewPanel>,
serviceFactory: DhServiceConstructor<T>,
panelRegistry: ExtendedMap<
string,
ExtendedMap<string, vscode.WebviewPanel>
>,
diagnosticsCollection: vscode.DiagnosticCollection,
outputChannel: vscode.OutputChannel,
toaster: Toaster
Expand All @@ -21,9 +25,15 @@ export class DhServiceRegistry<T extends DhcService> extends CacheService<
throw new Error(`${serviceFactory.name} server url is null.`);
}

// Get or add the panel registry for the server if it doesn't exist.
if (!panelRegistry.has(serverUrl)) {
panelRegistry.set(serverUrl, new ExtendedMap());
}
const serverPanelRegistry = panelRegistry.getOrThrow(serverUrl);

const dhService = new serviceFactory(
serverUrl,
panelRegistry,
serverPanelRegistry,
diagnosticsCollection,
outputChannel,
toaster
Expand Down
8 changes: 0 additions & 8 deletions src/services/DhcService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ import { ConnectionAndSession } from '../common';

const logger = new Logger('DhcService');

export type DhcServiceConstructor<T extends DhcService> = new (
serverUrl: string,
panelRegistry: ExtendedMap<string, vscode.WebviewPanel>,
diagnosticsCollection: vscode.DiagnosticCollection,
outputChannel: vscode.OutputChannel,
toaster: Toaster
) => T;

export class DhcService extends DhService<typeof DhcType, DhcType.CoreClient> {
private psk?: string;

Expand Down

0 comments on commit b5d579c

Please sign in to comment.