Skip to content

Commit 53c4a48

Browse files
authored
Merge pull request #135 from halcyon-tech/feature/examples_sevice_info
`service_info` available from Examples view
2 parents bec6763 + b016d2a commit 53c4a48

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
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/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as resultsProvider from "./views/results";
99
import { loadBase } from "./base";
1010
import { JobManager, setupConfig } from "./config";
1111
import { queryHistory } from "./views/queryHistoryView";
12-
import { ExampleBrowser } from "./views/exampleBrowser";
12+
import { ExampleBrowser } from "./views/examples/exampleBrowser";
1313
import { languageInit } from "./language";
1414
import { initialise } from "./testing";
1515
import { JobManagerView } from "./views/jobManager/jobManagerView";

src/views/exampleBrowser.ts renamed to src/views/examples/exampleBrowser.ts

Lines changed: 13 additions & 4 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 "./examples";
5-
import { OSData, fetchSystemInfo } from "../config";
6-
import { getInstance } from "../base";
4+
import { SQLExample, Examples, ServiceInfoLabel } from ".";
5+
import { OSData, fetchSystemInfo } from "../../config";
6+
import { getInstance } from "../../base";
7+
import { getServiceInfo } from "../../database/serviceInfo";
78

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

@@ -59,7 +60,15 @@ 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+
// Unlike the bulk of the examples which are defined in views/examples/index.ts, the services examples are retrieved dynamically
65+
if (!Examples[ServiceInfoLabel]) {
66+
getServiceInfo().then(serviceExamples => {
67+
Examples[ServiceInfoLabel] = serviceExamples;
68+
this.refresh();
69+
})
70+
}
71+
6372
if (this.currentFilter) {
6473
// If there is a filter, then show all examples that include this criteria
6574
let items: SQLExampleItem[] = [];

src/views/examples/index.ts

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

16-
export const Examples: SQLExamplesList = {
16+
// Unlike the bulk of the examples defined below, the services examples are retrieved dynamically
17+
export const ServiceInfoLabel = `IBM i (SQL) Services`;
18+
19+
export let Examples: SQLExamplesList = {
1720
"Data Definition Language (DDL)": [
1821
{
1922
"name": "Create Schema",

0 commit comments

Comments
 (0)