Skip to content

Commit

Permalink
Add status item for language state
Browse files Browse the repository at this point in the history
Signed-off-by: worksofliam <[email protected]>
  • Loading branch information
worksofliam committed Dec 18, 2024
1 parent 34d59d8 commit 79ffbc0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-db2i",
"displayName": "Db2 for IBM i",
"description": "Db2 for IBM i tools in VS Code",
"version": "1.7.0",
"version": "1.7.0-syntaxcheck2",
"engines": {
"vscode": "^1.95.0"
},
Expand Down
6 changes: 5 additions & 1 deletion src/language/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { formatProvider } from "./formatProvider";
import { hoverProvider, openProvider } from "./hoverProvider";
import { signatureProvider } from "./parameterProvider";
import { problemProvider } from "./problemProvider";
import { Db2StatusProvider } from "./statusProvider";

export const sqlLanguageStatus = new Db2StatusProvider();

export function languageInit() {
let functionality = [];
Expand All @@ -13,7 +16,8 @@ export function languageInit() {
signatureProvider,
hoverProvider,
openProvider,
problemProvider
problemProvider,
sqlLanguageStatus
);

return functionality;
Expand Down
4 changes: 2 additions & 2 deletions src/language/providers/problemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface CompletionType {
let currentTimeout: NodeJS.Timeout;
let sqlDiagnosticCollection = languages.createDiagnosticCollection(`db2i-sql`);

function getTimeout() {
export function getCheckerTimeout() {
return (Configuration.get<number>(`syntaxCheckInterval`) || 1500);
}

Expand Down Expand Up @@ -67,6 +67,6 @@ export const problemProvider = workspace.onDidChangeTextDocument(e => {
}
}
}
}, getTimeout());
}, getCheckerTimeout());
}
});
26 changes: 26 additions & 0 deletions src/language/providers/statusProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Disposable, languages, LanguageStatusSeverity } from "vscode";
import { SQLStatementChecker } from "../../connection/syntaxChecker";
import { getCheckerTimeout } from "./problemProvider";

export class Db2StatusProvider extends Disposable {
private item = languages.createLanguageStatusItem(`sql`, {language: `sql`});
constructor() {
super(() => this.item.dispose());

this.item.name = `SQL Language Status`;
this.setState(false);
}

setState(hasJob: Boolean) {
if (hasJob) {
const checker = SQLStatementChecker.get();
const checkerTimeout = getCheckerTimeout() / 1000;
this.item.text = `SQL assistance available. ${checker ? `Syntax checking enabled (every ${checkerTimeout}s after editing)` : `Syntax checking not available.`}`;
this.item.detail = `You're connected to an IBM i - you can use the advanced SQL language tooling. ${checker ? `` : `Syntax checking not available. This means that the syntax checker did not install when connecting to this system.`}`;
this.item.severity = checker ? LanguageStatusSeverity.Information : LanguageStatusSeverity.Warning;
} else {
this.item.text = `Basic SQL assistance available`;
this.item.detail = `Connect to an IBM i to enable advanced SQL language tooling.`;
}
}
}
2 changes: 2 additions & 0 deletions src/views/jobManager/jobManagerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SelfCodesQuickPickItem } from "./selfCodes/selfCodesBrowser";
import { updateStatusBar } from "./statusBar";
import { setCancelButtonVisibility } from "../results";
import { JDBCOptions } from "@ibm/mapepire-js/dist/src/types";
import { sqlLanguageStatus } from "../../language/providers";

const selectJobCommand = `vscode-db2i.jobManager.selectJob`;
const activeColor = new vscode.ThemeColor(`minimapGutter.addedBackground`);
Expand Down Expand Up @@ -304,6 +305,7 @@ export class JobManagerView implements TreeDataProvider<any> {
const selectedJob = JobManager.getSelection();

setCancelButtonVisibility(selectedJob && selectedJob.job.getStatus() === "busy");
sqlLanguageStatus.setState(selectedJob !== undefined);
commands.executeCommand(`setContext`, `vscode-db2i:jobManager.hasJob`, selectedJob !== undefined);
}

Expand Down

0 comments on commit 79ffbc0

Please sign in to comment.