Skip to content

Commit

Permalink
DA#302: Added: Save document while running the Query
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushTyagi1 committed Oct 4, 2023
1 parent 5caad37 commit e0323c4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 41 deletions.
72 changes: 36 additions & 36 deletions src/commands/queryHistory/applyQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
9 changes: 4 additions & 5 deletions src/workbench/queryWorkbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -125,7 +124,7 @@ export class QueryWorkbench {
null
);
}

activeTextEditor?.document.save();
}
};

Expand Down

0 comments on commit e0323c4

Please sign in to comment.