fix(completion): respect identifier quoting for oracle completions
This commit is contained in:
1 parent
99d2aa5f13
commit
2a8e329d05
3 files changed
+29
-1
No files matched your search
@@ -5292,6 +5292,7 @@ async function provideSqlCompletions(context: CompletionContext) {
|
|||||||
keywordCase: settingsStore.editorSettings.sqlFormatter.keywordCase,
|
keywordCase: settingsStore.editorSettings.sqlFormatter.keywordCase,
|
||||||
functionCase: settingsStore.editorSettings.sqlFormatter.functionCase,
|
functionCase: settingsStore.editorSettings.sqlFormatter.functionCase,
|
||||||
autoAliasTables: settingsStore.editorSettings.autoAliasTables,
|
autoAliasTables: settingsStore.editorSettings.autoAliasTables,
|
||||||
|
quoteIdentifiers: settingsStore.editorSettings.generateSqlQuoteIdentifiers,
|
||||||
});
|
});
|
||||||
return buildSqlCompletionResult(items, completionContext, fullDoc, position);
|
return buildSqlCompletionResult(items, completionContext, fullDoc, position);
|
||||||
}
|
}
|
||||||
@@ -5353,6 +5354,7 @@ async function provideSqlCompletions(context: CompletionContext) {
|
|||||||
keywordCase: settingsStore.editorSettings.sqlFormatter.keywordCase,
|
keywordCase: settingsStore.editorSettings.sqlFormatter.keywordCase,
|
||||||
functionCase: settingsStore.editorSettings.sqlFormatter.functionCase,
|
functionCase: settingsStore.editorSettings.sqlFormatter.functionCase,
|
||||||
autoAliasTables: settingsStore.editorSettings.autoAliasTables,
|
autoAliasTables: settingsStore.editorSettings.autoAliasTables,
|
||||||
|
quoteIdentifiers: settingsStore.editorSettings.generateSqlQuoteIdentifiers,
|
||||||
});
|
});
|
||||||
return buildSqlCompletionResult(items, completionContext, fullDoc, position);
|
return buildSqlCompletionResult(items, completionContext, fullDoc, position);
|
||||||
}
|
}
|
||||||
@@ -5693,6 +5695,7 @@ function buildLocalSqlCompletionResult(completionContext: ReturnType<typeof getS
|
|||||||
keywordCase: settingsStore.editorSettings.sqlFormatter.keywordCase,
|
keywordCase: settingsStore.editorSettings.sqlFormatter.keywordCase,
|
||||||
functionCase: settingsStore.editorSettings.sqlFormatter.functionCase,
|
functionCase: settingsStore.editorSettings.sqlFormatter.functionCase,
|
||||||
autoAliasTables: settingsStore.editorSettings.autoAliasTables,
|
autoAliasTables: settingsStore.editorSettings.autoAliasTables,
|
||||||
|
quoteIdentifiers: settingsStore.editorSettings.generateSqlQuoteIdentifiers,
|
||||||
});
|
});
|
||||||
|
|
||||||
return buildSqlCompletionResult(items, completionContext, fullDoc, position);
|
return buildSqlCompletionResult(items, completionContext, fullDoc, position);
|
||||||
@@ -6196,6 +6199,7 @@ async function performAsyncCompletionWithResult(epoch: number, completionContext
|
|||||||
keywordCase: settingsStore.editorSettings.sqlFormatter.keywordCase,
|
keywordCase: settingsStore.editorSettings.sqlFormatter.keywordCase,
|
||||||
functionCase: settingsStore.editorSettings.sqlFormatter.functionCase,
|
functionCase: settingsStore.editorSettings.sqlFormatter.functionCase,
|
||||||
autoAliasTables: settingsStore.editorSettings.autoAliasTables,
|
autoAliasTables: settingsStore.editorSettings.autoAliasTables,
|
||||||
|
quoteIdentifiers: settingsStore.editorSettings.generateSqlQuoteIdentifiers,
|
||||||
});
|
});
|
||||||
|
|
||||||
return buildSqlCompletionResult(items, completionContext, fullDoc, position);
|
return buildSqlCompletionResult(items, completionContext, fullDoc, position);
|
||||||
|
|||||||
@@ -70,3 +70,23 @@ describe("oracle completion apply identifiers", () => {
|
|||||||
expect(routine?.apply).toBe('"GetBom"()');
|
expect(routine?.apply).toBe('"GetBom"()');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("oracle completion with identifier quoting disabled (#9735)", () => {
|
||||||
|
const sql = "SELECT t.c FROM abc t";
|
||||||
|
const cursor = "SELECT t.c".length;
|
||||||
|
const input = {
|
||||||
|
databaseType: "oracle" as const,
|
||||||
|
tables: [{ name: "abc", type: "table" as const }],
|
||||||
|
columnsByTable: new Map([["abc", [{ name: "col1", table: "abc" }]]]),
|
||||||
|
};
|
||||||
|
const applyOf = (extra: { quoteIdentifiers?: boolean }) => buildSqlCompletionItems(sql, cursor, { ...input, ...extra }).find((item) => item.label === "col1")?.apply;
|
||||||
|
|
||||||
|
it("keeps lowercase columns bare when quoting is disabled", () => {
|
||||||
|
expect(applyOf({ quoteIdentifiers: false })).toBe("col1");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("still quotes lowercase columns by default and when quoting is enabled", () => {
|
||||||
|
expect(applyOf({})).toBe('"col1"');
|
||||||
|
expect(applyOf({ quoteIdentifiers: true })).toBe('"col1"');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1548,6 +1548,7 @@ export interface SqlCompletionProviderInput {
|
|||||||
keywordCase?: SqlKeywordCase;
|
keywordCase?: SqlKeywordCase;
|
||||||
functionCase?: SqlKeywordCase;
|
functionCase?: SqlKeywordCase;
|
||||||
autoAliasTables?: boolean;
|
autoAliasTables?: boolean;
|
||||||
|
quoteIdentifiers?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildSqlCompletionItems(
|
export function buildSqlCompletionItems(
|
||||||
@@ -1567,6 +1568,7 @@ export function buildSqlCompletionItems(
|
|||||||
keywordCase?: SqlKeywordCase;
|
keywordCase?: SqlKeywordCase;
|
||||||
functionCase?: SqlKeywordCase;
|
functionCase?: SqlKeywordCase;
|
||||||
autoAliasTables?: boolean;
|
autoAliasTables?: boolean;
|
||||||
|
quoteIdentifiers?: boolean;
|
||||||
},
|
},
|
||||||
): SqlCompletionItem[] {
|
): SqlCompletionItem[] {
|
||||||
if (isSqlCompletionSuppressedContext(sql, cursor, input)) return [];
|
if (isSqlCompletionSuppressedContext(sql, cursor, input)) return [];
|
||||||
@@ -1589,7 +1591,9 @@ class SqlCompletionProvider {
|
|||||||
private readonly input: SqlCompletionProviderInput,
|
private readonly input: SqlCompletionProviderInput,
|
||||||
) {
|
) {
|
||||||
this.t = input.translations;
|
this.t = input.translations;
|
||||||
this.dialect = sqlCompletionApplyDialect(input.databaseType, input.dialect);
|
const dialect = sqlCompletionApplyDialect(input.databaseType, input.dialect);
|
||||||
|
// "Quote identifiers in generated SQL" off: Oracle completion inserts bare names instead of quoting lowercase ones.
|
||||||
|
this.dialect = dialect === "oracle" && input.quoteIdentifiers === false ? undefined : dialect;
|
||||||
this.databaseType = input.databaseType;
|
this.databaseType = input.databaseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user