Skip to content

Commit

Permalink
Merge pull request #277 from codefori/feature/hover_support
Browse files Browse the repository at this point in the history
Hover support
  • Loading branch information
worksofliam authored Sep 18, 2024
2 parents 6164c1b + 9198377 commit 8c3716f
Show file tree
Hide file tree
Showing 25 changed files with 732 additions and 234 deletions.
6 changes: 6 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// https://www.ibm.com/docs/en/i/7.4?topic=views-syscolumns2
interface TableColumn {
TABLE_SCHEMA: string,
TABLE_NAME: string,
COLUMN_NAME: string,
SYSTEM_COLUMN_NAME: string,
CONSTRAINT_NAME?: string,
Expand All @@ -13,7 +16,9 @@ interface TableColumn {
IS_IDENTITY: "YES" | "NO",
}

// https://www.ibm.com/docs/en/i/7.4?topic=views-sysparms
interface SQLParm {
SPECIFIC_SCHEMA: string,
SPECIFIC_NAME: string,
PARAMETER_NAME: string,
PARAMETER_MODE: "IN" | "OUT" | "INOUT",
Expand All @@ -25,6 +30,7 @@ interface SQLParm {
DEFAULT?: string,
LONG_COMMENT?: string,
ORDINAL_POSITION: number,
ROW_TYPE: "P" | "R",
}

interface BasicSQLObject {
Expand Down
13 changes: 8 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
"chart.js": "^4.4.2",
"csv": "^6.1.3",
"json-to-markdown-table": "^1.0.0",
"lru-cache": "^6.0.0",
"node-fetch": "^3.3.1",
"showdown": "^2.1.0",
"sql-formatter": "^14.0.0"
Expand Down
51 changes: 9 additions & 42 deletions src/database/callable.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@

import vscode from "vscode"
import { JobManager } from "../config";
import { QueryOptions } from "../connection/types";
import { QueryOptions } from "@ibm/mapepire-js/dist/src/types";
const {instance} = vscode.extensions.getExtension(`halcyontechltd.code-for-ibmi`).exports;

export type CallableType = "PROCEDURE"|"FUNCTION";
export interface CallableRoutine {
schema: string;
name: string;
specificNames: string[];
type: string;
}

export interface CallableSignature {
specificName: string;
parms: SQLParm[];
returns: SQLParm[];
}

export default class Callable {
Expand All @@ -25,6 +28,8 @@ export default class Callable {
);

let routine: CallableRoutine = {
schema,
name,
specificNames: [],
type: forType
}
Expand All @@ -41,7 +46,7 @@ export default class Callable {
const results = await JobManager.runSQL<SQLParm>(
[
`SELECT * FROM QSYS2.SYSPARMS`,
`WHERE SPECIFIC_SCHEMA = ? AND ROW_TYPE = 'P' AND SPECIFIC_NAME in (${specificNames.map(n => `?`).join(`, `)})`,
`WHERE SPECIFIC_SCHEMA = ? AND ROW_TYPE in ('P', 'R') AND SPECIFIC_NAME in (${specificNames.map(n => `?`).join(`, `)})`,
`ORDER BY ORDINAL_POSITION`
].join(` `),
{
Expand All @@ -56,49 +61,11 @@ export default class Callable {
const groupedResults: CallableSignature[] = uniqueSpecificNames.map(name => {
return {
specificName: name,
parms: results.filter(row => row.SPECIFIC_NAME === name)
parms: results.filter(row => row.SPECIFIC_NAME === name && row.ROW_TYPE === `P`),
returns: results.filter(row => row.SPECIFIC_NAME === name && row.ROW_TYPE === `R`)
}
});

return groupedResults;
}

/**
* @param schema Not user input
* @param specificName Not user input
* @returns
*/
static getParms(schema: string, specificName: string, resolveName: boolean = false): Promise<SQLParm[]> {
const rowType = `P`; // Parameter
return Callable.getFromSysParms(schema, specificName, rowType, resolveName);
}

static getResultColumns(schema: string, specificName: string, resolveName: boolean = false) {
const rowType = `R`; // Row
return Callable.getFromSysParms(schema, specificName, rowType, resolveName);
}

static getFromSysParms(schema: string, name: string, rowType: "P"|"R", resolveName: boolean = false): Promise<SQLParm[]> {
let parameters = [schema, rowType];

let specificNameClause = undefined;

if (resolveName) {
specificNameClause = `SPECIFIC_NAME = (select specific_name from qsys2.sysroutines where specific_schema = ? and routine_name = ?)`;
parameters.push(schema, name);
} else {
specificNameClause = `SPECIFIC_NAME = ?`;
parameters.push(name);
}

const options : QueryOptions = { parameters };
return JobManager.runSQL<SQLParm>(
[
`SELECT * FROM QSYS2.SYSPARMS`,
`WHERE SPECIFIC_SCHEMA = ? AND ROW_TYPE = ? AND ${specificNameClause}`,
`ORDER BY ORDINAL_POSITION`
].join(` `),
options
);
}
}
2 changes: 1 addition & 1 deletion src/database/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getInstance } from "../base";
import { JobManager } from "../config";

export type SQLType = "schemas" | "tables" | "views" | "aliases" | "constraints" | "functions" | "variables" | "indexes" | "procedures" | "sequences" | "packages" | "triggers" | "types" | "logicals";
type PageData = { filter?: string, offset?: number, limit?: number };
export type PageData = { filter?: string, offset?: number, limit?: number };

const typeMap = {
'tables': [`T`, `P`, `M`],
Expand Down
2 changes: 2 additions & 0 deletions src/database/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export default class Table {
static async getItems(schema: string, name: string): Promise<TableColumn[]> {
const sql = [
`SELECT `,
` column.TABLE_SCHEMA,`,
` column.TABLE_NAME,`,
` column.COLUMN_NAME,`,
` key.CONSTRAINT_NAME,`,
` column.DATA_TYPE, `,
Expand Down
4 changes: 3 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getInstance, loadBase } from "./base";
import { JobManager, onConnectOrServerInstall, initConfig } from "./config";
import { queryHistory } from "./views/queryHistoryView";
import { ExampleBrowser } from "./views/examples/exampleBrowser";
import { languageInit } from "./language";
import { languageInit } from "./language/providers";
import { initialiseTestSuite } from "./testing";
import { JobManagerView } from "./views/jobManager/jobManagerView";
import { ServerComponent } from "./connection/serverComponent";
Expand All @@ -21,6 +21,7 @@ import { SelfTreeDecorationProvider, selfCodesResultsView } from "./views/jobMan
import Configuration from "./configuration";
import { JDBCOptions } from "@ibm/mapepire-js/dist/src/types";
import { Db2iUriHandler, getStatementUri } from "./uriHandler";
import { DbCache } from "./language/providers/logic/cache";

export interface Db2i {
sqlJobManager: SQLJobManager,
Expand Down Expand Up @@ -88,6 +89,7 @@ export function activate(context: vscode.ExtensionContext): Db2i {
const instance = getInstance();

instance.subscribe(context, `connected`, `db2i-connected`, () => {
DbCache.resetCache();
selfCodesView.setRefreshEnabled(false);
selfCodesView.setJobOnly(false);
// Refresh the examples when we have it, so we only display certain examples
Expand Down
15 changes: 0 additions & 15 deletions src/language/index.ts

This file was deleted.

22 changes: 0 additions & 22 deletions src/language/providers/completionItemCache.ts

This file was deleted.

Loading

0 comments on commit 8c3716f

Please sign in to comment.