Skip to content

Commit f98b022

Browse files
committed
Merge branch 'main' into feature/peek
Signed-off-by: worksofliam <[email protected]>
2 parents d55a23b + ffd7189 commit f98b022

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+7182
-4637
lines changed

.github/workflows/webpack_ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ jobs:
7070
👋 A new build is available for this PR based on ${{ github.event.pull_request.head.sha }}.
7171
7272
* [Download here.](https://github.com/codefori/vscode-db2i/actions/runs/${{ github.run_id }})
73-
* [Read more about how to test](https://github.com/codefori/vscode-ibmi/blob/master/.github/pr_testing_template.md)
73+
* [Read more about how to test](https://github.com/codefori/vscode-db2i/blob/master/.github/pr_testing_template.md)

.vscode/launch.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,24 @@
3131
"preLaunchTask": "${defaultBuildTask}",
3232
"sourceMaps": true,
3333
"env": {
34-
"testing": "true"
34+
"db2_testing": "true"
35+
}
36+
},
37+
{
38+
"name": "Launch Tests (Specific)",
39+
"type": "extensionHost",
40+
"request": "launch",
41+
"args": [
42+
"--extensionDevelopmentPath=${workspaceFolder}"
43+
],
44+
"outFiles": [
45+
"${workspaceFolder}/dist/**/*.js"
46+
],
47+
"preLaunchTask": "${defaultBuildTask}",
48+
"sourceMaps": true,
49+
"env": {
50+
"db2_testing": "true",
51+
"db2_specific": "true"
3552
}
3653
},
3754
]

global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ interface SQLParm {
3535

3636
interface BasicSQLObject {
3737
type: string;
38+
tableType: string;
3839
schema: string;
3940
name: string;
4041
specificName: string;

package-lock.json

Lines changed: 5272 additions & 4312 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-db2i",
33
"displayName": "Db2 for IBM i",
44
"description": "Db2 for IBM i tools in VS Code",
5-
"version": "1.6.3-scott12",
5+
"version": "1.8.3",
66
"engines": {
77
"vscode": "^1.95.0"
88
},
@@ -199,6 +199,32 @@
199199
"default": false
200200
}
201201
}
202+
},
203+
{
204+
"id": "vscode-db2i.syntax",
205+
"title": "SQL Syntax Checking",
206+
"properties": {
207+
"vscode-db2i.syntax.checkOnOpen": {
208+
"type": "boolean",
209+
"description": "If enabled, will check the syntax of the SQL file when it is opened",
210+
"default": false
211+
},
212+
"vscode-db2i.syntax.checkOnEdit": {
213+
"type": "boolean",
214+
"description": "Whether the syntax checker should run automatically when the document is edited",
215+
"default": true
216+
},
217+
"vscode-db2i.syntax.checkInterval": {
218+
"type": "number",
219+
"description": "Time between editing (ms) and sending a request to syntax check on the server",
220+
"default": 1500
221+
},
222+
"vscode-db2i.syntax.showWarnings": {
223+
"type": "boolean",
224+
"description": "Whether SQL syntax warnings should show in the editor",
225+
"default": false
226+
}
227+
}
202228
}
203229
],
204230
"viewsContainers": {
@@ -332,6 +358,16 @@
332358
"title": "Get Indexes",
333359
"category": "Db2 for i"
334360
},
361+
{
362+
"command": "vscode-db2i.getAuthorities",
363+
"title": "Get Authorities",
364+
"category": "Db2 for i"
365+
},
366+
{
367+
"command": "vscode-db2i.getObjectLocks",
368+
"title": "Get Object Locks",
369+
"category": "Db2 for i"
370+
},
335371
{
336372
"command": "vscode-db2i.clearData",
337373
"title": "Clear...",
@@ -655,6 +691,13 @@
655691
"title": "Export",
656692
"category": "IBM i Notebooks",
657693
"icon": "$(save)"
694+
},
695+
{
696+
"command": "vscode-db2i.syntax.checkDocument",
697+
"title": "Check SQL syntax",
698+
"category": "Db2 for IBM i",
699+
"enablement": "code-for-ibmi:connected == true && vscode-db2i:jobManager.hasJob && vscode-db2i:statementCanCancel != true && vscode-db2i.syntax.checkerAvailable == true && vscode-db2i.syntax.checkerRunning != true",
700+
"icon": "$(check-all)"
658701
}
659702
],
660703
"menus": {
@@ -920,6 +963,16 @@
920963
"when": "viewItem == table || viewItem == schema",
921964
"group": "db2workWith@3"
922965
},
966+
{
967+
"command": "vscode-db2i.getAuthorities",
968+
"when": "viewItem == table || viewItem == view || viewItem == alias || viewItem == constraint || viewItem == function || viewItem == variable || viewItem == index || viewItem == procedure || viewItem == sequence || viewItem == package || viewItem == trigger || viewItem == type",
969+
"group": "db2workWith@4"
970+
},
971+
{
972+
"command": "vscode-db2i.getObjectLocks",
973+
"when": "viewItem == table || viewItem == view || viewItem == alias || viewItem == function || viewItem == variable || viewItem == index || viewItem == procedure || viewItem == sequence || viewItem == package || viewItem == trigger || viewItem == type",
974+
"group": "db2workWith@5"
975+
},
923976
{
924977
"command": "vscode-db2i.clearData",
925978
"when": "viewItem == table",
@@ -1040,6 +1093,11 @@
10401093
"command": "vscode-db2i.statement.cancel",
10411094
"when": "editorLangId == sql && vscode-db2i:statementCanCancel == true",
10421095
"group": "navigation@1"
1096+
},
1097+
{
1098+
"command": "vscode-db2i.syntax.checkDocument",
1099+
"when": "editorLangId == sql && code-for-ibmi:connected == true",
1100+
"group": "navigation"
10431101
}
10441102
],
10451103
"sql/editor/context": [
@@ -1264,9 +1322,9 @@
12641322
},
12651323
"devDependencies": {
12661324
"@continuedev/core": "^1.0.13",
1267-
"@halcyontech/vscode-ibmi-types": "^2.0.0",
1325+
"@halcyontech/vscode-ibmi-types": "^2.14.5",
12681326
"@types/glob": "^7.1.3",
1269-
"@types/node": "14.x",
1327+
"@types/node": "18.x",
12701328
"@types/vscode": "^1.95.0",
12711329
"esbuild-loader": "^3.0.1",
12721330
"eslint": "^7.32.0",
@@ -1275,7 +1333,7 @@
12751333
"raw-loader": "^4.0.2",
12761334
"ts-loader": "^9.3.1",
12771335
"typescript": "^4.3.2",
1278-
"vitest": "^0.33.0",
1336+
"vitest": "^2.1.8",
12791337
"vscd": "^1.1.0",
12801338
"vscode-test": "^1.5.2",
12811339
"webpack": "^5.91.0",

snippets/create.code-snippets

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
"prefix": "create procedure",
44
"body": [
55
"create or replace procedure ${1:procedure_name}($2)",
6+
" program type sub modifies sql data",
67
" set option usrprf = *user, dynusrprf = *user, commit = *none",
7-
" program type sub",
8-
" modifies sql data",
98
"begin",
109
" $0",
1110
"end;"

src/aiProviders/context.ts

Lines changed: 48 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { JobManager } from "../config";
22
import * as vscode from "vscode";
33
import Statement from "../database/statement";
4+
import { ContextItem } from "@continuedev/core";
45

56
export function canTalkToDb() {
67
return JobManager.getSelection() !== undefined;
@@ -14,73 +15,31 @@ export function getCurrentSchema(): string {
1415
};
1516

1617
export type TableRefs = { [key: string]: TableColumn[] };
17-
18-
export async function getTableMetaData(schema: string, tableName: string): Promise<TableColumn[]> {
19-
const objectFindStatement = [
20-
`SELECT `,
21-
` column.TABLE_SCHEMA,`,
22-
` column.TABLE_NAME,`,
23-
` column.COLUMN_NAME,`,
24-
` key.CONSTRAINT_NAME,`,
25-
` column.DATA_TYPE, `,
26-
` column.CHARACTER_MAXIMUM_LENGTH,`,
27-
` column.NUMERIC_SCALE, `,
28-
` column.NUMERIC_PRECISION,`,
29-
` column.IS_NULLABLE, `,
30-
// ` column.HAS_DEFAULT, `,
31-
// ` column.COLUMN_DEFAULT, `,
32-
` column.COLUMN_TEXT, `,
33-
` column.IS_IDENTITY`,
34-
`FROM QSYS2.SYSCOLUMNS2 as column`,
35-
`LEFT JOIN QSYS2.syskeycst as key`,
36-
` on `,
37-
` column.table_schema = key.table_schema and`,
38-
` column.table_name = key.table_name and`,
39-
` column.column_name = key.column_name`,
40-
`WHERE column.TABLE_SCHEMA = '${Statement.delimName(schema, true)}'`,
41-
`AND column.TABLE_NAME = '${Statement.delimName(tableName, true)}'`,
42-
`ORDER BY column.ORDINAL_POSITION`,
43-
].join(` `);
44-
45-
return await JobManager.runSQL(objectFindStatement);
46-
}
47-
48-
export async function parsePromptForRefs(stream: vscode.ChatResponseStream, prompt: string[]): Promise<TableRefs> {
49-
const tables: TableRefs = {};
50-
for (const word of prompt) {
51-
const [schema, table] = word.split(`.`);
52-
const cleanedTable = table.replace(/[,\/#!?$%\^&\*;:{}=\-_`~()]/g, "");
53-
if (schema && cleanedTable) {
54-
if (stream !== null) {
55-
stream.progress(`looking up information for ${schema}.${cleanedTable}`)
56-
}
57-
const data = await getTableMetaData(schema, cleanedTable);
58-
tables[cleanedTable] = tables[cleanedTable] || [];
59-
tables[cleanedTable].push(...data);
60-
}
61-
}
62-
return tables;
18+
interface MarkdownRef {
19+
TABLE_NAME: string,
20+
COLUMN_INFO?: string,
21+
SCHMEA?: string,
6322
}
6423

6524
export async function findPossibleTables(stream: vscode.ChatResponseStream, schema: string, words: string[]) {
6625

6726
let tables: TableRefs = {}
6827

69-
// parse all SCHEMA.TABLE references first
70-
tables = await parsePromptForRefs(stream, words.filter(word => word.includes('.')));
71-
28+
// Parse all SCHEMA.TABLE references first
29+
const schemaTableRefs = words.filter(word => word.includes('.'));
7230
const justWords = words.map(word => word.replace(/[,\/#!?$%\^&\*;:{}=\-_`~()]/g, ""));
7331

7432
// Remove plurals from words
7533
justWords.push(...justWords.filter(word => word.endsWith('s')).map(word => word.slice(0, -1)));
7634

77-
// filter prompt for possible refs to tables
35+
// Filter prompt for possible refs to tables
7836
const validWords = justWords
7937
.filter(word => word.length > 2 && !word.endsWith('s') && !word.includes(`'`))
8038
.map(word => `'${Statement.delimName(word, true)}'`);
8139

8240
const objectFindStatement = [
8341
`SELECT `,
42+
` column.TABLE_SCHEMA,`,
8443
` column.TABLE_NAME,`,
8544
` column.COLUMN_NAME,`,
8645
` key.CONSTRAINT_NAME,`,
@@ -99,15 +58,18 @@ export async function findPossibleTables(stream: vscode.ChatResponseStream, sche
9958
` column.table_schema = key.table_schema and`,
10059
` column.table_name = key.table_name and`,
10160
` column.column_name = key.column_name`,
102-
`WHERE column.TABLE_SCHEMA = '${schema}'`,
61+
`WHERE column.TABLE_SCHEMA = '${Statement.delimName(schema, true)}'`,
10362
...[
104-
words.length > 0
105-
? `AND column.TABLE_NAME in (${validWords.join(`, `)})`
106-
: ``,
63+
schemaTableRefs.length > 0
64+
? `AND (column.TABLE_NAME in (${validWords.join(`, `)}) OR (${schemaTableRefs.map(ref => {
65+
const [schema, table] = ref.split('.');
66+
const cleanedTable = table.replace(/[,\/#!?$%\^&\*;:{}=\-_`~()]/g, "");
67+
return `(column.TABLE_SCHEMA = '${Statement.delimName(schema, true)}' AND column.TABLE_NAME = '${Statement.delimName(cleanedTable, true)}')`;
68+
}).join(' OR ')}))`
69+
: `AND column.TABLE_NAME in (${validWords.join(`, `)})`,
10770
],
10871
`ORDER BY column.ORDINAL_POSITION`,
10972
].join(` `);
110-
11173
// TODO
11274
const result: TableColumn[] = await JobManager.runSQL(objectFindStatement);
11375

@@ -138,41 +100,44 @@ export async function findPossibleTables(stream: vscode.ChatResponseStream, sche
138100
*
139101
* Tables with names starting with 'SYS' are skipped.
140102
*/
141-
export function refsToMarkdown(refs: TableRefs) {
103+
export function refsToMarkdown(refs: TableRefs): MarkdownRef[] {
142104
const condensedResult = Object.keys(refs).length > 5;
143105

144-
let markdown: string[] = [];
145-
106+
let markdownRefs: MarkdownRef[] = [];
146107
for (const tableName in refs) {
147108
if (tableName.startsWith(`SYS`)) continue;
148109

149-
markdown.push(`# ${tableName}`, ``);
150-
151-
if (condensedResult) {
152-
markdown.push(`| Column | Type | Text |`);
153-
markdown.push(`| - | - | - |`);
154-
} else {
155-
markdown.push(
156-
`| Column | Type | Nullable | Identity | Text | Constraint |`
157-
);
158-
markdown.push(`| - | - | - | - | - | - |`);
159-
}
160-
for (const column of refs[tableName]) {
161-
if (condensedResult) {
162-
markdown.push(
163-
`| ${column.COLUMN_NAME} | ${column.DATA_TYPE} | ${column.COLUMN_TEXT} |`
164-
);
165-
} else {
166-
markdown.push(
167-
`| ${column.COLUMN_NAME} | ${column.DATA_TYPE} | ${column.IS_NULLABLE} | ${column.IS_IDENTITY} | ${column.COLUMN_TEXT} | ${column.CONSTRAINT_NAME} |`
168-
);
169-
}
170-
}
171-
172-
markdown.push(``);
110+
const curRef: MarkdownRef = {
111+
TABLE_NAME: tableName,
112+
SCHMEA: refs[tableName][0].TABLE_SCHEMA,
113+
COLUMN_INFO: refs[tableName].map(column => {
114+
const lengthPrecision = column.CHARACTER_MAXIMUM_LENGTH
115+
? `(${column.CHARACTER_MAXIMUM_LENGTH}${column.NUMERIC_PRECISION ? `:${column.NUMERIC_PRECISION}` : ``})`
116+
: ``;
117+
return `${column.COLUMN_NAME}${column.COLUMN_TEXT ? ` - ${column.COLUMN_TEXT}` : ``} ${column.DATA_TYPE}${lengthPrecision} is_identity: ${column.IS_IDENTITY} is_nullable: ${column.IS_NULLABLE}`;
118+
}).join(`\n`)
119+
};
120+
markdownRefs.push(curRef);
121+
}
122+
123+
return markdownRefs;
124+
}
125+
126+
export function createContinueContextItems(refs: MarkdownRef[]) {
127+
const contextItems: ContextItem[] = [];
128+
const job = JobManager.getSelection();
129+
for (const tableRef of refs) {
130+
let prompt = `Table: ${tableRef.TABLE_NAME} (Schema: ${tableRef.SCHMEA}) Column Information:\n`;
131+
prompt += `Format: column_name (column_text) type(length:precision) is_identity is_nullable\n`
132+
prompt += `${tableRef.COLUMN_INFO}`;
133+
contextItems.push({
134+
name: `${job.name}-${tableRef.SCHMEA}-${tableRef.TABLE_NAME}`,
135+
description: `Column information for ${tableRef.TABLE_NAME}`,
136+
content: prompt,
137+
});
173138
}
174139

175-
return markdown.join(`\n`);
140+
return contextItems;
176141
}
177142

178143
export async function getSystemStatus(): Promise<string> {

0 commit comments

Comments
 (0)