Skip to content

Only run certain features when job is ready #354

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

Merged
merged 1 commit into from
Mar 17, 2025
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
6 changes: 3 additions & 3 deletions src/connection/syntaxChecker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { posix } from "path";
import { getValidatorSource, VALIDATOR_NAME, WRAPPER_NAME } from "./checker";
import { JobManager } from "../../config";
import { getBase, getInstance } from "../../base";
import { JobInfo } from "../manager";

interface SqlCheckError {
CURSTMTLENGTH: number;
Expand Down Expand Up @@ -134,14 +135,13 @@ export class SQLStatementChecker implements IBMiComponent {
return undefined;
}

async checkMultipleStatements(statements: string[]): Promise<SqlSyntaxError[]|undefined> {
async checkMultipleStatements(currentJob: JobInfo, statements: string[]): Promise<SqlSyntaxError[]|undefined> {
const connection = getInstance()?.getConnection();
if (!connection) return undefined;

const currentJob = JobManager.getSelection();
const library = this.getLibrary(connection);

if (currentJob && library) {
if (library) {
const checks = statements.map(stmt => `select * from table(${library}.${this.functionName}(?)) x`).join(` union all `);
const stmt = currentJob.job.query<SqlCheckError>(checks, {parameters: statements});
const result = await stmt.execute(statements.length);
Expand Down
2 changes: 1 addition & 1 deletion src/language/providers/completionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ export const completionProvider = languages.registerCompletionItemProvider(
allItems.push(...getLocalDefs(sqlDoc, offset))
}

if (remoteAssistIsEnabled() && currentStatement) {
if (remoteAssistIsEnabled(false) && currentStatement) {
allItems.push(...await getCompletionItems(trigger, currentStatement, offset))
}

Expand Down
2 changes: 1 addition & 1 deletion src/language/providers/hoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const openProvider = workspace.onDidOpenTextDocument(async (document) =>

export const hoverProvider = languages.registerHoverProvider({ language: `sql` }, {
async provideHover(document, position, token) {
if (!remoteAssistIsEnabled()) return;
if (!remoteAssistIsEnabled(true)) return;

const defaultSchema = getDefaultSchema();
const sqlDoc = getSqlDocument(document);
Expand Down
12 changes: 10 additions & 2 deletions src/language/providers/logic/available.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@
import { env } from "process";
import { ServerComponent } from "../../../connection/serverComponent";
import { JobManager } from "../../../config";
import { JobInfo } from "../../../connection/manager";

export function localAssistIsEnabled() {
return (env.DB2I_DISABLE_CA !== `true`);
}

export function remoteAssistIsEnabled() {
return localAssistIsEnabled() && ServerComponent.isInstalled() && JobManager.getSelection() !== undefined;
export function remoteAssistIsEnabled(needsToBeReady?: boolean): JobInfo|undefined {
if (!localAssistIsEnabled()) return;
if (!ServerComponent.isInstalled()) return;

const selection = JobManager.getSelection();
if (!selection) return;
if (selection.job.getStatus() !== `ready` && needsToBeReady) return;

return selection;
}
3 changes: 1 addition & 2 deletions src/language/providers/parameterProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import { getSqlDocument } from "./logic/parse";

export const signatureProvider = languages.registerSignatureHelpProvider({ language: `sql` }, {
async provideSignatureHelp(document, position, token, context) {
const content = document.getText();
const offset = document.offsetAt(position);

if (remoteAssistIsEnabled()) {

const sqlDoc = getSqlDocument(document);
Expand Down
7 changes: 3 additions & 4 deletions src/language/providers/problemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ export function setCheckerAvailableContext(additionalState = true) {
commands.executeCommand(`setContext`, CHECKER_AVAILABLE_CONTEXT, available);
}

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

Expand Down Expand Up @@ -120,7 +118,8 @@ interface SqlDiagnostic extends Diagnostic {

async function validateSqlDocument(document: TextDocument, specificStatement?: number) {
const checker = SQLStatementChecker.get();
if (remoteAssistIsEnabled() && checker && !checkerRunning) {
const job = remoteAssistIsEnabled(true);
if (checker && job) {
const basename = document.fileName ? path.basename(document.fileName) : `Untitled`;
if (isSafeDocument(document)) {
setCheckerRunningContext(true);
Expand Down Expand Up @@ -181,7 +180,7 @@ async function validateSqlDocument(document: TextDocument, specificStatement?: n

let syntaxChecked: SqlSyntaxError[] | undefined;
try {
syntaxChecked = await window.withProgress({ location: ProgressLocation.Window, title: `$(sync-spin) Checking SQL Syntax` }, () => { return checker.checkMultipleStatements(sqlStatementContents) });
syntaxChecked = await window.withProgress({ location: ProgressLocation.Window, title: `$(sync-spin) Checking SQL Syntax` }, () => { return checker.checkMultipleStatements(job, sqlStatementContents) });
} catch (e) {
window.showErrorMessage(`${basename}: the SQL syntax checker failed to run. ${e.message}`);
syntaxChecked = undefined;
Expand Down
Loading