Skip to content

Commit 40e3ce5

Browse files
committed
Add service info correctly
1 parent c925190 commit 40e3ce5

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

src/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ServerComponent, UpdateStatus } from "./connection/serverComponent";
66
import { JobManagerView } from "./views/jobManager/jobManagerView";
77
import Configuration from "./configuration";
88
import { ConfigManager } from "./views/jobManager/ConfigManager";
9+
import { Examples, ServiceInfoLabel } from "./views/examples";
910

1011
interface IBMiLevels {
1112
version: number;
@@ -67,6 +68,9 @@ export function setupConfig(context: ExtensionContext) {
6768
getInstance().onEvent(`disconnected`, async () => {
6869
JobManagerView.setVisible(false);
6970
await JobManager.endAll();
71+
72+
// Remove old service examples
73+
delete Examples[ServiceInfoLabel];
7074
});
7175
}
7276

src/database/serviceInfo.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { SQLExample } from "../views/examples";
2+
import { JobManager } from "../config";
3+
import Statement from "./statement";
4+
5+
export async function getServiceInfo(): Promise<SQLExample[]|undefined> {
6+
// The reason we check for a selection is because we don't want it to prompt the user to start one here
7+
if (JobManager.getSelection()) {
8+
const resultSet = await JobManager.runSQL<{SERVICE_NAME: string, EXAMPLE: string}>(`select SERVICE_NAME, EXAMPLE from qsys2.services_info`);
9+
10+
return resultSet.map(r => ({
11+
name: Statement.prettyName(r.SERVICE_NAME),
12+
content: [r.EXAMPLE],
13+
}))
14+
} else {
15+
return undefined;
16+
}
17+
}

src/views/examples/exampleBrowser.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { EventEmitter, MarkdownString, workspace } from "vscode";
22
import { window } from "vscode";
33
import { CancellationToken, Event, ExtensionContext, ProviderResult, ThemeIcon, TreeDataProvider, TreeItem, TreeItemCollapsibleState, commands } from "vscode";
4-
import { SQLExample, Examples } from ".";
4+
import { SQLExample, Examples, ServiceInfoLabel } from ".";
55
import { OSData, fetchSystemInfo } from "../../config";
66
import { getInstance } from "../../base";
7+
import { getServiceInfo } from "../../database/serviceInfo";
78

89
const openExampleCommand = `vscode-db2i.examples.open`;
910

@@ -59,7 +60,14 @@ export class ExampleBrowser implements TreeDataProvider<any> {
5960
return element;
6061
}
6162

62-
getChildren(element?: ExampleGroupItem): ProviderResult<any[]> {
63+
async getChildren(element?: ExampleGroupItem): Promise<any[]> {
64+
if (!Examples[ServiceInfoLabel]) {
65+
getServiceInfo().then(serviceExamples => {
66+
Examples[ServiceInfoLabel] = serviceExamples;
67+
this.refresh();
68+
})
69+
}
70+
6371
if (this.currentFilter) {
6472
// If there is a filter, then show all examples that include this criteria
6573
let items: SQLExampleItem[] = [];

src/views/examples/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export interface SQLExample {
1313
requirements?: ExampleSystemRequirements;
1414
};
1515

16-
export const Examples: SQLExamplesList = {
16+
export const ServiceInfoLabel = `IBM i (SQL) Services`;
17+
18+
export let Examples: SQLExamplesList = {
1719
"Data Definition Language (DDL)": [
1820
{
1921
"name": "Create Schema",

0 commit comments

Comments
 (0)