Skip to content

Commit

Permalink
Simplified picker return (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Aug 21, 2024
1 parent a5ad106 commit fcacab0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
12 changes: 4 additions & 8 deletions src/controllers/ConnectionController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as vscode from 'vscode';
import type {
ConnectionPickItem,
ConsoleType,
Disposable,
IConfigService,
Expand Down Expand Up @@ -270,24 +269,21 @@ export class ConnectionController implements Disposable {
editor.document.uri
)?.serverUrl;

let result:
| ConnectionPickItem<'server', ServerState>
| ConnectionPickItem<'connection', IDhService>
| null = null;
let selectedCnResult: ServerState | IDhService | null = null;

try {
result = await createConnectionQuickPick(
selectedCnResult = await createConnectionQuickPick(
runningServersWithoutConnections,
connections,
editor.document.languageId,
editorActiveConnectionUrl
);

if (result == null) {
if (selectedCnResult == null) {
return false;
}

await this.connectEditor(result.data, editor);
await this.connectEditor(selectedCnResult, editor);

return true;
} catch (err) {
Expand Down
8 changes: 2 additions & 6 deletions src/util/uiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ export async function createConnectionQuickPick(
connections: IDhService[],
editorLanguageId: string,
editorActiveConnectionUrl?: URL | null
): Promise<
| ConnectionPickItem<'server', ServerState>
| ConnectionPickItem<'connection', IDhService>
| null
> {
): Promise<ServerState | IDhService | null> {
const serverOptions: ConnectionPickItem<'server', ServerState>[] =
servers.map(data => ({
type: 'server',
Expand Down Expand Up @@ -95,7 +91,7 @@ export async function createConnectionQuickPick(
return null;
}

return result;
return result.data;
}

/**
Expand Down

0 comments on commit fcacab0

Please sign in to comment.