Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Da#302 testing fixes in terminal change indexes problem and workbench save issue #303

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/commands/indexes/openIndexInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
73 changes: 36 additions & 37 deletions src/commands/queryHistory/applyQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,44 @@ export const applyQuery = async (query: IQuery) => {
return;
}
const activeTextEditor = vscode.window.activeTextEditor;
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;

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;
}
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
);
});
activeTextEditor.document.save();
} 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;
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;
}

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;
}
}
}
};
2 changes: 1 addition & 1 deletion src/model/IndexDirectory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
3 changes: 2 additions & 1 deletion src/workbench/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/workbench/queryWorkbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -77,17 +78,17 @@ 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
);
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 @@ -118,13 +119,12 @@ export class QueryWorkbench {
numDocs: "-",
size: "-",
};
await workbenchWebviewProvider.setQueryResult(
workbenchWebviewProvider.setQueryResult(
JSON.stringify(errorArray),
queryStatusProps,
null
);
}

}
};

Expand Down
1 change: 0 additions & 1 deletion src/workbench/workbenchWebviewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IQueryResultProps>(Constants.QUERY_RESULT)) {
this.sendQueryResult(JSON.stringify([{ "status": "Loading last executed result" }]), { queryStatus: QueryStatus.Running }, null);
Expand Down