Skip to content

Commit

Permalink
getConsoleType util (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Oct 8, 2024
1 parent 6cf8fa0 commit 74182f3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/controllers/ConnectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
createConnectionQuickPickOptions,
createConnectStatusBarItem,
getConnectionsForConsoleType,
getConsoleType,
getEditorForUri,
isSupportedLanguageId,
Logger,
Expand Down Expand Up @@ -132,7 +133,7 @@ export class ConnectionController implements Disposable {
if ('url' in connectionOrServer) {
const cn = await this._serverManager.connectToServer(
connectionOrServer.url,
editor.document.languageId as ConsoleType
getConsoleType(editor.document.languageId)
);

if (cn == null) {
Expand Down
6 changes: 2 additions & 4 deletions src/controllers/ExtensionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from '../common';
import {
assertDefined,
getConsoleTypeOrDefault,
getConsoleType,
getEditorForUri,
getTempDir,
isInstanceOf,
Expand Down Expand Up @@ -528,9 +528,7 @@ export class ExtensionController implements Disposable {
// Use the active editor's language id to determine the console type or
// fallback to 'python'.
const workerConsoleType =
serverState.type === 'DHE'
? getConsoleTypeOrDefault(languageId)
: undefined;
serverState.type === 'DHE' ? getConsoleType(languageId) : undefined;

this._serverManager?.connectToServer(serverState.url, workerConsoleType);
};
Expand Down
10 changes: 5 additions & 5 deletions src/util/serverUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ export async function getConnectionsForConsoleType(
}

/**
* If the given value is a valid console type, return it, otherwise default to 'python'.
* If the given value is a valid console type, return it, otherwise return undefined.
* @param maybeConsoleType
* @returns A console type.
* @returns A console type or undefined if given value is invalid.
*/
export function getConsoleTypeOrDefault(
export function getConsoleType(
maybeConsoleType?: string
): ConsoleType {
): ConsoleType | undefined {
return typeof maybeConsoleType === 'string' &&
SERVER_LANGUAGE_SET.has(maybeConsoleType as ConsoleType)
? (maybeConsoleType as ConsoleType)
: 'python';
: undefined;
}

/**
Expand Down

0 comments on commit 74182f3

Please sign in to comment.