diff --git a/package.json b/package.json index 92368f6d..5bf16360 100644 --- a/package.json +++ b/package.json @@ -211,7 +211,7 @@ }, { "id": "vscode-db2i.syntax", - "title": "SQL Syntax Checking", + "title": "SQL Syntax Options", "properties": { "vscode-db2i.syntax.checkOnOpen": { "type": "boolean", @@ -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 } } } diff --git a/src/database/table.ts b/src/database/table.ts index f54e673f..9fb43b61 100644 --- a/src/database/table.ts +++ b/src/database/table.ts @@ -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, `, diff --git a/src/language/providers/completionProvider.ts b/src/language/providers/completionProvider.ts index c72748f4..6460d664 100644 --- a/src/language/providers/completionProvider.ts +++ b/src/language/providers/completionProvider.ts @@ -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"; @@ -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}`, @@ -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[]; @@ -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` ) @@ -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); @@ -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); diff --git a/src/language/providers/contributes.json b/src/language/providers/contributes.json index 56b78d78..3002842a 100644 --- a/src/language/providers/contributes.json +++ b/src/language/providers/contributes.json @@ -3,7 +3,7 @@ "configuration": [ { "id": "vscode-db2i.syntax", - "title": "SQL Syntax Checking", + "title": "SQL Syntax Options", "properties": { "vscode-db2i.syntax.checkOnOpen": { "type": "boolean", @@ -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 } } } diff --git a/src/language/providers/logic/available.ts b/src/language/providers/logic/available.ts index d4342579..21b7378e 100644 --- a/src/language/providers/logic/available.ts +++ b/src/language/providers/logic/available.ts @@ -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`); diff --git a/src/language/providers/statusProvider.ts b/src/language/providers/statusProvider.ts index 242212d4..f8ed9ffa 100644 --- a/src/language/providers/statusProvider.ts +++ b/src/language/providers/statusProvider.ts @@ -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`}); @@ -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`;