Skip to content

Commit

Permalink
Disable check button when checker is running
Browse files Browse the repository at this point in the history
Signed-off-by: worksofliam <[email protected]>
  • Loading branch information
worksofliam committed Dec 20, 2024
1 parent 73571da commit c616bff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@
"command": "vscode-db2i.syntax.checkDocument",
"title": "Check SQL syntax",
"category": "Db2 for IBM i",
"enablement": "code-for-ibmi:connected == true && vscode-db2i:jobManager.hasJob && vscode-db2i:statementCanCancel != true && vscode-db2i.syntax.checkerAvailable == true",
"enablement": "code-for-ibmi:connected == true && vscode-db2i:jobManager.hasJob && vscode-db2i:statementCanCancel != true && vscode-db2i.syntax.checkerAvailable == true && vscode-db2i.syntax.checkerRunning != true",
"icon": "$(check-all)"
}
],
Expand Down
2 changes: 1 addition & 1 deletion src/language/providers/contributes.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"command": "vscode-db2i.syntax.checkDocument",
"title": "Check SQL syntax",
"category": "Db2 for IBM i",
"enablement": "code-for-ibmi:connected == true && vscode-db2i:jobManager.hasJob && vscode-db2i:statementCanCancel != true && vscode-db2i.syntax.checkerAvailable == true",
"enablement": "code-for-ibmi:connected == true && vscode-db2i:jobManager.hasJob && vscode-db2i:statementCanCancel != true && vscode-db2i.syntax.checkerAvailable == true && vscode-db2i.syntax.checkerRunning != true",
"icon": "$(check-all)"
}
],
Expand Down
14 changes: 12 additions & 2 deletions src/language/providers/problemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,19 @@ function shouldShowWarnings() {
}

const CHECKER_AVAILABLE_CONTEXT = `vscode-db2i.syntax.checkerAvailable`;
const CHECKER_RUNNING_CONTEXT = `vscode-db2i.syntax.checkerRunning`;

export function setCheckerAvailableContext() {
const available = SQLStatementChecker.get() !== undefined;
commands.executeCommand(`setContext`, CHECKER_AVAILABLE_CONTEXT, available);
}

let checkerRunning = false;
export function setCheckerRunningContext(isRunning: boolean) {
checkerRunning = isRunning;
commands.executeCommand(`setContext`, CHECKER_RUNNING_CONTEXT, isRunning);
}

export const CHECK_DOCUMENT_COMMAND = `vscode-db2i.syntax.checkDocument`;
export const checkDocumentDefintion = commands.registerCommand(CHECK_DOCUMENT_COMMAND, async (uri?: Uri) => {
const document = uri ? (await workspace.openTextDocument(uri)) : window.activeTextEditor?.document;
Expand Down Expand Up @@ -89,7 +96,8 @@ interface SqlDiagnostic extends Diagnostic {

async function validateSqlDocument(document: TextDocument, specificStatement?: number) {
const checker = SQLStatementChecker.get();
if (remoteAssistIsEnabled() && checker) {
if (remoteAssistIsEnabled() && checker && !checkerRunning) {
setCheckerRunningContext(true);
const content = document.getText();
const sqlDocument = new Document(content);

Expand Down Expand Up @@ -162,7 +170,7 @@ async function validateSqlDocument(document: TextDocument, specificStatement?: n
severity: diagnosticTypeMap[groupError.type],
groupId: currentRange.groupId
};

if (existingError >= 0) {
currentErrors[existingError] = newDiag;
} else {
Expand All @@ -177,6 +185,8 @@ async function validateSqlDocument(document: TextDocument, specificStatement?: n
}
}
}

setCheckerRunningContext(false);
}

function shouldShowError(error: SqlSyntaxError) {
Expand Down

0 comments on commit c616bff

Please sign in to comment.