Skip to content

Commit e27c2f7

Browse files
committed
Merge branch 'main' into feature/peek
2 parents d4eda78 + 4032ee6 commit e27c2f7

File tree

10 files changed

+271
-72
lines changed

10 files changed

+271
-72
lines changed

package.json

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,21 @@
447447
"category": "Db2 for i",
448448
"icon": "$(window)"
449449
},
450+
{
451+
"command": "vscode-db2i.runEditorStatement.multiple.all",
452+
"title": "Run all statements",
453+
"category": "Db2 for i"
454+
},
455+
{
456+
"command": "vscode-db2i.runEditorStatement.multiple.selected",
457+
"title": "Run selected statements",
458+
"category": "Db2 for i"
459+
},
460+
{
461+
"command": "vscode-db2i.runEditorStatement.multiple.from",
462+
"title": "Run statements from cursor",
463+
"category": "Db2 for i"
464+
},
450465
{
451466
"command": "vscode-db2i.statement.cancel",
452467
"title": "Cancel",
@@ -1124,22 +1139,37 @@
11241139
{
11251140
"command": "vscode-db2i.runEditorStatement.inView",
11261141
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true",
1127-
"group": "navigation@1"
1142+
"group": "navigation@2"
1143+
},
1144+
{
1145+
"command": "vscode-db2i.runEditorStatement.multiple.all",
1146+
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true",
1147+
"group": "navigation_multiple@1"
1148+
},
1149+
{
1150+
"command": "vscode-db2i.runEditorStatement.multiple.selected",
1151+
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true && editorHasSelection",
1152+
"group": "navigation_multiple@2"
1153+
},
1154+
{
1155+
"command": "vscode-db2i.runEditorStatement.multiple.from",
1156+
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true && !editorHasSelection",
1157+
"group": "navigation_multiple@2"
11281158
},
11291159
{
11301160
"command": "vscode-db2i.editorExplain.withRun",
11311161
"when": "editorLangId == sql",
1132-
"group": "2_explain@1"
1162+
"group": "navigation_explain@1"
11331163
},
11341164
{
11351165
"command": "vscode-db2i.editorExplain.withoutRun",
11361166
"when": "editorLangId == sql",
1137-
"group": "2_explain@2"
1167+
"group": "navigation_explain@2"
11381168
},
11391169
{
11401170
"command": "vscode-db2i.notebook.fromSqlUri",
11411171
"when": "editorLangId == sql",
1142-
"group": "3_notebook@1"
1172+
"group": "navigation_notebook@1"
11431173
}
11441174
],
11451175
"notebook/toolbar": [

src/connection/manager.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { OldSQLJob } from "./sqlJob";
55
import { askAboutNewJob, onConnectOrServerInstall, osDetail } from "../config";
66
import { SelfValue } from "../views/jobManager/selfCodes/nodes";
77
import Configuration from "../configuration";
8-
import { QueryOptions } from "@ibm/mapepire-js/dist/src/types";
8+
import { QueryOptions, QueryResult } from "@ibm/mapepire-js/dist/src/types";
99
import { Query } from "@ibm/mapepire-js/dist/src/query";
1010

1111
export interface JobInfo {
@@ -118,25 +118,27 @@ export class SQLJobManager {
118118
return this.jobs[jobExists];
119119
}
120120

121-
/**
122-
* Runs SQL
123-
* @param query the SQL query
124-
* @param parameters the list of parameters (indicated by '?' parameter parkers in the SQL query)
125-
* @param isTerseResults whether the returned data is in terse format. When set to true, the data is returned as an array
126-
* of arrays. When set to false, data is returned as an array of objects (compatible with legacy API).
127-
* @returns
128-
*/
129-
async runSQL<T>(query: string, opts?: QueryOptions): Promise<T[]> {
121+
async runSQL<T>(query: string, opts?: QueryOptions, rowsToFetch = 2147483647): Promise<T[]> {
130122
// 2147483647 is NOT arbitrary. On the server side, this is processed as a Java
131123
// int. This is the largest number available without overflow (Integer.MAX_VALUE)
132-
const rowsToFetch = 2147483647;
133124

134125
const statement = await this.getPagingStatement<T>(query, opts);
135126
const results = await statement.execute(rowsToFetch);
136127
statement.close();
137128
return results.data;
138129
}
139130

131+
async runSQLVerbose<T>(query: string, opts?: QueryOptions, rowsToFetch = 2147483647): Promise<QueryResult<T>> {
132+
// 2147483647 is NOT arbitrary. On the server side, this is processed as a Java
133+
// int. This is the largest number available without overflow (Integer.MAX_VALUE)
134+
135+
const statement = await this.getPagingStatement<T>(query, opts);
136+
const results = await statement.execute(rowsToFetch);
137+
statement.close();
138+
139+
return results;
140+
}
141+
140142
async getPagingStatement<T>(query: string, opts?: QueryOptions): Promise<Query<T>> {
141143
const selected = this.jobs[this.selectedJob]
142144
if (ServerComponent.isInstalled() && selected) {

src/connection/syntaxChecker/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { posix } from "path";
44
import { getValidatorSource, VALIDATOR_NAME, WRAPPER_NAME } from "./checker";
55
import { JobManager } from "../../config";
66
import { getBase, getInstance } from "../../base";
7+
import { JobInfo } from "../manager";
78

89
interface SqlCheckError {
910
CURSTMTLENGTH: number;
@@ -134,14 +135,13 @@ export class SQLStatementChecker implements IBMiComponent {
134135
return undefined;
135136
}
136137

137-
async checkMultipleStatements(statements: string[]): Promise<SqlSyntaxError[]|undefined> {
138+
async checkMultipleStatements(currentJob: JobInfo, statements: string[]): Promise<SqlSyntaxError[]|undefined> {
138139
const connection = getInstance()?.getConnection();
139140
if (!connection) return undefined;
140141

141-
const currentJob = JobManager.getSelection();
142142
const library = this.getLibrary(connection);
143143

144-
if (currentJob && library) {
144+
if (library) {
145145
const checks = statements.map(stmt => `select * from table(${library}.${this.functionName}(?)) x`).join(` union all `);
146146
const stmt = currentJob.job.query<SqlCheckError>(checks, {parameters: statements});
147147
const result = await stmt.execute(statements.length);

src/language/providers/completionProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ export const completionProvider = languages.registerCompletionItemProvider(
611611
allItems.push(...getLocalDefs(sqlDoc, offset))
612612
}
613613

614-
if (remoteAssistIsEnabled() && currentStatement) {
614+
if (remoteAssistIsEnabled(false) && currentStatement) {
615615
allItems.push(...await getCompletionItems(trigger, currentStatement, offset))
616616
}
617617

src/language/providers/hoverProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const openProvider = workspace.onDidOpenTextDocument(async (document) =>
6060

6161
export const hoverProvider = languages.registerHoverProvider({ language: `sql` }, {
6262
async provideHover(document, position, token) {
63-
if (!remoteAssistIsEnabled()) return;
63+
if (!remoteAssistIsEnabled(true)) return;
6464

6565
const defaultSchema = getDefaultSchema();
6666
const sqlDoc = getSqlDocument(document);

src/language/providers/logic/available.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@
22
import { env } from "process";
33
import { ServerComponent } from "../../../connection/serverComponent";
44
import { JobManager } from "../../../config";
5+
import { JobInfo } from "../../../connection/manager";
56

67
export function localAssistIsEnabled() {
78
return (env.DB2I_DISABLE_CA !== `true`);
89
}
910

10-
export function remoteAssistIsEnabled() {
11-
return localAssistIsEnabled() && ServerComponent.isInstalled() && JobManager.getSelection() !== undefined;
11+
export function remoteAssistIsEnabled(needsToBeReady?: boolean): JobInfo|undefined {
12+
if (!localAssistIsEnabled()) return;
13+
if (!ServerComponent.isInstalled()) return;
14+
15+
const selection = JobManager.getSelection();
16+
if (!selection) return;
17+
if (selection.job.getStatus() !== `ready` && needsToBeReady) return;
18+
19+
return selection;
1220
}

src/language/providers/parameterProvider.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ import { getSqlDocument } from "./logic/parse";
1111

1212
export const signatureProvider = languages.registerSignatureHelpProvider({ language: `sql` }, {
1313
async provideSignatureHelp(document, position, token, context) {
14-
const content = document.getText();
1514
const offset = document.offsetAt(position);
16-
15+
1716
if (remoteAssistIsEnabled()) {
1817

1918
const sqlDoc = getSqlDocument(document);

src/language/providers/problemProvider.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { commands, CompletionItemKind, Diagnostic, DiagnosticSeverity, languages, ProgressLocation, Range, TextDocument, Uri, window, workspace } from "vscode";
1+
import { commands, CompletionItemKind, Diagnostic, Disposable, DiagnosticSeverity, languages, ProgressLocation, Range, TextDocument, Uri, window, workspace } from "vscode";
22
import {
33
SQLType,
44
} from "../../database/schemas";
@@ -58,9 +58,7 @@ export function setCheckerAvailableContext(additionalState = true) {
5858
commands.executeCommand(`setContext`, CHECKER_AVAILABLE_CONTEXT, available);
5959
}
6060

61-
let checkerRunning = false;
6261
export function setCheckerRunningContext(isRunning: boolean) {
63-
checkerRunning = isRunning;
6462
commands.executeCommand(`setContext`, CHECKER_RUNNING_CONTEXT, isRunning);
6563
}
6664

@@ -73,7 +71,9 @@ export const checkDocumentDefintion = commands.registerCommand(CHECK_DOCUMENT_CO
7371
}
7472
});
7573

76-
export const problemProvider = [
74+
export const problemProvider: Disposable[] = [
75+
sqlDiagnosticCollection,
76+
7777
workspace.onDidCloseTextDocument(e => {
7878
// Only clear errors from unsaved files.
7979
if (e.isUntitled) {
@@ -120,7 +120,8 @@ interface SqlDiagnostic extends Diagnostic {
120120

121121
async function validateSqlDocument(document: TextDocument, specificStatement?: number) {
122122
const checker = SQLStatementChecker.get();
123-
if (remoteAssistIsEnabled() && checker && !checkerRunning) {
123+
const job = remoteAssistIsEnabled(true);
124+
if (checker && job) {
124125
const basename = document.fileName ? path.basename(document.fileName) : `Untitled`;
125126
if (isSafeDocument(document)) {
126127
setCheckerRunningContext(true);
@@ -181,7 +182,7 @@ async function validateSqlDocument(document: TextDocument, specificStatement?: n
181182

182183
let syntaxChecked: SqlSyntaxError[] | undefined;
183184
try {
184-
syntaxChecked = await window.withProgress({ location: ProgressLocation.Window, title: `$(sync-spin) Checking SQL Syntax` }, () => { return checker.checkMultipleStatements(sqlStatementContents) });
185+
syntaxChecked = await window.withProgress({ location: ProgressLocation.Window, title: `$(sync-spin) Checking SQL Syntax` }, () => { return checker.checkMultipleStatements(job, sqlStatementContents) });
185186
} catch (e) {
186187
window.showErrorMessage(`${basename}: the SQL syntax checker failed to run. ${e.message}`);
187188
syntaxChecked = undefined;

src/views/results/contributes.json

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@
5151
"category": "Db2 for i",
5252
"icon": "$(window)"
5353
},
54+
{
55+
"command": "vscode-db2i.runEditorStatement.multiple.all",
56+
"title": "Run all statements",
57+
"category": "Db2 for i"
58+
},
59+
{
60+
"command": "vscode-db2i.runEditorStatement.multiple.selected",
61+
"title": "Run selected statements",
62+
"category": "Db2 for i"
63+
},
64+
{
65+
"command": "vscode-db2i.runEditorStatement.multiple.from",
66+
"title": "Run statements from cursor",
67+
"category": "Db2 for i"
68+
},
5469
{
5570
"command": "vscode-db2i.statement.cancel",
5671
"title": "Cancel",
@@ -111,22 +126,37 @@
111126
{
112127
"command": "vscode-db2i.runEditorStatement.inView",
113128
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true",
114-
"group": "navigation@1"
129+
"group": "navigation@2"
130+
},
131+
{
132+
"command": "vscode-db2i.runEditorStatement.multiple.all",
133+
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true",
134+
"group": "navigation_multiple@1"
135+
},
136+
{
137+
"command": "vscode-db2i.runEditorStatement.multiple.selected",
138+
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true && editorHasSelection",
139+
"group": "navigation_multiple@2"
140+
},
141+
{
142+
"command": "vscode-db2i.runEditorStatement.multiple.from",
143+
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true && !editorHasSelection",
144+
"group": "navigation_multiple@2"
115145
},
116146
{
117147
"command": "vscode-db2i.editorExplain.withRun",
118148
"when": "editorLangId == sql",
119-
"group": "2_explain@1"
149+
"group": "navigation_explain@1"
120150
},
121151
{
122152
"command": "vscode-db2i.editorExplain.withoutRun",
123153
"when": "editorLangId == sql",
124-
"group": "2_explain@2"
154+
"group": "navigation_explain@2"
125155
},
126156
{
127157
"command": "vscode-db2i.notebook.fromSqlUri",
128158
"when": "editorLangId == sql",
129-
"group": "3_notebook@1"
159+
"group": "navigation_notebook@1"
130160
}
131161
],
132162
"view/title": [

0 commit comments

Comments
 (0)