Skip to content

Commit 7c3cefe

Browse files
authored
Merge pull request #375 from codefori/feature/346_use_system_names_in_columns
Implement option to use system names for columns in content assist
2 parents 22525e4 + 5a7f699 commit 7c3cefe

File tree

6 files changed

+35
-11
lines changed

6 files changed

+35
-11
lines changed

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211
},
212212
{
213213
"id": "vscode-db2i.syntax",
214-
"title": "SQL Syntax Checking",
214+
"title": "SQL Syntax Options",
215215
"properties": {
216216
"vscode-db2i.syntax.checkOnOpen": {
217217
"type": "boolean",
@@ -232,6 +232,11 @@
232232
"type": "boolean",
233233
"description": "Whether SQL syntax warnings should show in the editor",
234234
"default": false
235+
},
236+
"vscode-db2i.syntax.useSystemNames": {
237+
"type": "boolean",
238+
"description": "Whether to use system names for columns in the content assist",
239+
"default": false
235240
}
236241
}
237242
}

src/database/table.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default class Table {
1515
`SELECT `,
1616
` column.TABLE_SCHEMA,`,
1717
` column.TABLE_NAME,`,
18+
` column.SYSTEM_COLUMN_NAME,`,
1819
` column.COLUMN_NAME,`,
1920
` key.CONSTRAINT_NAME,`,
2021
` column.DATA_TYPE, `,

src/language/providers/completionProvider.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { CTEReference, ClauseType, ObjectRef, StatementType } from "../sql/types
1010
import { CallableType } from "../../database/callable";
1111
import { prepareParamType, createCompletionItem, getParmAttributes } from "./logic/completion";
1212
import { isCallableType, getCallableParameters } from "./logic/callable";
13-
import { localAssistIsEnabled, remoteAssistIsEnabled } from "./logic/available";
13+
import { localAssistIsEnabled, remoteAssistIsEnabled, useSystemNames } from "./logic/available";
1414
import { DbCache } from "./logic/cache";
1515
import { getSqlDocument } from "./logic/parse";
1616
import { TableColumn, BasicSQLObject } from "../../types";
@@ -57,9 +57,9 @@ const completionTypes: { [index: string]: CompletionType } = {
5757

5858

5959

60-
function getColumnAttributes(column: TableColumn): string {
60+
function getColumnAttributes(column: TableColumn, useSystemName: boolean): string {
6161
const lines: string[] = [
62-
`Column: ${column.COLUMN_NAME}`,
62+
`Column: ${useSystemName ? column.SYSTEM_COLUMN_NAME : column.COLUMN_NAME}`,
6363
`Type: ${prepareParamType(column)}`,
6464
`HAS_DEFAULT: ${column.HAS_DEFAULT}`,
6565
`IS_IDENTITY: ${column.IS_IDENTITY}`,
@@ -85,7 +85,8 @@ function getAllColumns(name: string, schema: string, items: CompletionItem[]) {
8585
async function getObjectColumns(
8686
schema: string,
8787
name: string,
88-
isUDTF = false
88+
isUDTF: boolean,
89+
useSystemNamesInColumn: boolean,
8990
): Promise<CompletionItem[]> {
9091

9192
let completionItems: CompletionItem[];
@@ -121,9 +122,9 @@ async function getObjectColumns(
121122

122123
completionItems = columns.map((i) =>
123124
createCompletionItem(
124-
Statement.prettyName(i.COLUMN_NAME),
125+
Statement.prettyName(useSystemNamesInColumn ? i.SYSTEM_COLUMN_NAME : i.COLUMN_NAME),
125126
CompletionItemKind.Field,
126-
getColumnAttributes(i),
127+
getColumnAttributes(i, useSystemNamesInColumn),
127128
`Schema: ${schema}\nTable: ${name}\n`,
128129
`a@objectcolumn`
129130
)
@@ -268,7 +269,8 @@ async function getCompletionItemsForTriggerDot(
268269
const completionItems = await getObjectColumns(
269270
curRefIdentifier.object.schema,
270271
curRefIdentifier.object.name,
271-
curRefIdentifier.isUDTF
272+
curRefIdentifier.isUDTF,
273+
useSystemNames()
272274
);
273275

274276
list.push(...completionItems);
@@ -346,7 +348,7 @@ async function getCompletionItemsForRefs(currentStatement: LanguageStatement.def
346348
// Fetch all the columns for tables that have references in the statement
347349
const tableItemPromises = objectRefs.map((ref) =>
348350
ref.object.name && ref.object.schema
349-
? getObjectColumns(ref.object.schema, ref.object.name, ref.isUDTF)
351+
? getObjectColumns(ref.object.schema, ref.object.name, ref.isUDTF, useSystemNames())
350352
: Promise.resolve([])
351353
);
352354
const results = await Promise.allSettled(tableItemPromises);

src/language/providers/contributes.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"configuration": [
44
{
55
"id": "vscode-db2i.syntax",
6-
"title": "SQL Syntax Checking",
6+
"title": "SQL Syntax Options",
77
"properties": {
88
"vscode-db2i.syntax.checkOnOpen": {
99
"type": "boolean",
@@ -24,6 +24,11 @@
2424
"type": "boolean",
2525
"description": "Whether SQL syntax warnings should show in the editor",
2626
"default": false
27+
},
28+
"vscode-db2i.syntax.useSystemNames": {
29+
"type": "boolean",
30+
"description": "Whether to use system names for columns in the content assist",
31+
"default": false
2732
}
2833
}
2934
}

src/language/providers/logic/available.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import { env } from "process";
33
import { ServerComponent } from "../../../connection/serverComponent";
44
import { JobManager } from "../../../config";
55
import { JobInfo } from "../../../connection/manager";
6+
import Configuration from "../../../configuration";
7+
8+
export function useSystemNames() {
9+
return Configuration.get<boolean>(`syntax.useSystemNames`) || false;
10+
}
611

712
export function localAssistIsEnabled() {
813
return (env.DB2I_DISABLE_CA !== `true`);

src/language/providers/statusProvider.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Disposable, languages, LanguageStatusSeverity } from "vscode";
22
import { SQLStatementChecker } from "../../connection/syntaxChecker";
33
import { getCheckerTimeout } from "./problemProvider";
4+
import { useSystemNames } from "./logic/available";
45

56
export class Db2StatusProvider extends Disposable {
67
private item = languages.createLanguageStatusItem(`sql`, {language: `sql`});
@@ -16,7 +17,12 @@ export class Db2StatusProvider extends Disposable {
1617
const checker = SQLStatementChecker.get();
1718
const checkerTimeout = getCheckerTimeout() / 1000;
1819
this.item.text = `SQL assistance available. ${checker ? `Syntax checking enabled (every ${checkerTimeout}s after editing)` : `Syntax checking not available.`}`;
19-
this.item.detail = `You're connected to an IBM i - you can use the advanced SQL language tooling. ${checker ? `` : `Syntax checking not available. This means that the syntax checker did not install when connecting to this system.`}`;
20+
this.item.detail = `You're connected to an IBM i. ${checker ? `You can use the advanced SQL language tooling.` : `Syntax checking not available. This means that the syntax checker did not install when connecting to this system.`}`;
21+
this.item.detail = [
22+
`You're connected to an IBM i.`,
23+
checker ? `You can use the advanced SQL language tooling.` : `Syntax checking not available. This means that the syntax checker did not install when connecting to this system.`,
24+
(useSystemNames() ? `System names` : `SQL names`) + ` for columns will be used in the content assist.`
25+
].join(` `);
2026
this.item.severity = checker ? LanguageStatusSeverity.Information : LanguageStatusSeverity.Warning;
2127
} else {
2228
this.item.text = `Basic SQL assistance available`;

0 commit comments

Comments
 (0)