diff --git a/src/controllers/ExtensionController.ts b/src/controllers/ExtensionController.ts index c690a8d3..ee590fee 100644 --- a/src/controllers/ExtensionController.ts +++ b/src/controllers/ExtensionController.ts @@ -42,7 +42,7 @@ import { DheJsApiCache, DheService, DheServiceCache, - DhService, + DhcService, PanelService, SecretService, ServerManager, @@ -56,7 +56,7 @@ import type { IDheClientFactory, IDheService, IDheServiceFactory, - IDhService, + IDhcService, IDhServiceFactory, IPanelService, ISecretService, @@ -601,7 +601,7 @@ export class ExtensionController implements Disposable { * Create a new text document based on the given connection capabilities. * @param dhService */ - onCreateNewDocument = async (dhService: IDhService): Promise => { + onCreateNewDocument = async (dhService: IDhcService): Promise => { const language = (await dhService.supportsConsoleType('python')) ? 'python' : 'groovy'; @@ -703,7 +703,7 @@ export class ExtensionController implements Disposable { const connectionState = await this._connectionController.getOrCreateConnection(uri); - if (isInstanceOf(connectionState, DhService)) { + if (isInstanceOf(connectionState, DhcService)) { await connectionState?.runEditorCode(editor, selectionOnly === true); } }; diff --git a/src/providers/ServerConnectionTreeProvider.ts b/src/providers/ServerConnectionTreeProvider.ts index f1656a71..3ea7bf6c 100644 --- a/src/providers/ServerConnectionTreeProvider.ts +++ b/src/providers/ServerConnectionTreeProvider.ts @@ -2,12 +2,12 @@ import * as vscode from 'vscode'; import { TreeDataProviderBase } from './TreeDataProviderBase'; import { CONNECTION_TREE_ITEM_CONTEXT, ICON_ID } from '../common'; import type { - IDhService, + IDhcService, ConnectionState, ServerConnectionNode, } from '../types'; import { isInstanceOf, sortByStringProp } from '../util'; -import { DhService } from '../services'; +import { DhcService } from '../services'; /** * Provider for the server connection tree view. @@ -32,7 +32,7 @@ export class ServerConnectionTreeProvider extends TreeDataProviderBase => { if (elementOrRoot == null) { return this.serverManager diff --git a/src/services/DhService.ts b/src/services/DhService.ts deleted file mode 100644 index 9e857246..00000000 --- a/src/services/DhService.ts +++ /dev/null @@ -1,365 +0,0 @@ -import * as vscode from 'vscode'; -import type { dh as DhcType } from '@deephaven/jsapi-types'; -import { isAggregateError } from '@deephaven/require-jsapi'; -import { hasErrorCode } from '../util/typeUtils'; -import type { - ConsoleType, - IDhService, - IPanelService, - IToastService, - Lazy, - UniqueID, - VariableChanges, - VariableDefintion, - VariableID, -} from '../types'; -import { formatTimestamp, getCombinedSelectedLinesText, Logger } from '../util'; -import { - OPEN_VARIABLE_PANELS_CMD, - REFRESH_VARIABLE_PANELS_CMD, - VARIABLE_UNICODE_ICONS, -} from '../common'; -import type { ConnectionAndSession } from '../dh/dhc'; -import { NoConsoleTypesError, parseServerError } from '../dh/errorUtils'; -import type { URLMap } from './URLMap'; - -const logger = new Logger('DhService'); - -export abstract class DhService - implements IDhService -{ - constructor( - serverUrl: URL, - coreCredentialsCache: URLMap>, - panelService: IPanelService, - diagnosticsCollection: vscode.DiagnosticCollection, - outputChannel: vscode.OutputChannel, - toaster: IToastService, - tagId?: UniqueID - ) { - this.coreCredentialsCache = coreCredentialsCache; - this.serverUrl = serverUrl; - this.panelService = panelService; - this.diagnosticsCollection = diagnosticsCollection; - this.outputChannel = outputChannel; - this.toaster = toaster; - this.tagId = tagId; - } - - private readonly _onDidDisconnect = new vscode.EventEmitter(); - readonly onDidDisconnect = this._onDidDisconnect.event; - - public readonly serverUrl: URL; - public readonly tagId?: UniqueID; - protected readonly subscriptions: (() => void)[] = []; - - protected readonly coreCredentialsCache: URLMap< - Lazy - >; - protected readonly outputChannel: vscode.OutputChannel; - protected readonly toaster: IToastService; - private readonly panelService: IPanelService; - private readonly diagnosticsCollection: vscode.DiagnosticCollection; - private cachedCreateClient: Promise | null = null; - private cachedCreateSession: Promise< - ConnectionAndSession - > | null = null; - private cachedInitApi: Promise | null = null; - - protected dh: TDH | null = null; - protected cn: DhcType.IdeConnection | null = null; - protected client: TClient | null = null; - protected session: DhcType.IdeSession | null = null; - - protected abstract initApi(): Promise; - protected abstract createClient(dh: TDH): Promise; - protected abstract createSession( - dh: TDH, - client: TClient - ): Promise>; - - private clearCaches(): void { - this.cachedCreateClient = null; - this.cachedCreateSession = null; - this.cachedInitApi = null; - this.client = null; - - if (this.cn != null) { - this.cn.close(); - this._onDidDisconnect.fire(this.serverUrl); - } - this.cn = null; - - this.dh = null; - this.session = null; - - this.subscriptions.forEach(dispose => dispose()); - } - - public async dispose(): Promise { - this.clearCaches(); - this._onDidDisconnect.dispose(); - } - - protected getToastErrorMessage( - err: unknown, - defaultErrorMessage: string - ): string { - if (err instanceof NoConsoleTypesError) { - return `No console types available for server: ${this.serverUrl}`; - } - - if (isAggregateError(err)) { - return `Failed to connect to server with code: ${err.code} ${this.serverUrl}`; - } - - return defaultErrorMessage; - } - - public get isInitialized(): boolean { - return this.cachedInitApi != null; - } - - public get isConnected(): boolean { - return this.dh != null && this.cn != null && this.session != null; - } - - public async initDh(): Promise { - try { - if (this.cachedInitApi == null) { - this.outputChannel.appendLine( - `Initializing Deephaven API...: ${this.serverUrl}` - ); - this.cachedInitApi = this.initApi(); - } - this.dh = await this.cachedInitApi; - - this.outputChannel.appendLine( - `Initialized Deephaven API: ${this.serverUrl}` - ); - } catch (err) { - this.clearCaches(); - logger.error(err); - this.outputChannel.appendLine( - `Failed to initialize Deephaven API${err == null ? '.' : `: ${err}`}` - ); - const toastMessage = this.getToastErrorMessage( - err, - 'Failed to initialize Deephaven API' - ); - this.toaster.error(toastMessage); - return false; - } - - if (this.cachedCreateClient == null) { - this.outputChannel.appendLine('Creating client...'); - this.cachedCreateClient = this.createClient(this.dh); - } - this.client = await this.cachedCreateClient; - - if (this.cachedCreateSession == null) { - this.outputChannel.appendLine('Creating session...'); - this.cachedCreateSession = this.createSession(this.dh, this.client); - - try { - const { cn, session } = await this.cachedCreateSession; - - cn.subscribeToFieldUpdates(changes => { - this.panelService.updateVariables( - this.serverUrl, - changes as VariableChanges - ); - - const panelVariablesToUpdate = changes.updated.filter( - (variable): variable is VariableDefintion => - this.panelService.hasPanel( - this.serverUrl, - variable.id as VariableID - ) - ); - - vscode.commands.executeCommand( - REFRESH_VARIABLE_PANELS_CMD, - this.serverUrl, - panelVariablesToUpdate - ); - }); - - // TODO: Use constant 'disconnect' event name - this.subscriptions.push( - cn.addEventListener('disconnect', () => { - this.clearCaches(); - }) - ); - - session.onLogMessage(logItem => { - // TODO: Should this pull log level from config somewhere? - if (logItem.logLevel !== 'INFO') { - const date = new Date(logItem.micros / 1000); - const timestamp = formatTimestamp(date); - - this.outputChannel.append( - `${timestamp} ${logItem.logLevel} ${logItem.message}` - ); - } - }); - } catch (err) {} - } - - try { - const { cn, session } = await this.cachedCreateSession; - this.cn = cn; - this.session = session; - } catch (err) { - logger.error(err); - const toastMessage = this.getToastErrorMessage( - err, - `Failed to create Deephaven session: ${this.serverUrl}` - ); - - this.toaster.error(toastMessage); - } - - if (this.cn == null || this.session == null) { - this.clearCaches(); - - return false; - } else { - this.toaster.info(`Created Deephaven session: ${this.serverUrl}`); - - return true; - } - } - - public async runEditorCode( - editor: vscode.TextEditor, - selectionOnly = false - ): Promise { - // Clear previous diagnostics when cmd starts running - this.diagnosticsCollection.set(editor.document.uri, []); - - if (this.session == null) { - await this.initDh(); - } - - if (this.cn == null || this.session == null) { - return; - } - - const [consoleType] = await this.cn.getConsoleTypes(); - - if (consoleType !== editor.document.languageId) { - this.toaster.error( - `This connection does not support '${editor.document.languageId}'.` - ); - return; - } - - const text = selectionOnly - ? getCombinedSelectedLinesText(editor) - : editor.document.getText(); - - logger.info('Sending text to dh:', text); - - let result: DhcType.ide.CommandResult; - let error: string | null = null; - - try { - const start = performance.now(); - result = await this.session.runCode(text); - logger.debug('Command took', performance.now() - start, 'ms'); - error = result.error; - } catch (err) { - error = String(err); - - // Grpc UNAUTHENTICATED code. This should not generally happen since we - // clear the caches on connection disconnect - if (hasErrorCode(err, 16)) { - this.clearCaches(); - this.toaster.error( - 'Session is no longer invalid. Please re-run the command to reconnect.' - ); - return; - } - } - - if (error) { - logger.error(error); - this.outputChannel.show(true); - this.outputChannel.appendLine(error); - this.toaster.error('An error occurred when running a command'); - - if (editor.document.languageId === 'python') { - const { line, value } = parseServerError(error); - - if (line != null) { - // If selectionOnly is true, the line number in the error will be - // relative to the selection (Python line numbers are 1 based. vscode - // line numbers are zero based.) - const fileLine = - (selectionOnly ? line + editor.selection.start.line : line) - 1; - - // There seems to be an error for certain Python versions where line - // numbers are shown as -1. In such cases, we'll just mark the first - // token on the first line to at least flag the file as having an error. - const startLine = Math.max(0, fileLine); - - // Zero length will flag a token instead of a line - const lineLength = - fileLine < 0 ? 0 : editor.document.lineAt(fileLine).text.length; - - // Diagnostic representing the line of code that produced the server error - const diagnostic: vscode.Diagnostic = { - message: value == null ? error : `${value}\n${error}`, - severity: vscode.DiagnosticSeverity.Error, - range: new vscode.Range(startLine, 0, startLine, lineLength), - source: 'deephaven', - }; - - this.diagnosticsCollection.set(editor.document.uri, [diagnostic]); - } - } - - return; - } - - const changed = [ - ...result!.changes.created, - ...result!.changes.updated, - // Type assertion is necessary to make use of our more specific branded types - // coming from the less specific types defined in the jsapi-types package. - ] as VariableDefintion[]; - - changed.forEach(({ title = 'Unknown', type }) => { - const icon = VARIABLE_UNICODE_ICONS[type] ?? type; - this.outputChannel.appendLine(`${icon} ${title}`); - }); - - const showVariables = changed.filter(v => !v.title.startsWith('_')); - - vscode.commands.executeCommand( - OPEN_VARIABLE_PANELS_CMD, - this.serverUrl, - showVariables - ); - } - - getConsoleTypes = async (): Promise> => { - if (this.cn == null) { - return new Set(); - } - - const consoleTypes = await (this.cn.getConsoleTypes() as Promise< - ConsoleType[] - >); - - return new Set(consoleTypes); - }; - - supportsConsoleType = async (consoleType: ConsoleType): Promise => { - const consoleTypes = await this.getConsoleTypes(); - return consoleTypes.has(consoleType); - }; -} - -export default DhService; diff --git a/src/services/DhcService.ts b/src/services/DhcService.ts index fbc63de6..3ded112c 100644 --- a/src/services/DhcService.ts +++ b/src/services/DhcService.ts @@ -1,18 +1,124 @@ import * as vscode from 'vscode'; import type { dh as DhcType } from '@deephaven/jsapi-types'; -import { initDhcApi } from '@deephaven/require-jsapi'; -import DhService from './DhService'; -import { getTempDir, Logger, urlToDirectoryName } from '../util'; +import { initDhcApi, isAggregateError } from '@deephaven/require-jsapi'; +import { + formatTimestamp, + getCombinedSelectedLinesText, + getTempDir, + Logger, + urlToDirectoryName, +} from '../util'; import { AUTH_HANDLER_TYPE_ANONYMOUS, AUTH_HANDLER_TYPE_PSK, initDhcSession, type ConnectionAndSession, } from '../dh/dhc'; +import type { + ConsoleType, + IDhcService, + IPanelService, + IToastService, + Lazy, + UniqueID, + VariableChanges, + VariableDefintion, + VariableID, +} from '../types'; +import type { URLMap } from './URLMap'; +import { + OPEN_VARIABLE_PANELS_CMD, + REFRESH_VARIABLE_PANELS_CMD, + VARIABLE_UNICODE_ICONS, +} from '../common'; +import { NoConsoleTypesError, parseServerError } from '../dh/errorUtils'; +import { hasErrorCode } from '../util/typeUtils'; const logger = new Logger('DhcService'); -export class DhcService extends DhService { +export class DhcService implements IDhcService { + constructor( + serverUrl: URL, + coreCredentialsCache: URLMap>, + panelService: IPanelService, + diagnosticsCollection: vscode.DiagnosticCollection, + outputChannel: vscode.OutputChannel, + toaster: IToastService, + tagId?: UniqueID + ) { + this.coreCredentialsCache = coreCredentialsCache; + this.serverUrl = serverUrl; + this.panelService = panelService; + this.diagnosticsCollection = diagnosticsCollection; + this.outputChannel = outputChannel; + this.toaster = toaster; + this.tagId = tagId; + } + + private readonly _onDidDisconnect = new vscode.EventEmitter(); + readonly onDidDisconnect = this._onDidDisconnect.event; + + public readonly serverUrl: URL; + public readonly tagId?: UniqueID; + private readonly subscriptions: (() => void)[] = []; + + private readonly coreCredentialsCache: URLMap>; + private readonly outputChannel: vscode.OutputChannel; + private readonly toaster: IToastService; + private readonly panelService: IPanelService; + private readonly diagnosticsCollection: vscode.DiagnosticCollection; + private cachedCreateClient: Promise | null = null; + private cachedCreateSession: Promise< + ConnectionAndSession + > | null = null; + private cachedInitApi: Promise | null = null; + + private dh: typeof DhcType | null = null; + private cn: DhcType.IdeConnection | null = null; + private client: DhcType.CoreClient | null = null; + private session: DhcType.IdeSession | null = null; + + get isInitialized(): boolean { + return this.cachedInitApi != null; + } + + get isConnected(): boolean { + return this.dh != null && this.cn != null && this.session != null; + } + + private clearCaches(): void { + this.cachedCreateClient = null; + this.cachedCreateSession = null; + this.cachedInitApi = null; + this.client = null; + + if (this.cn != null) { + this.cn.close(); + this._onDidDisconnect.fire(this.serverUrl); + } + this.cn = null; + + this.dh = null; + this.session = null; + + this.subscriptions.forEach(dispose => dispose()); + } + + private getToastErrorMessage( + err: unknown, + defaultErrorMessage: string + ): string { + if (err instanceof NoConsoleTypesError) { + return `No console types available for server: ${this.serverUrl}`; + } + + if (isAggregateError(err)) { + return `Failed to connect to server with code: ${err.code} ${this.serverUrl}`; + } + + return defaultErrorMessage; + } + async getPsk(): Promise { const credentials = await this.coreCredentialsCache.get(this.serverUrl)?.(); @@ -23,16 +129,121 @@ export class DhcService extends DhService { return credentials.token ?? null; } - protected async initApi(): Promise { + async initApi(): Promise { return initDhcApi( this.serverUrl, getTempDir({ subDirectory: urlToDirectoryName(this.serverUrl) }) ); } - protected async createClient( - dh: typeof DhcType - ): Promise { + async initDh(): Promise { + try { + if (this.cachedInitApi == null) { + this.outputChannel.appendLine( + `Initializing Deephaven API...: ${this.serverUrl}` + ); + this.cachedInitApi = this.initApi(); + } + this.dh = await this.cachedInitApi; + + this.outputChannel.appendLine( + `Initialized Deephaven API: ${this.serverUrl}` + ); + } catch (err) { + this.clearCaches(); + logger.error(err); + this.outputChannel.appendLine( + `Failed to initialize Deephaven API${err == null ? '.' : `: ${err}`}` + ); + const toastMessage = this.getToastErrorMessage( + err, + 'Failed to initialize Deephaven API' + ); + this.toaster.error(toastMessage); + return false; + } + + if (this.cachedCreateClient == null) { + this.outputChannel.appendLine('Creating client...'); + this.cachedCreateClient = this.createClient(this.dh); + } + this.client = await this.cachedCreateClient; + + if (this.cachedCreateSession == null) { + this.outputChannel.appendLine('Creating session...'); + this.cachedCreateSession = this.createSession(this.dh, this.client); + + try { + const { cn, session } = await this.cachedCreateSession; + + cn.subscribeToFieldUpdates(changes => { + this.panelService.updateVariables( + this.serverUrl, + changes as VariableChanges + ); + + const panelVariablesToUpdate = changes.updated.filter( + (variable): variable is VariableDefintion => + this.panelService.hasPanel( + this.serverUrl, + variable.id as VariableID + ) + ); + + vscode.commands.executeCommand( + REFRESH_VARIABLE_PANELS_CMD, + this.serverUrl, + panelVariablesToUpdate + ); + }); + + // TODO: Use constant 'disconnect' event name + this.subscriptions.push( + cn.addEventListener('disconnect', () => { + this.clearCaches(); + }) + ); + + session.onLogMessage(logItem => { + // TODO: Should this pull log level from config somewhere? + if (logItem.logLevel !== 'INFO') { + const date = new Date(logItem.micros / 1000); + const timestamp = formatTimestamp(date); + + this.outputChannel.append( + `${timestamp} ${logItem.logLevel} ${logItem.message}` + ); + } + }); + } catch (err) {} + } + + try { + const { cn, session } = await this.cachedCreateSession; + this.cn = cn; + this.session = session; + } catch (err) { + logger.error(err); + const toastMessage = this.getToastErrorMessage( + err, + `Failed to create Deephaven session: ${this.serverUrl}` + ); + + this.toaster.error(toastMessage); + } + + if (this.cn == null || this.session == null) { + this.clearCaches(); + + return false; + } else { + this.toaster.info(`Created Deephaven session: ${this.serverUrl}`); + + return true; + } + } + + async createClient(dh: typeof DhcType): Promise { try { return new dh.CoreClient(this.serverUrl.toString()); } catch (err) { @@ -41,7 +252,7 @@ export class DhcService extends DhService { } } - protected async createSession( + async createSession( dh: typeof DhcType, client: DhcType.CoreClient ): Promise> { @@ -78,6 +289,141 @@ export class DhcService extends DhService { throw new Error('No supported authentication methods found.'); } + + async dispose(): Promise { + this.clearCaches(); + this._onDidDisconnect.dispose(); + } + + getConsoleTypes = async (): Promise> => { + if (this.cn == null) { + return new Set(); + } + + const consoleTypes = await (this.cn.getConsoleTypes() as Promise< + ConsoleType[] + >); + + return new Set(consoleTypes); + }; + + supportsConsoleType = async (consoleType: ConsoleType): Promise => { + const consoleTypes = await this.getConsoleTypes(); + return consoleTypes.has(consoleType); + }; + + async runEditorCode( + editor: vscode.TextEditor, + selectionOnly = false + ): Promise { + // Clear previous diagnostics when cmd starts running + this.diagnosticsCollection.set(editor.document.uri, []); + + if (this.session == null) { + await this.initDh(); + } + + if (this.cn == null || this.session == null) { + return; + } + + const [consoleType] = await this.cn.getConsoleTypes(); + + if (consoleType !== editor.document.languageId) { + this.toaster.error( + `This connection does not support '${editor.document.languageId}'.` + ); + return; + } + + const text = selectionOnly + ? getCombinedSelectedLinesText(editor) + : editor.document.getText(); + + logger.info('Sending text to dh:', text); + + let result: DhcType.ide.CommandResult; + let error: string | null = null; + + try { + const start = performance.now(); + result = await this.session.runCode(text); + logger.debug('Command took', performance.now() - start, 'ms'); + error = result.error; + } catch (err) { + error = String(err); + + // Grpc UNAUTHENTICATED code. This should not generally happen since we + // clear the caches on connection disconnect + if (hasErrorCode(err, 16)) { + this.clearCaches(); + this.toaster.error( + 'Session is no longer invalid. Please re-run the command to reconnect.' + ); + return; + } + } + + if (error) { + logger.error(error); + this.outputChannel.show(true); + this.outputChannel.appendLine(error); + this.toaster.error('An error occurred when running a command'); + + if (editor.document.languageId === 'python') { + const { line, value } = parseServerError(error); + + if (line != null) { + // If selectionOnly is true, the line number in the error will be + // relative to the selection (Python line numbers are 1 based. vscode + // line numbers are zero based.) + const fileLine = + (selectionOnly ? line + editor.selection.start.line : line) - 1; + + // There seems to be an error for certain Python versions where line + // numbers are shown as -1. In such cases, we'll just mark the first + // token on the first line to at least flag the file as having an error. + const startLine = Math.max(0, fileLine); + + // Zero length will flag a token instead of a line + const lineLength = + fileLine < 0 ? 0 : editor.document.lineAt(fileLine).text.length; + + // Diagnostic representing the line of code that produced the server error + const diagnostic: vscode.Diagnostic = { + message: value == null ? error : `${value}\n${error}`, + severity: vscode.DiagnosticSeverity.Error, + range: new vscode.Range(startLine, 0, startLine, lineLength), + source: 'deephaven', + }; + + this.diagnosticsCollection.set(editor.document.uri, [diagnostic]); + } + } + + return; + } + + const changed = [ + ...result!.changes.created, + ...result!.changes.updated, + // Type assertion is necessary to make use of our more specific branded types + // coming from the less specific types defined in the jsapi-types package. + ] as VariableDefintion[]; + + changed.forEach(({ title = 'Unknown', type }) => { + const icon = VARIABLE_UNICODE_ICONS[type] ?? type; + this.outputChannel.appendLine(`${icon} ${title}`); + }); + + const showVariables = changed.filter(v => !v.title.startsWith('_')); + + vscode.commands.executeCommand( + OPEN_VARIABLE_PANELS_CMD, + this.serverUrl, + showVariables + ); + } } export default DhcService; diff --git a/src/services/DhcServiceFactory.ts b/src/services/DhcServiceFactory.ts index df89f37d..4c4f0a9a 100644 --- a/src/services/DhcServiceFactory.ts +++ b/src/services/DhcServiceFactory.ts @@ -2,6 +2,7 @@ import * as vscode from 'vscode'; import type { dh as DhcType } from '@deephaven/jsapi-types'; import { DhcService } from './DhcService'; import type { + IDhcService, IDhServiceFactory, IPanelService, IToastService, @@ -22,7 +23,7 @@ export class DhcServiceFactory implements IDhServiceFactory { private toaster: IToastService ) {} - create = (serverUrl: URL, tagId?: UniqueID): DhcService => { + create = (serverUrl: URL, tagId?: UniqueID): IDhcService => { const dhService = new DhcService( serverUrl, this.coreCredentialsCache, diff --git a/src/services/ServerManager.ts b/src/services/ServerManager.ts index b7b0a00f..389eaa1f 100644 --- a/src/services/ServerManager.ts +++ b/src/services/ServerManager.ts @@ -31,7 +31,7 @@ import { } from '../util'; import { URLMap } from './URLMap'; import { URIMap } from './URIMap'; -import { DhService } from './DhService'; +import { DhcService } from './DhcService'; import { AUTH_HANDLER_TYPE_PSK } from '../dh/dhc'; const logger = new Logger('ServerManager'); @@ -479,7 +479,7 @@ export class ServerManager implements IServerManager { const uri = editor.document.uri; const isConsoleTypeSupported = - isInstanceOf(connectionState, DhService) && + isInstanceOf(connectionState, DhcService) && (await connectionState.supportsConsoleType( editor.document.languageId as ConsoleType )); diff --git a/src/services/index.ts b/src/services/index.ts index e161de37..56ff8aba 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -1,6 +1,5 @@ export * from './cache'; export * from './ConfigService'; -export * from './DhService'; export * from './DhcService'; export * from './DhcServiceFactory'; export * from './DheService'; diff --git a/src/types/serviceTypes.d.ts b/src/types/serviceTypes.d.ts index 4e956ca7..fb32c10a 100644 --- a/src/types/serviceTypes.d.ts +++ b/src/types/serviceTypes.d.ts @@ -42,9 +42,7 @@ export interface IConfigService { /** * Service that manages connections + sessions to a DH worker. */ -export interface IDhService - extends Disposable, - ConnectionState { +export interface IDhcService extends Disposable, ConnectionState { readonly isInitialized: boolean; readonly isConnected: boolean; readonly onDidDisconnect: vscode.Event; @@ -94,7 +92,7 @@ export interface IFactory { * Factory for creating IDhService instances. */ export type IDhServiceFactory = IFactory< - IDhService, + IDhcService, [serverUrl: URL, tagId?: UniqueID] >; export type IDheClientFactory = ( diff --git a/src/util/serverUtils.ts b/src/util/serverUtils.ts index 26278282..e54dd8d2 100644 --- a/src/util/serverUtils.ts +++ b/src/util/serverUtils.ts @@ -9,7 +9,7 @@ import type { } from '../types'; import { PIP_SERVER_STATUS_DIRECTORY, SERVER_LANGUAGE_SET } from '../common'; import { getTempDir } from './tmpUtils'; -import { DhService } from '../services'; +import { DhcService } from '../services'; import { isInstanceOf } from './isInstanceOf'; /** @@ -131,7 +131,7 @@ export async function* iterateConnectionsForConsoleType( ): AsyncGenerator { for (const connection of connections) { const isConsoleTypeSupported = - isInstanceOf(connection, DhService) && + isInstanceOf(connection, DhcService) && (await connection.supportsConsoleType(consoleType)); if (isConsoleTypeSupported) { diff --git a/src/util/treeViewUtils.spec.ts b/src/util/treeViewUtils.spec.ts index 32dfda8c..0abb39db 100644 --- a/src/util/treeViewUtils.spec.ts +++ b/src/util/treeViewUtils.spec.ts @@ -14,7 +14,7 @@ import { } from './treeViewUtils'; import type { ConsoleType, - IDhService, + IDhcService, ServerState, VariableDefintion, VariableType, @@ -40,7 +40,7 @@ const variableTypes: readonly VariableType[] = [ ] as const; describe('getPanelConnectionTreeItem', () => { - const getConsoleTypes: IDhService['getConsoleTypes'] = vi + const getConsoleTypes: IDhcService['getConsoleTypes'] = vi .fn() .mockResolvedValue(new Set(['python'])); @@ -54,7 +54,7 @@ describe('getPanelConnectionTreeItem', () => { isInitialized, serverUrl, getConsoleTypes, - } as IDhService; + } as IDhcService; vi.mocked(isInstanceOf).mockReturnValue(true); diff --git a/src/util/treeViewUtils.ts b/src/util/treeViewUtils.ts index 49cae6cb..a5aa6da3 100644 --- a/src/util/treeViewUtils.ts +++ b/src/util/treeViewUtils.ts @@ -12,7 +12,7 @@ import { SERVER_TREE_ITEM_CONTEXT, type ServerTreeItemContextValue, } from '../common'; -import { DhService } from '../services'; +import { DhcService } from '../services'; import { isInstanceOf } from './isInstanceOf'; /** @@ -55,7 +55,7 @@ export async function getPanelConnectionTreeItem( connection: ConnectionState ): Promise { const [consoleType] = - isInstanceOf(connection, DhService) && connection.isInitialized + isInstanceOf(connection, DhcService) && connection.isInitialized ? await connection.getConsoleTypes() : []; diff --git a/src/util/uiUtils.spec.ts b/src/util/uiUtils.spec.ts index 10cb00da..39bb5790 100644 --- a/src/util/uiUtils.spec.ts +++ b/src/util/uiUtils.spec.ts @@ -11,7 +11,7 @@ import { import type { ConnectionState, CoreConnectionConfig, - IDhService, + IDhcService, ServerState, } from '../types'; @@ -83,7 +83,7 @@ describe('createConnectionQuickPickOptions', () => { it('should throw if no servers or connections', () => { const servers: ServerState[] = []; - const connections: IDhService[] = []; + const connections: IDhcService[] = []; expect(() => createConnectionQuickPickOptions(servers, connections, 'python')