From 00edbf070f0c0c50efc074b53ee0e62cc8cc49f5 Mon Sep 17 00:00:00 2001 From: AayushTyagi1 Date: Wed, 4 Oct 2023 15:04:45 +0530 Subject: [PATCH 1/5] DA#239: BugFix: Fix terminal change issue --- src/workbench/queryWorkbench.ts | 4 ++-- src/workbench/workbenchWebviewProvider.ts | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/workbench/queryWorkbench.ts b/src/workbench/queryWorkbench.ts index 49e00665..c22456f1 100644 --- a/src/workbench/queryWorkbench.ts +++ b/src/workbench/queryWorkbench.ts @@ -77,7 +77,7 @@ export class QueryWorkbench { size: resultSize ? (resultSize > 1000 ? (resultSize / 1000).toFixed(2) + " KB" : resultSize + " Bytes") : "" }; const explainPlan = JSON.stringify(result?.meta.profile.executionTimings); - await workbenchWebviewProvider.setQueryResult( + workbenchWebviewProvider.setQueryResult( JSON.stringify(result?.rows), queryStatusProps, explainPlan @@ -118,7 +118,7 @@ export class QueryWorkbench { numDocs: "-", size: "-", }; - await workbenchWebviewProvider.setQueryResult( + workbenchWebviewProvider.setQueryResult( JSON.stringify(errorArray), queryStatusProps, null diff --git a/src/workbench/workbenchWebviewProvider.ts b/src/workbench/workbenchWebviewProvider.ts index 477c2732..6aeab6df 100644 --- a/src/workbench/workbenchWebviewProvider.ts +++ b/src/workbench/workbenchWebviewProvider.ts @@ -47,7 +47,6 @@ export class WorkbenchWebviewProvider implements vscode.WebviewViewProvider { this._view.webview.html = getWebviewContent(reactAppUri, this._context); const isDarkTheme: boolean = vscode.window.activeColorTheme.kind === vscode.ColorThemeKind.Dark; this._view?.webview.postMessage({ command: "theme", isDarkTheme }); - this._view?.onDidDispose(() => Memory.state.update(Constants.QUERY_RESULT, null)); this._view?.onDidChangeVisibility(() => { if (Memory.state.get(Constants.QUERY_RESULT)) { this.sendQueryResult(JSON.stringify([{ "status": "Loading last executed result" }]), { queryStatus: QueryStatus.Running }, null); From 0e660124b8dc4c3a7e933f233815633b6da80c34 Mon Sep 17 00:00:00 2001 From: AayushTyagi1 Date: Wed, 4 Oct 2023 15:08:13 +0530 Subject: [PATCH 2/5] DA#239: BugFix: Fix Index with # issue --- src/commands/indexes/openIndexInformation.ts | 32 ++++++++++---------- src/model/IndexDirectory.ts | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/commands/indexes/openIndexInformation.ts b/src/commands/indexes/openIndexInformation.ts index 691f980e..f2d30c00 100644 --- a/src/commands/indexes/openIndexInformation.ts +++ b/src/commands/indexes/openIndexInformation.ts @@ -19,20 +19,20 @@ import { MemFS } from "../../util/fileSystemProvider"; import IndexNode from "../../model/IndexNode"; export const openIndexInfo = async (indexNode: IndexNode, memFs: MemFS) => { - try { - const uri = vscode.Uri.parse( - `couchbase:/${indexNode.bucketName}/${indexNode.scopeName}/Indexes/${indexNode.indexName}.n1ql` - ); - memFs.writeFile( - uri, - Buffer.from(indexNode.data), - { create: true, overwrite: true } - ); - const document = await vscode.workspace.openTextDocument(uri); - await vscode.window.showTextDocument(document, { preview: false }); - return true; - } catch (err: any) { - logger.error("Failed to open index information"); - logger.debug(err); - } + try { + const uri = vscode.Uri.parse( + `couchbase:/${indexNode.bucketName}/${indexNode.scopeName}/Indexes/${indexNode.indexName}.sqlpp` + ); + memFs.writeFile( + uri, + Buffer.from(indexNode.data), + { create: true, overwrite: true } + ); + const document = await vscode.workspace.openTextDocument(uri); + await vscode.window.showTextDocument(document, { preview: false }); + return true; + } catch (err: any) { + logger.error("Failed to open index information"); + logger.debug(err); + } }; diff --git a/src/model/IndexDirectory.ts b/src/model/IndexDirectory.ts index 8e26186d..0e392c64 100644 --- a/src/model/IndexDirectory.ts +++ b/src/model/IndexDirectory.ts @@ -83,7 +83,7 @@ export class IndexDirectory implements INode { this.connection, this.scopeName, this.bucketName, - `${query.name.substring(1)}_${(query.collectionName ?? "")}`, + `${query.name[0] === '#' ? query.name.substring(1) : query.name}${(query.collectionName ? ("_" + query.collectionName) : "")}`, getIndexDefinition(query), vscode.TreeItemCollapsibleState.None ); From 5caad37f521de86c343edd4f012242e5bd1d17d7 Mon Sep 17 00:00:00 2001 From: AayushTyagi1 Date: Wed, 4 Oct 2023 17:18:11 +0530 Subject: [PATCH 3/5] DA#302: Added: Save document while running the Query --- src/commands/queryHistory/applyQuery.ts | 1 + src/workbench/controller.ts | 3 ++- src/workbench/queryWorkbench.ts | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/commands/queryHistory/applyQuery.ts b/src/commands/queryHistory/applyQuery.ts index 0b1958f3..43dbab8c 100644 --- a/src/commands/queryHistory/applyQuery.ts +++ b/src/commands/queryHistory/applyQuery.ts @@ -12,6 +12,7 @@ export const applyQuery = async (query: IQuery) => { return; } const activeTextEditor = vscode.window.activeTextEditor; + activeTextEditor?.document.save(); if ( activeTextEditor && activeTextEditor.document.languageId === "SQL++" diff --git a/src/workbench/controller.ts b/src/workbench/controller.ts index 091f0b2a..6d9a0c3c 100644 --- a/src/workbench/controller.ts +++ b/src/workbench/controller.ts @@ -57,8 +57,9 @@ export default class UntitledSqlppDocumentService { }); const document = await vscode.workspace.openTextDocument(uri); + document.save(); await vscode.window.showTextDocument(document, { preview: false }); - return vscode.workspace.openTextDocument(uri); + return document; } /** diff --git a/src/workbench/queryWorkbench.ts b/src/workbench/queryWorkbench.ts index c22456f1..f73f5db0 100644 --- a/src/workbench/queryWorkbench.ts +++ b/src/workbench/queryWorkbench.ts @@ -47,6 +47,7 @@ export class QueryWorkbench { } // Get the active text editor const activeTextEditor = vscode.window.activeTextEditor; + activeTextEditor?.document.save(); if (activeTextEditor && activeTextEditor.document.languageId === "SQL++") { // Get the text content of the active text editor. const query = activeTextEditor.selection.isEmpty ? activeTextEditor.document.getText() : activeTextEditor.document.getText(activeTextEditor.selection); From e0323c45fbf88ec08053b14eb5bbef1465948443 Mon Sep 17 00:00:00 2001 From: AayushTyagi1 Date: Wed, 4 Oct 2023 18:44:51 +0530 Subject: [PATCH 4/5] DA#302: Added: Save document while running the Query --- src/commands/queryHistory/applyQuery.ts | 72 ++++++++++++------------- src/workbench/queryWorkbench.ts | 9 ++-- 2 files changed, 40 insertions(+), 41 deletions(-) diff --git a/src/commands/queryHistory/applyQuery.ts b/src/commands/queryHistory/applyQuery.ts index 43dbab8c..52c1a554 100644 --- a/src/commands/queryHistory/applyQuery.ts +++ b/src/commands/queryHistory/applyQuery.ts @@ -12,46 +12,46 @@ export const applyQuery = async (query: IQuery) => { return; } const activeTextEditor = vscode.window.activeTextEditor; - activeTextEditor?.document.save(); - if ( - activeTextEditor && - activeTextEditor.document.languageId === "SQL++" - ){ - activeTextEditor.edit((editBuilder)=>{ - editBuilder.replace( - new vscode.Range(0, 0, activeTextEditor.document.lineCount, 0), - query.query // Replace the entire content with the query - ); - }); - } else { - await vscode.commands.executeCommand(Commands.openQueryWorkbench); - // Wait for editor to become active, If exceeds 3 seconds, then error is thrown - let timeElapsed = 0; // in ms - let timeInterval = 200; // in ms - let totalTime = 3000; //in ms - while (true) { - await new Promise(resolve => setTimeout(resolve, timeInterval)); + if ( + activeTextEditor && + activeTextEditor.document.languageId === "SQL++" + ) { + activeTextEditor.edit((editBuilder) => { + editBuilder.replace( + new vscode.Range(0, 0, activeTextEditor.document.lineCount, 0), + query.query // Replace the entire content with the query + ); + }); + } else { + await vscode.commands.executeCommand(Commands.openQueryWorkbench); + // Wait for editor to become active, If exceeds 3 seconds, then error is thrown + let timeElapsed = 0; // in ms + let timeInterval = 200; // in ms + let totalTime = 3000; //in ms + while (true) { + await new Promise(resolve => setTimeout(resolve, timeInterval)); + + let newActiveTextEditor = vscode.window.activeTextEditor; - let newActiveTextEditor = vscode.window.activeTextEditor; + if (newActiveTextEditor && newActiveTextEditor.document.languageId === "SQL++") { + let lineCount = newActiveTextEditor.document.lineCount; + newActiveTextEditor.edit((editBuilder) => { + editBuilder.replace( + new vscode.Range(0, 0, lineCount, 0), + query.query - if (newActiveTextEditor && newActiveTextEditor.document.languageId === "SQL++") { - let lineCount = newActiveTextEditor.document.lineCount; - newActiveTextEditor.edit((editBuilder)=>{ - editBuilder.replace( - new vscode.Range(0, 0, lineCount, 0), - query.query - - ); - }); - break; - } + ); + }); + break; + } - timeElapsed += timeInterval; + timeElapsed += timeInterval; - if (timeElapsed >= totalTime) { - vscode.window.showErrorMessage("Unable to open workbench with selected query"); - return; - } + if (timeElapsed >= totalTime) { + vscode.window.showErrorMessage("Unable to open workbench with selected query"); + return; } } + } + activeTextEditor?.document.save(); }; \ No newline at end of file diff --git a/src/workbench/queryWorkbench.ts b/src/workbench/queryWorkbench.ts index f73f5db0..dd4d2b19 100644 --- a/src/workbench/queryWorkbench.ts +++ b/src/workbench/queryWorkbench.ts @@ -47,7 +47,6 @@ export class QueryWorkbench { } // Get the active text editor const activeTextEditor = vscode.window.activeTextEditor; - activeTextEditor?.document.save(); if (activeTextEditor && activeTextEditor.document.languageId === "SQL++") { // Get the text content of the active text editor. const query = activeTextEditor.selection.isEmpty ? activeTextEditor.document.getText() : activeTextEditor.document.getText(activeTextEditor.selection); @@ -86,9 +85,9 @@ export class QueryWorkbench { await saveQuery({ query: query, id: getUUID() }); queryHistoryTreeProvider.refresh(); let timeWait = result?.meta.metrics?.resultSize || 0; - - await new Promise((resolve)=>{ - setTimeout(resolve,(timeWait/10000)); + + await new Promise((resolve) => { + setTimeout(resolve, (timeWait / 10000)); }); } catch (err) { const errorArray = []; @@ -125,7 +124,7 @@ export class QueryWorkbench { null ); } - + activeTextEditor?.document.save(); } }; From 9dcd2862777386c05e5c7c5bcb2840bd91adfd4c Mon Sep 17 00:00:00 2001 From: AayushTyagi1 Date: Wed, 4 Oct 2023 19:08:23 +0530 Subject: [PATCH 5/5] DA#302: Added: Save document while running the Query --- src/commands/queryHistory/applyQuery.ts | 6 ++---- src/workbench/queryWorkbench.ts | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/commands/queryHistory/applyQuery.ts b/src/commands/queryHistory/applyQuery.ts index 52c1a554..17bf4b28 100644 --- a/src/commands/queryHistory/applyQuery.ts +++ b/src/commands/queryHistory/applyQuery.ts @@ -22,6 +22,7 @@ export const applyQuery = async (query: IQuery) => { query.query // Replace the entire content with the query ); }); + activeTextEditor.document.save(); } else { await vscode.commands.executeCommand(Commands.openQueryWorkbench); // Wait for editor to become active, If exceeds 3 seconds, then error is thrown @@ -30,18 +31,16 @@ export const applyQuery = async (query: IQuery) => { let totalTime = 3000; //in ms while (true) { await new Promise(resolve => setTimeout(resolve, timeInterval)); - let newActiveTextEditor = vscode.window.activeTextEditor; - if (newActiveTextEditor && newActiveTextEditor.document.languageId === "SQL++") { let lineCount = newActiveTextEditor.document.lineCount; newActiveTextEditor.edit((editBuilder) => { editBuilder.replace( new vscode.Range(0, 0, lineCount, 0), query.query - ); }); + newActiveTextEditor.document.save(); break; } @@ -53,5 +52,4 @@ export const applyQuery = async (query: IQuery) => { } } } - activeTextEditor?.document.save(); }; \ No newline at end of file diff --git a/src/workbench/queryWorkbench.ts b/src/workbench/queryWorkbench.ts index dd4d2b19..a8cdcedc 100644 --- a/src/workbench/queryWorkbench.ts +++ b/src/workbench/queryWorkbench.ts @@ -49,6 +49,7 @@ export class QueryWorkbench { const activeTextEditor = vscode.window.activeTextEditor; if (activeTextEditor && activeTextEditor.document.languageId === "SQL++") { // Get the text content of the active text editor. + activeTextEditor.document.save(); const query = activeTextEditor.selection.isEmpty ? activeTextEditor.document.getText() : activeTextEditor.document.getText(activeTextEditor.selection); const queryContext = this.editorToContext.get(activeTextEditor.document.uri.toString()); const queryContextString = queryContext && (`${queryContext?.bucketName}.${queryContext?.scopeName}`); // Query context string is of format bucketName.ScopeName @@ -124,7 +125,6 @@ export class QueryWorkbench { null ); } - activeTextEditor?.document.save(); } };