Skip to content

Implement option to use system names for columns in content assist #375

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

Merged
merged 2 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
},
{
"id": "vscode-db2i.syntax",
"title": "SQL Syntax Checking",
"title": "SQL Syntax Options",
"properties": {
"vscode-db2i.syntax.checkOnOpen": {
"type": "boolean",
Expand All @@ -232,6 +232,11 @@
"type": "boolean",
"description": "Whether SQL syntax warnings should show in the editor",
"default": false
},
"vscode-db2i.syntax.useSystemNames": {
"type": "boolean",
"description": "Whether to use system names for columns in the content assist",
"default": false
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/database/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default class Table {
`SELECT `,
` column.TABLE_SCHEMA,`,
` column.TABLE_NAME,`,
` column.SYSTEM_COLUMN_NAME,`,
` column.COLUMN_NAME,`,
` key.CONSTRAINT_NAME,`,
` column.DATA_TYPE, `,
Expand Down
18 changes: 10 additions & 8 deletions src/language/providers/completionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CTEReference, ClauseType, ObjectRef, StatementType } from "../sql/types
import { CallableType } from "../../database/callable";
import { prepareParamType, createCompletionItem, getParmAttributes } from "./logic/completion";
import { isCallableType, getCallableParameters } from "./logic/callable";
import { localAssistIsEnabled, remoteAssistIsEnabled } from "./logic/available";
import { localAssistIsEnabled, remoteAssistIsEnabled, useSystemNames } from "./logic/available";
import { DbCache } from "./logic/cache";
import { getSqlDocument } from "./logic/parse";
import { TableColumn, BasicSQLObject } from "../../types";
Expand Down Expand Up @@ -57,9 +57,9 @@ const completionTypes: { [index: string]: CompletionType } = {



function getColumnAttributes(column: TableColumn): string {
function getColumnAttributes(column: TableColumn, useSystemName: boolean): string {
const lines: string[] = [
`Column: ${column.COLUMN_NAME}`,
`Column: ${useSystemName ? column.SYSTEM_COLUMN_NAME : column.COLUMN_NAME}`,
`Type: ${prepareParamType(column)}`,
`HAS_DEFAULT: ${column.HAS_DEFAULT}`,
`IS_IDENTITY: ${column.IS_IDENTITY}`,
Expand All @@ -85,7 +85,8 @@ function getAllColumns(name: string, schema: string, items: CompletionItem[]) {
async function getObjectColumns(
schema: string,
name: string,
isUDTF = false
isUDTF: boolean,
useSystemNamesInColumn: boolean,
): Promise<CompletionItem[]> {

let completionItems: CompletionItem[];
Expand Down Expand Up @@ -121,9 +122,9 @@ async function getObjectColumns(

completionItems = columns.map((i) =>
createCompletionItem(
Statement.prettyName(i.COLUMN_NAME),
Statement.prettyName(useSystemNamesInColumn ? i.SYSTEM_COLUMN_NAME : i.COLUMN_NAME),
CompletionItemKind.Field,
getColumnAttributes(i),
getColumnAttributes(i, useSystemNamesInColumn),
`Schema: ${schema}\nTable: ${name}\n`,
`a@objectcolumn`
)
Expand Down Expand Up @@ -268,7 +269,8 @@ async function getCompletionItemsForTriggerDot(
const completionItems = await getObjectColumns(
curRefIdentifier.object.schema,
curRefIdentifier.object.name,
curRefIdentifier.isUDTF
curRefIdentifier.isUDTF,
useSystemNames()
);

list.push(...completionItems);
Expand Down Expand Up @@ -346,7 +348,7 @@ async function getCompletionItemsForRefs(currentStatement: LanguageStatement.def
// Fetch all the columns for tables that have references in the statement
const tableItemPromises = objectRefs.map((ref) =>
ref.object.name && ref.object.schema
? getObjectColumns(ref.object.schema, ref.object.name, ref.isUDTF)
? getObjectColumns(ref.object.schema, ref.object.name, ref.isUDTF, useSystemNames())
: Promise.resolve([])
);
const results = await Promise.allSettled(tableItemPromises);
Expand Down
7 changes: 6 additions & 1 deletion src/language/providers/contributes.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"configuration": [
{
"id": "vscode-db2i.syntax",
"title": "SQL Syntax Checking",
"title": "SQL Syntax Options",
"properties": {
"vscode-db2i.syntax.checkOnOpen": {
"type": "boolean",
Expand All @@ -24,6 +24,11 @@
"type": "boolean",
"description": "Whether SQL syntax warnings should show in the editor",
"default": false
},
"vscode-db2i.syntax.useSystemNames": {
"type": "boolean",
"description": "Whether to use system names for columns in the content assist",
"default": false
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/language/providers/logic/available.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { env } from "process";
import { ServerComponent } from "../../../connection/serverComponent";
import { JobManager } from "../../../config";
import { JobInfo } from "../../../connection/manager";
import Configuration from "../../../configuration";

export function useSystemNames() {
return Configuration.get<boolean>(`syntax.useSystemNames`) || false;
}

export function localAssistIsEnabled() {
return (env.DB2I_DISABLE_CA !== `true`);
Expand Down
8 changes: 7 additions & 1 deletion src/language/providers/statusProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Disposable, languages, LanguageStatusSeverity } from "vscode";
import { SQLStatementChecker } from "../../connection/syntaxChecker";
import { getCheckerTimeout } from "./problemProvider";
import { useSystemNames } from "./logic/available";

export class Db2StatusProvider extends Disposable {
private item = languages.createLanguageStatusItem(`sql`, {language: `sql`});
Expand All @@ -16,7 +17,12 @@ export class Db2StatusProvider extends Disposable {
const checker = SQLStatementChecker.get();
const checkerTimeout = getCheckerTimeout() / 1000;
this.item.text = `SQL assistance available. ${checker ? `Syntax checking enabled (every ${checkerTimeout}s after editing)` : `Syntax checking not available.`}`;
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.`}`;
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.`}`;
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.`,
(useSystemNames() ? `System names` : `SQL names`) + ` for columns will be used in the content assist.`
].join(` `);
this.item.severity = checker ? LanguageStatusSeverity.Information : LanguageStatusSeverity.Warning;
} else {
this.item.text = `Basic SQL assistance available`;
Expand Down
Loading