feat(completion): fix SQL alias completion, star expansion, and formatter layout

This commit is contained in:
jinmo authored and GitHub committed 2026-08-10 01:11:25 +08:00
1 parent 0402fea37b
commit 868f7961e3
30 files changed
+758 -76

No files matched your search

+11 -2
View File
@@ -3,7 +3,8 @@ export const SQL_FORMATTER_CONFIG_FORMATTER = "sql-formatter";
const CASE_VALUES = ["preserve", "upper", "lower"] as const;
const INDENT_STYLE_VALUES = ["standard", "tabularLeft", "tabularRight"] as const;
const LOGICAL_OPERATOR_NEWLINE_VALUES = ["before", "after"] as const;
const LOGICAL_OPERATOR_NEWLINE_VALUES = ["before", "after", "none"] as const;
const FROM_CLAUSE_LAYOUT_VALUES = ["newLine", "sameLine"] as const;
const TAB_WIDTH_VALUES = [2, 4] as const;
const EXPRESSION_WIDTH_VALUES = [50, 80, 120] as const;
const LINES_BETWEEN_QUERIES_VALUES = [0, 1, 2] as const;
@@ -14,6 +15,7 @@ const SQL_FORMATTER_LEGACY_OPTION_KEYS = new Set(["params"]);
export type SqlFormatterCase = (typeof CASE_VALUES)[number];
export type SqlFormatterIndentStyle = (typeof INDENT_STYLE_VALUES)[number];
export type SqlFormatterLogicalOperatorNewline = (typeof LOGICAL_OPERATOR_NEWLINE_VALUES)[number];
export type SqlFormatterFromClauseLayout = (typeof FROM_CLAUSE_LAYOUT_VALUES)[number];
export type SqlFormatterTabWidth = (typeof TAB_WIDTH_VALUES)[number];
export type SqlFormatterExpressionWidth = (typeof EXPRESSION_WIDTH_VALUES)[number];
export type SqlFormatterLinesBetweenQueries = (typeof LINES_BETWEEN_QUERIES_VALUES)[number];
@@ -44,6 +46,7 @@ export interface SqlFormatterOptionSettings {
useTabs: boolean;
tabWidth: SqlFormatterTabWidth;
logicalOperatorNewline: SqlFormatterLogicalOperatorNewline;
fromClauseLayout: SqlFormatterFromClauseLayout;
expressionWidth: SqlFormatterExpressionWidth;
linesBetweenQueries: SqlFormatterLinesBetweenQueries;
denseOperators: boolean;
@@ -70,6 +73,7 @@ export const DEFAULT_SQL_FORMATTER_SETTINGS: SqlFormatterSettings = {
useTabs: false,
tabWidth: 2,
logicalOperatorNewline: "before",
fromClauseLayout: "newLine",
expressionWidth: 50,
linesBetweenQueries: 1,
denseOperators: false,
@@ -86,6 +90,7 @@ const SQL_FORMATTER_OPTION_KEYS = new Set<keyof SqlFormatterOptionSettings>([
"useTabs",
"tabWidth",
"logicalOperatorNewline",
"fromClauseLayout",
"expressionWidth",
"linesBetweenQueries",
"denseOperators",
@@ -102,6 +107,7 @@ const SQL_FORMATTER_OPTION_VALIDATORS: Record<keyof SqlFormatterOptionSettings,
useTabs: (value) => typeof value === "boolean",
tabWidth: (value) => isNumberChoice(value, TAB_WIDTH_VALUES),
logicalOperatorNewline: (value) => isStringChoice(value, LOGICAL_OPERATOR_NEWLINE_VALUES),
fromClauseLayout: (value) => isStringChoice(value, FROM_CLAUSE_LAYOUT_VALUES),
expressionWidth: (value) => isNumberChoice(value, EXPRESSION_WIDTH_VALUES),
linesBetweenQueries: (value) => isNumberChoice(value, LINES_BETWEEN_QUERIES_VALUES),
denseOperators: (value) => typeof value === "boolean",
@@ -182,6 +188,7 @@ export function sqlFormatterOptionSettings(settings: unknown): SqlFormatterOptio
useTabs: normalizeBoolean(input.useTabs, DEFAULT_SQL_FORMATTER_SETTINGS.useTabs),
tabWidth: normalizeNumberChoice(input.tabWidth, TAB_WIDTH_VALUES, DEFAULT_SQL_FORMATTER_SETTINGS.tabWidth),
logicalOperatorNewline: normalizeChoice(input.logicalOperatorNewline, LOGICAL_OPERATOR_NEWLINE_VALUES, DEFAULT_SQL_FORMATTER_SETTINGS.logicalOperatorNewline),
fromClauseLayout: normalizeChoice(input.fromClauseLayout, FROM_CLAUSE_LAYOUT_VALUES, DEFAULT_SQL_FORMATTER_SETTINGS.fromClauseLayout),
expressionWidth: normalizeNumberChoice(input.expressionWidth, EXPRESSION_WIDTH_VALUES, DEFAULT_SQL_FORMATTER_SETTINGS.expressionWidth),
linesBetweenQueries: normalizeNumberChoice(input.linesBetweenQueries, LINES_BETWEEN_QUERIES_VALUES, DEFAULT_SQL_FORMATTER_SETTINGS.linesBetweenQueries),
denseOperators: normalizeBoolean(input.denseOperators, DEFAULT_SQL_FORMATTER_SETTINGS.denseOperators),
@@ -253,7 +260,9 @@ export function sqlFormatterOptions(settings: unknown) {
indentStyle: normalized.indentStyle,
useTabs: normalized.useTabs,
tabWidth: normalized.tabWidth,
logicalOperatorNewline: normalized.logicalOperatorNewline,
// sql-formatter itself only supports before/after. The custom "none"
// mode is applied as a post-processing pass by formatSqlText.
logicalOperatorNewline: normalized.logicalOperatorNewline === "none" ? "before" : normalized.logicalOperatorNewline,
expressionWidth: normalized.expressionWidth,
linesBetweenQueries: normalized.linesBetweenQueries,
denseOperators: normalized.denseOperators,