MCPcopy Create free account
hub / github.com/Borvik/vscode-postgres / run

Method run

src/commands/selectConnection.ts:13–56  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11
12export class selectConnectionCommand extends BaseCommand {
13 async run() {
14 // can we even select a connection it gets stored against a document uri
15 if (!vscode.window || !vscode.window.activeTextEditor || !vscode.window.activeTextEditor.document || !vscode.window.activeTextEditor.document.uri) {
16 // alert and return;
17 vscode.window.showWarningMessage('Unable to select a connection - a document is not active');
18 return;
19 }
20
21 let connections = Global.context.globalState.get<{ [key: string]: IConnection }>(Constants.GlobalStateKey);
22 if (!connections) connections = {};
23
24 let hosts: ConnectionQuickPickItem[] = [];
25 hosts.push({
26 label: '$(plus) Create new connection',
27 connection_key: '',
28 is_new_selector: true
29 });
30
31 for (const k in connections) {
32 if (connections.hasOwnProperty(k)) {
33 hosts.push({
34 label: connections[k].label || connections[k].host,
35 connection_key: k
36 });
37 }
38 }
39
40 const hostToSelect = await vscode.window.showQuickPick(hosts, {placeHolder: 'Select a connection', matchOnDetail: false});
41 if (!hostToSelect) return;
42
43 if (!hostToSelect.is_new_selector) {
44 let connection: IConnection = Object.assign({}, connections[hostToSelect.connection_key]);
45 if (connection.hasPassword || !connection.hasOwnProperty('hasPassword')) {
46 connection.password = await Global.context.secrets.get(hostToSelect.connection_key);
47 }
48 EditorState.connection = connection;
49 await vscode.commands.executeCommand('vscode-postgres.selectDatabase');
50 return;
51 }
52
53 let result = await vscode.commands.executeCommand('vscode-postgres.addConnection');
54 if (!result) return;
55 await vscode.commands.executeCommand('vscode-postgres.selectDatabase');
56 }
57}

Callers

nothing calls this directly

Calls 1

showQuickPickMethod · 0.80

Tested by

no test coverage detected