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

Method run

src/commands/runQuery.ts:10–53  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8
9export class runQueryCommand extends BaseCommand {
10 async run() {
11 if (!vscode.window.activeTextEditor && !vscode.window.activeTextEditor.document) {
12 vscode.window.showWarningMessage('No SQL file selected');
13 return;
14 }
15
16 let connection = EditorState.connection;
17 if (!connection) {
18 vscode.window.showWarningMessage('No PostgreSQL Server or Database selected');
19 return;
20 }
21
22 let editor = vscode.window.activeTextEditor;
23 let querySelection = null;
24
25 // Calculate the selection if we have a selection, otherwise we'll use null to indicate
26 // the entire document is the selection
27 if (!editor.selection.isEmpty) {
28 let selection = editor.selection;
29 querySelection = {
30 startLine: selection.start.line,
31 startColumn: selection.start.character,
32 endLine: selection.end.line,
33 endColumn: selection.end.character
34 }
35 } else {
36 querySelection = {
37 startLine: 0,
38 startColumn: 0,
39 endLine: editor.document.lineCount
40 //endColumn: editor.document.lineAt(editor.document.lineCount).range.end.
41 }
42 }
43
44 // Trim down the selection. If it is empty after selecting, then we don't execute
45 let selectionToTrim = editor.selection.isEmpty ? undefined : editor.selection;
46 if (editor.document.getText(selectionToTrim).trim().length === 0) {
47 vscode.window.showWarningMessage('No SQL found to run');
48 return;
49 }
50
51 let sql = editor.document.getText(selectionToTrim);
52 return Database.runQuery(sql, editor, connection);
53 }
54}

Callers

nothing calls this directly

Calls 1

runQueryMethod · 0.80

Tested by

no test coverage detected