Skip to content

Go to Definition support #278

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

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b654ec0
Initial work for peek for objects
worksofliam Sep 18, 2024
a6b83a0
Merge branch 'main' into feature/peek
worksofliam Sep 18, 2024
9f19697
Merge branch 'main' into feature/peek
worksofliam Dec 3, 2024
eed57eb
Merge branch 'main' into feature/peek
worksofliam Dec 3, 2024
9f5ea2d
Slim down definition and use formatter
worksofliam Dec 3, 2024
d55a23b
Fix invalid comment references
worksofliam Dec 3, 2024
f98b022
Merge branch 'main' into feature/peek
worksofliam Feb 5, 2025
d6e93bf
Remove formatter from peek provider
worksofliam Feb 5, 2025
f99b033
Upload artifact version bump
worksofliam Feb 5, 2025
0db258c
Move peek result to second line to skip comment
worksofliam Feb 5, 2025
87ad327
Merge branch 'main' into feature/peek
worksofliam Mar 15, 2025
eedcba4
Go to defintion now resolves based on library list
worksofliam Mar 15, 2025
c37c119
Fix library list bug with caching
worksofliam Mar 15, 2025
d93be8d
Simplify peek logic
worksofliam Mar 15, 2025
d168244
Don't hardcode the current library
worksofliam Mar 16, 2025
82cf8ab
Ability to configure naming for default job
worksofliam Mar 17, 2025
bb38ea0
Peek to support SQL and system naming
worksofliam Mar 17, 2025
c21673e
Change range line
worksofliam Mar 17, 2025
621860f
Add text on library list setting to clarify current schema
worksofliam Mar 17, 2025
d4eda78
New API to get current schema
worksofliam Mar 17, 2025
e27c2f7
Merge branch 'main' into feature/peek
worksofliam Mar 17, 2025
df33661
Better support for SQL naming vs system naming
worksofliam Mar 17, 2025
d741729
Fix for delimited names
worksofliam Mar 19, 2025
b690143
Replace config call
worksofliam Mar 24, 2025
59ae5bf
Merge branch 'main' into feature/peek
worksofliam Apr 29, 2025
a898a5c
Add additional info to hover for naming info
worksofliam Apr 29, 2025
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
42 changes: 24 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,22 @@
}
},
{
"id": "vscode-db2i.self",
"title": "SQL Error Logging Facility (SELF)",
"id": "vscode-db2i.jobManager",
"title": "SQL Job Manager",
"properties": {
"vscode-db2i.jobSelfDefault": {
"vscode-db2i.jobManager.jobNamingDefault": {
"type": "string",
"order": 0,
"description": "Default naming mode for new jobs",
"default": "system",
"enum": [
"system",
"sql"
]
},
"vscode-db2i.jobManager.jobSelfDefault": {
"type": "string",
"order": 1,
"description": "Default SELF setting for new jobs",
"default": "*NONE",
"enum": [
Expand All @@ -200,7 +210,13 @@
"*ERROR",
"*WARNING"
]
},
}
}
},
{
"id": "vscode-db2i.self",
"title": "SQL Error Logging Facility (SELF)",
"properties": {
"vscode-db2i.jobSelfViewAutoRefresh": {
"type": "boolean",
"title": "Auto-refresh SELF Codes view",
Expand Down Expand Up @@ -423,11 +439,6 @@
"category": "Db2 for i",
"icon": "$(output)"
},
{
"command": "vscode-db2i.setCurrentSchema",
"title": "Set current schema",
"category": "Db2 for i"
},
{
"command": "vscode-db2i.setSchemaFilter",
"title": "Set filter",
Expand Down Expand Up @@ -588,8 +599,8 @@
"icon": "$(edit)"
},
{
"command": "vscode-db2i.jobManager.defaultSelfSettings",
"title": "SQL Error Logging Facility (SELF) - Default Setting",
"command": "vscode-db2i.jobManager.defaultSettings",
"title": "Default Job Settings",
"category": "Db2 for i",
"icon": "$(gear)"
},
Expand Down Expand Up @@ -948,7 +959,7 @@
"when": "view == jobManager"
},
{
"command": "vscode-db2i.jobManager.defaultSelfSettings",
"command": "vscode-db2i.jobManager.defaultSettings",
"group": "navigation",
"when": "view == jobManager"
},
Expand Down Expand Up @@ -1014,11 +1025,6 @@
}
],
"view/item/context": [
{
"command": "vscode-db2i.setCurrentSchema",
"when": "viewItem == schema",
"group": "db2@1"
},
{
"command": "vscode-db2i.setSchemaFilter",
"when": "viewItem == schema",
Expand Down Expand Up @@ -1375,7 +1381,7 @@
},
{
"view": "vscode-db2i.self.nodes",
"contents": "🛠️ SELF Codes will appear here. You can set the SELF log level on specific jobs, or you can set the default for new jobs in the User Settings.\n\n[Set Default for New Jobs](command:vscode-db2i.jobManager.defaultSelfSettings)\n\n[Learn about SELF](command:vscode-db2i.self.help)"
"contents": "🛠️ SELF Codes will appear here. You can set the SELF log level on specific jobs, or you can set the default for new jobs in the User Settings.\n\n[Set Default for New Jobs](command:vscode-db2i.jobManager.defaultSettings)\n\n[Learn about SELF](command:vscode-db2i.self.help)"
}
],
"notebooks": [
Expand Down
33 changes: 25 additions & 8 deletions src/connection/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface JobInfo {
job: OldSQLJob;
}

export type NamingFormats = "sql"|"system";

const NO_SELECTED_JOB = -1;

export class SQLJobManager {
Expand All @@ -27,11 +29,12 @@ export class SQLJobManager {
if (ServerComponent.isInstalled()) {

const instance = getInstance();
const config = instance.getConfig();
const connection = instance.getConnection()!;
const config = connection.getConfig();

const newJob = predefinedJob || (new OldSQLJob({
libraries: [config.currentLibrary, ...config.libraryList.filter((item) => item != config.currentLibrary)],
naming: `system`,
naming: SQLJobManager.getNamingDefault(),
"full open": false,
"transaction isolation": "none",
"query optimize goal": "1",
Expand Down Expand Up @@ -117,6 +120,16 @@ export class SQLJobManager {
return this.jobs[jobExists];
}

private resetCurrentSchema(query: string, job: OldSQLJob) {
if (query.toUpperCase().startsWith(`SET`)) {
const newSchema = query.split(` `)[2];
if (newSchema) {
job.resetCurrentSchemaCache();
}
}
return query;
}

async runSQL<T>(query: string, opts?: QueryOptions, rowsToFetch = 2147483647): Promise<T[]> {
// 2147483647 is NOT arbitrary. On the server side, this is processed as a Java
// int. This is the largest number available without overflow (Integer.MAX_VALUE)
Expand All @@ -128,10 +141,7 @@ export class SQLJobManager {
const results = await statement.execute(rowsToFetch);
statement.close();

// const e = performance.now()
// console.log(`Statement executed in ${e - s} ms. ${results.data.length} rows returned.`);
// console.log(`\t${query.padEnd(40).substring(0, 40)}`)

this.resetCurrentSchema(query, this.jobs[this.selectedJob].job);
return results.data;
}

Expand All @@ -143,12 +153,15 @@ export class SQLJobManager {
const results = await statement.execute(rowsToFetch);
statement.close();

this.resetCurrentSchema(query, this.jobs[this.selectedJob].job);
return results;
}

async getPagingStatement<T>(query: string, opts?: QueryOptions): Promise<Query<T>> {
const selected = this.jobs[this.selectedJob]
const selected = this.jobs[this.selectedJob];
if (ServerComponent.isInstalled() && selected) {
this.resetCurrentSchema(query, selected?.job);

return selected.job.query<T>(query, opts);

} else if (!ServerComponent.isInstalled()) {
Expand All @@ -171,6 +184,10 @@ export class SQLJobManager {
}

static getSelfDefault(): SelfValue {
return Configuration.get<SelfValue>(`jobSelfDefault`) || `*NONE`;
return Configuration.get<SelfValue>(`jobManager.jobSelfDefault`) || `*NONE`;
}

static getNamingDefault(): NamingFormats {
return (Configuration.get<string>(`jobManager.jobNamingDefault`) || `system`) as NamingFormats;
}
}
38 changes: 25 additions & 13 deletions src/connection/sqlJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SQLJob } from "@ibm/mapepire-js";
import { ConnectionResult, QueryResult, ServerRequest, ServerResponse } from "@ibm/mapepire-js/dist/src/types";
import { JobLogEntry, JobStatus } from "./types";
import Statement from "../database/statement";
import { NamingFormats } from "./manager";

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

Expand All @@ -13,11 +14,35 @@ export class OldSQLJob extends SQLJob {
private selfState: SelfValue = "*NONE";

id: string | undefined;
private currentSchemaStore: string | undefined;

getSelfCode(): SelfValue {
return this.selfState;
}

resetCurrentSchemaCache() {
this.currentSchemaStore = undefined;
}

async getCurrentSchema(): Promise<string> {
if (this.getNaming() === `sql`) {
if (this.currentSchemaStore)
return this.currentSchemaStore;

const result = await this.execute<{'00001': string}>(`values (current schema)`);
if (result.success && result.data.length > 0) {
this.currentSchemaStore = result.data[0]['00001'];
return this.currentSchemaStore;
}
}

return this.options.libraries[0] || `QGPL`;
}

getNaming(): NamingFormats {
return this.options.naming;
}

public static async useExec() {
let useExec = false;

Expand Down Expand Up @@ -169,19 +194,6 @@ export class OldSQLJob extends SQLJob {
throw e;
}
}

async setCurrentSchema(schema: string): Promise<QueryResult<any>> {
if (schema) {
const upperSchema = Statement.delimName(schema, true);
const result = await this.execute(`set current schema = ?`, {parameters: [upperSchema]});
if (result.success) {
this.options.libraries[0] = upperSchema;
}

return result;

}
}

getJobLog(): Promise<QueryResult<JobLogEntry>> {
return this.query<JobLogEntry>(`select * from table(qsys2.joblog_info('*')) a`).execute();
Expand Down
6 changes: 3 additions & 3 deletions src/connection/syntaxChecker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class SQLStatementChecker implements IBMiComponent {

private getLibrary(connection: IBMi) {
if (!this.library) {
this.library = connection?.config?.tempLibrary.toUpperCase() || `ILEDITOR`;
this.library = connection?.getConfig()?.tempLibrary.toUpperCase() || `ILEDITOR`;
}

return this.library;
Expand Down Expand Up @@ -79,7 +79,7 @@ export class SQLStatementChecker implements IBMiComponent {
return -1;
}

async getRemoteState(connection: IBMi) {
async getRemoteState(connection: IBMi): Promise<ComponentState> {
const lib = this.getLibrary(connection);

const wrapperVersion = await SQLStatementChecker.getVersionOf(connection, lib, WRAPPER_NAME);
Expand All @@ -98,7 +98,7 @@ export class SQLStatementChecker implements IBMiComponent {
update(connection: IBMi): ComponentState | Promise<ComponentState> {
return connection.withTempDirectory(async tempDir => {
const tempSourcePath = posix.join(tempDir, `sqlchecker.sql`);
await connection.content.writeStreamfileRaw(tempSourcePath, Buffer.from(this.getSource(connection), "utf-8"));
await connection.getConfig().writeStreamfileRaw(tempSourcePath, Buffer.from(this.getSource(connection), "utf-8"));
const result = await connection.runCommand({
command: `RUNSQLSTM SRCSTMF('${tempSourcePath}') COMMIT(*NONE) NAMING(*SYS)`,
noLibList: true
Expand Down
Loading
Loading