Skip to content

Commit bb38ea0

Browse files
committed
Peek to support SQL and system naming
Signed-off-by: worksofliam <[email protected]>
1 parent 82cf8ab commit bb38ea0

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

src/connection/manager.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export interface JobInfo {
1313
job: OldSQLJob;
1414
}
1515

16+
export type NamingFormats = "sql"|"system";
17+
1618
const NO_SELECTED_JOB = -1;
1719

1820
export class SQLJobManager {
@@ -163,7 +165,7 @@ export class SQLJobManager {
163165
return Configuration.get<SelfValue>(`jobManager.jobSelfDefault`) || `*NONE`;
164166
}
165167

166-
static getNamingDefault(): "sql"|"system" {
167-
return (Configuration.get<string>(`jobManager.jobNamingDefault`) || `system`) as "system" | "sql";
168+
static getNamingDefault(): NamingFormats {
169+
return (Configuration.get<string>(`jobManager.jobNamingDefault`) || `system`) as NamingFormats;
168170
}
169171
}

src/connection/sqlJob.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { SQLJob } from "@ibm/mapepire-js";
55
import { ConnectionResult, JobStatus, QueryResult, ServerRequest, ServerResponse } from "@ibm/mapepire-js/dist/src/types";
66
import { JobLogEntry } from "./types";
77
import Statement from "../database/statement";
8+
import { NamingFormats } from "./manager";
89

910
const DB2I_VERSION = (process.env[`DB2I_VERSION`] || `<version unknown>`) + ((process.env.DEV) ? ``:`-dev`);
1011

@@ -18,6 +19,14 @@ export class OldSQLJob extends SQLJob {
1819
return this.selfState;
1920
}
2021

22+
getCurrentSchema(): string {
23+
return this.options.libraries[0] || `QGPL`;
24+
}
25+
26+
getNaming(): NamingFormats {
27+
return this.options.naming;
28+
}
29+
2130
public static async useExec() {
2231
let useExec = false;
2332

src/language/providers/peekProvider.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@ import { languages, workspace } from "vscode";
22
import { getSqlDocument } from "./logic/parse";
33
import { JobManager } from "../../config";
44
import Statement from "../../database/statement";
5-
import { StatementType } from "../sql/types";
65
import { remoteAssistIsEnabled } from "./logic/available";
7-
import Schemas, { AllSQLTypes, InternalTypes, SQLType } from "../../database/schemas";
6+
import Schemas, { } from "../../database/schemas";
87

98

109
export const peekProvider = languages.registerDefinitionProvider({ language: `sql` }, {
1110
async provideDefinition(document, position, token) {
12-
const standardObjects: SQLType[] = AllSQLTypes.filter(type => ![`functions`, `procedures`].includes(type));
1311
if (!remoteAssistIsEnabled()) return;
1412

15-
const defaultSchema = getDefaultSchema();
13+
const currentJob = JobManager.getSelection();
14+
15+
if (!currentJob) return;
16+
17+
const defaultSchema = currentJob.job.getCurrentSchema();
18+
const naming = currentJob.job.getNaming();
19+
1620
const sqlDoc = getSqlDocument(document);
1721
const offset = document.offsetAt(position);
1822

@@ -26,7 +30,13 @@ export const peekProvider = languages.registerDefinitionProvider({ language: `sq
2630

2731
if (ref) {
2832
const name = Statement.noQuotes(Statement.delimName(ref.object.name, true));
29-
const schema = ref.object.schema ? Statement.noQuotes(Statement.delimName(ref.object.schema, true)) : undefined;
33+
34+
// Schema is based on a few things:
35+
// If it's a fully qualified path, use the schema path
36+
// Otherwise:
37+
// - if SQL naming is in use, then use the default schema
38+
// - if system naming is in use, then don't pass a library and the library list will be used
39+
const schema = ref.object.schema ? Statement.noQuotes(Statement.delimName(ref.object.schema, true)) : naming === `sql` ? defaultSchema : undefined;
3040

3141
const possibleObjects = await Schemas.resolveObjects([{name, schema}]);
3242

@@ -45,9 +55,4 @@ export const peekProvider = languages.registerDefinitionProvider({ language: `sq
4555
}
4656
}
4757
}
48-
});
49-
50-
const getDefaultSchema = (): string => {
51-
const currentJob = JobManager.getSelection();
52-
return currentJob && currentJob.job.options.libraries[0] ? currentJob.job.options.libraries[0] : `QGPL`;
53-
}
58+
});

0 commit comments

Comments
 (0)