Skip to content

Commit 9637530

Browse files
committed
Merge branch 'main' into chatai
2 parents 67cf28b + 058a62e commit 9637530

File tree

6 files changed

+166
-64
lines changed

6 files changed

+166
-64
lines changed

package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,12 @@
361361
"mac": "cmd+r",
362362
"when": "editorLangId == sql && resourceExtname != .inb"
363363
},
364+
{
365+
"command": "vscode-db2i.runEditorStatement.inView",
366+
"key": "ctrl+alt+r",
367+
"mac": "cmd+ctrl+r",
368+
"when": "editorLangId == sql"
369+
},
364370
{
365371
"command": "vscode-db2i.editorExplain.withRun",
366372
"key": "ctrl+shift+r",
@@ -526,6 +532,12 @@
526532
"category": "Db2 for i",
527533
"icon": "$(notebook-execute)"
528534
},
535+
{
536+
"command": "vscode-db2i.runEditorStatement.inView",
537+
"title": "Run statement in new view",
538+
"category": "Db2 for i",
539+
"icon": "$(window)"
540+
},
529541
{
530542
"command": "vscode-db2i.statement.cancel",
531543
"title": "Cancel",
@@ -835,6 +847,11 @@
835847
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true",
836848
"group": "navigation@1"
837849
},
850+
{
851+
"command": "vscode-db2i.runEditorStatement.inView",
852+
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true",
853+
"group": "navigation@1"
854+
},
838855
{
839856
"command": "vscode-db2i.editorExplain.withRun",
840857
"when": "editorLangId == sql",

src/connection/manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ export class SQLJobManager {
9494
return this.jobs;
9595
}
9696

97-
getJob(name: string): JobInfo | undefined {
98-
return this.jobs.find(info => info.name === name);
97+
getJob(nameOrId: string): JobInfo | undefined {
98+
return this.jobs.find(info => info.name === nameOrId || info.job.id === nameOrId);
9999
}
100100

101101
setSelection(selectedName: string): JobInfo|undefined {

src/views/html.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ export function getHeader(options: {withCollapsed?: boolean} = {}): string {
6767
min-height: 100vh;
6868
}
6969
70+
.primaryButton {
71+
background-color: var(--vscode-button-background);
72+
color: var(--vscode-button-foreground);
73+
border: none;
74+
border-radius: 5px;
75+
padding: 5px 10px;
76+
cursor: pointer;
77+
}
78+
7079
/* https://cssloaders.github.io */
7180
.loader {
7281
width: 32px;

src/views/results/html.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function getLoadingHTML(): string {
3838
`;
3939
}
4040

41-
export function generateScroller(basicSelect: string, isCL: boolean): string {
41+
export function generateScroller(basicSelect: string, isCL: boolean, withCancel?: boolean): string {
4242
const withCollapsed = Configuration.get<boolean>('collapsedResultSet');
4343

4444
return /*html*/`
@@ -121,6 +121,17 @@ export function generateScroller(basicSelect: string, isCL: boolean): string {
121121
break;
122122
}
123123
});
124+
125+
const cancelButton = document.getElementById('cancelButton');
126+
127+
if (cancelButton) {
128+
cancelButton.addEventListener('click', () => {
129+
vscode.postMessage({
130+
command: 'cancel',
131+
queryId: myQueryId
132+
});
133+
});
134+
}
124135
}
125136
126137
function fetchNextPage() {
@@ -206,6 +217,7 @@ export function generateScroller(basicSelect: string, isCL: boolean): string {
206217
<div id="spinnerContent" class="center-screen">
207218
<p id="loadingText">Running statement</p>
208219
<span class="loader"></span>
220+
${withCancel ? `<button id="cancelButton" class="primaryButton">Cancel</button>` : ``}
209221
</div>
210222
</body>
211223
</html>

src/views/results/index.ts

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import vscode, { SnippetString, ViewColumn, TreeView } from "vscode"
1+
import vscode, { SnippetString, ViewColumn, TreeView, window } from "vscode"
22

33
import * as csv from "csv/sync";
44

@@ -57,8 +57,8 @@ export function initialise(context: vscode.ExtensionContext) {
5757
webviewOptions: { retainContextWhenHidden: true },
5858
}),
5959

60-
vscode.commands.registerCommand(`vscode-db2i.statement.cancel`, async () => {
61-
const selected = JobManager.getSelection();
60+
vscode.commands.registerCommand(`vscode-db2i.statement.cancel`, async (jobName?: string) => {
61+
const selected = typeof jobName === `string` ? JobManager.getJob(jobName) : JobManager.getSelection();
6262
if (selected) {
6363
updateStatusBar({canceling: true});
6464
const cancelled = await selected.job.requestCancel();
@@ -141,11 +141,16 @@ export function initialise(context: vscode.ExtensionContext) {
141141

142142
vscode.commands.registerCommand(`vscode-db2i.editorExplain.withRun`, (options?: StatementInfo) => { runHandler({ qualifier: `explain`, ...options }) }),
143143
vscode.commands.registerCommand(`vscode-db2i.editorExplain.withoutRun`, (options?: StatementInfo) => { runHandler({ qualifier: `onlyexplain`, ...options }) }),
144+
vscode.commands.registerCommand(`vscode-db2i.runEditorStatement.inView`, (options?: StatementInfo) => { runHandler({ viewColumn: ViewColumn.Beside, ...options }) }),
144145
vscode.commands.registerCommand(`vscode-db2i.runEditorStatement`, (options?: StatementInfo) => { runHandler(options) })
145146
)
146147
}
147148

148149
async function runHandler(options?: StatementInfo) {
150+
if (options === undefined || options.viewColumn === undefined) {
151+
await resultSetProvider.ensureActivation();
152+
}
153+
149154
// Options here can be a vscode.Uri when called from editor context.
150155
// But that isn't valid here.
151156
const optionsIsValid = (options?.content !== undefined);
@@ -154,7 +159,13 @@ async function runHandler(options?: StatementInfo) {
154159
vscode.commands.executeCommand('vscode-db2i.dove.close');
155160

156161
if (optionsIsValid || (editor && editor.document.languageId === `sql`)) {
157-
await resultSetProvider.ensureActivation();
162+
let chosenView = resultSetProvider;
163+
164+
const useWindow = (title: string, column?: ViewColumn) => {
165+
const webview = window.createWebviewPanel(`sqlResultSet`, title, column || ViewColumn.Two, {retainContextWhenHidden: true, enableScripts: true, enableFindWidget: true});
166+
chosenView = new ResultSetPanelProvider();
167+
chosenView.resolveWebviewView(webview);
168+
}
158169

159170
const statementDetail = parseStatement(editor, optionsIsValid ? options : undefined);
160171

@@ -178,10 +189,15 @@ async function runHandler(options?: StatementInfo) {
178189
}
179190

180191
const statement = statementDetail.statement;
192+
const refs = statement.getObjectReferences();
193+
const ref = refs[0];
194+
195+
let possibleTitle = `SQL Results`;
196+
if (ref && ref.object.name) {
197+
possibleTitle = (ref.object.schema ? ref.object.schema + `.` : ``) + ref.object.name;
198+
}
181199

182200
if (statement.type === StatementType.Create || statement.type === StatementType.Alter) {
183-
const refs = statement.getObjectReferences();
184-
const ref = refs[0];
185201
const databaseObj =
186202
statement.type === StatementType.Create && ref.createType.toUpperCase() === `schema`
187203
? ref.object.schema || ``
@@ -191,29 +207,38 @@ async function runHandler(options?: StatementInfo) {
191207

192208
if (statementDetail.content.trim().length > 0) {
193209
try {
210+
const inWindow = Boolean(options && options.viewColumn);
211+
194212
if (statementDetail.qualifier === `cl`) {
195-
resultSetProvider.setScrolling(statementDetail.content, true); // Never errors
213+
if (inWindow) {
214+
useWindow(`CL results`, options.viewColumn);
215+
}
216+
chosenView.setScrolling(statementDetail.content, true); // Never errors
217+
196218
} else if (statementDetail.qualifier === `statement`) {
197219
// If it's a basic statement, we can let it scroll!
198-
resultSetProvider.setScrolling(statementDetail.content); // Never errors
220+
if (inWindow) {
221+
useWindow(possibleTitle, options.viewColumn);
222+
}
223+
chosenView.setScrolling(statementDetail.content, false, undefined, inWindow); // Never errors
199224

200225
} else if ([`explain`, `onlyexplain`].includes(statementDetail.qualifier)) {
201226
// If it's an explain, we need to
202227
const selectedJob = JobManager.getSelection();
203228
if (selectedJob) {
204229
const onlyExplain = statementDetail.qualifier === `onlyexplain`;
205230

206-
resultSetProvider.setLoadingText(onlyExplain ? `Explaining without running...` : `Explaining...`);
231+
chosenView.setLoadingText(onlyExplain ? `Explaining without running...` : `Explaining...`);
207232
const explainType: ExplainType = onlyExplain ? ExplainType.DoNotRun : ExplainType.Run;
208233

209234
setCancelButtonVisibility(true);
210235
const explained = await selectedJob.job.explain(statementDetail.content, explainType); // Can throw
211236
setCancelButtonVisibility(false);
212237

213238
if (onlyExplain) {
214-
resultSetProvider.setLoadingText(`Explained.`, false);
239+
chosenView.setLoadingText(`Explained.`, false);
215240
} else {
216-
resultSetProvider.setScrolling(statementDetail.content, false, explained.id); // Never errors
241+
chosenView.setScrolling(statementDetail.content, false, explained.id); // Never errors
217242
}
218243

219244
explainTree = new ExplainTree(explained.vedata);
@@ -226,7 +251,7 @@ async function runHandler(options?: StatementInfo) {
226251
}
227252
} else {
228253
// Otherwise... it's a bit complicated.
229-
resultSetProvider.setLoadingText(`Executing SQL statement...`, false);
254+
chosenView.setLoadingText(`Executing SQL statement...`, false);
230255

231256
setCancelButtonVisibility(true);
232257
updateStatusBar({executing: true});
@@ -279,13 +304,13 @@ async function runHandler(options?: StatementInfo) {
279304

280305
const textDoc = await vscode.workspace.openTextDocument({ language: statementDetail.qualifier, content });
281306
await vscode.window.showTextDocument(textDoc);
282-
resultSetProvider.setLoadingText(`Query executed with ${data.length} rows returned.`, false);
307+
chosenView.setLoadingText(`Query executed with ${data.length} rows returned.`, false);
283308
break;
284309
}
285310

286311
} else {
287312
vscode.window.showInformationMessage(`Statement executed with no data returned.`);
288-
resultSetProvider.setLoadingText(`Statement executed with no data returned.`);
313+
chosenView.setLoadingText(`Statement executed with no data returned.`);
289314
}
290315
}
291316

@@ -304,7 +329,7 @@ async function runHandler(options?: StatementInfo) {
304329
}
305330

306331
if ([`statement`, `explain`, `onlyexplain`].includes(statementDetail.qualifier) && statementDetail.history !== false) {
307-
resultSetProvider.setError(errorText);
332+
chosenView.setError(errorText);
308333
} else {
309334
vscode.window.showErrorMessage(errorText);
310335
}

0 commit comments

Comments
 (0)