Skip to content

Commit 4d9d8be

Browse files
committed
style(sql-completion): apply formatting
1 parent 026adc2 commit 4d9d8be

4 files changed

Lines changed: 26 additions & 34 deletions

File tree

ui/chen/api/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import type {
2-
ChenActionItem,
3-
ChenAuthResponse,
4-
ChenProfile,
5-
ChenTreeNode
6-
} from "~/chen/types";
1+
import type { ChenActionItem, ChenAuthResponse, ChenProfile, ChenTreeNode } from "~/chen/types";
72
import type {
83
ChenQualifiedRelation,
94
ChenRelationColumnsMetadata,

ui/chen/utils/sqlCompletion.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,13 @@ export function createChenCompletionSource(options: ChenCompletionSourceOptions)
4444
if (!scope?.nodeKey || !scope.context) return null;
4545

4646
let cancelled = false;
47-
context.addEventListener("abort", () => {
48-
cancelled = true;
49-
}, { onDocChange: true });
47+
context.addEventListener(
48+
"abort",
49+
() => {
50+
cancelled = true;
51+
},
52+
{ onDocChange: true }
53+
);
5054

5155
try {
5256
const analysis = analyzeChenSqlCompletion(context.state.doc.toString(), context.pos);
@@ -70,14 +74,15 @@ export function createChenCompletionSource(options: ChenCompletionSourceOptions)
7074
if (relation) {
7175
const columns = await options.store.getColumns(scope, [relation]);
7276
if (cancelled) return null;
73-
return qualifiedColumnCompletion(relation, columnsFor(columns, relation), scope.context, options.dialect())(
74-
context
75-
);
77+
return qualifiedColumnCompletion(
78+
relation,
79+
columnsFor(columns, relation),
80+
scope.context,
81+
options.dialect()
82+
)(context);
7683
}
7784

78-
const schemaRelations = lookup.page.items.filter((item) =>
79-
identifiersEqual(item.schema, analysis.qualifier)
80-
);
85+
const schemaRelations = lookup.page.items.filter((item) => identifiersEqual(item.schema, analysis.qualifier));
8186
if (schemaRelations.length) {
8287
return relationCompletion(schemaRelations, scope.context, options.dialect())(context);
8388
}
@@ -109,12 +114,11 @@ export function analyzeChenSqlCompletion(sql: string, position = sql.length): Ch
109114
const statementEnd = nextSeparator === -1 ? sql.length : nextSeparator;
110115
const statement = sql.slice(statementStart, statementEnd);
111116
const beforeCursor = sql.slice(statementStart, position);
112-
const relationMatch = beforeCursor.match(
113-
/\b(?:from|join|update|into)\s+((?:[a-z_][\w$]*\.)?[a-z_][\w$]*)?$/i
114-
);
117+
const relationMatch = beforeCursor.match(/\b(?:from|join|update|into)\s+((?:[a-z_][\w$]*\.)?[a-z_][\w$]*)?$/i);
115118
const qualifierMatch = beforeCursor.match(/(?:^|[^\w$])([a-z_][\w$]*)\.\s*[\w$]*$/i);
116119
const references: ChenSqlCompletionAnalysis["references"] = [];
117-
const relationPattern = /\b(?:from|join|update|into)\s+([a-z_][\w$]*(?:\s*\.\s*[a-z_][\w$]*)?)(?:\s+(?:as\s+)?([a-z_][\w$]*))?/gi;
120+
const relationPattern =
121+
/\b(?:from|join|update|into)\s+([a-z_][\w$]*(?:\s*\.\s*[a-z_][\w$]*)?)(?:\s+(?:as\s+)?([a-z_][\w$]*))?/gi;
118122

119123
// ponytail: This intentionally handles simple relation references only. Replace
120124
// it with syntax-tree scope walking when CTEs, quoted identifiers, or comma joins
@@ -139,7 +143,9 @@ async function resolveReferencedRelations(
139143
scope: ChenSqlMetadataScope,
140144
references: ChenSqlCompletionAnalysis["references"]
141145
) {
142-
const relations = await Promise.all(references.map((reference) => resolveRelation(store, scope, reference.identifier)));
146+
const relations = await Promise.all(
147+
references.map((reference) => resolveRelation(store, scope, reference.identifier))
148+
);
143149
return [...new Map(relations.filter(Boolean).map((relation) => [relationIdentity(relation!), relation!])).values()];
144150
}
145151

@@ -160,11 +166,9 @@ async function lookupRelation(store: ChenSqlMetadataStore, scope: ChenSqlMetadat
160166
);
161167
if (candidates.length <= 1) return { relation: candidates[0] || null, page };
162168
const defaultSchema = defaultSchemaFor(candidates, scope.context);
163-
const relation = (
164-
(defaultSchema
165-
? candidates.find((candidate) => identifiersEqual(candidate.schema, defaultSchema))
166-
: undefined) || candidates[0]
167-
);
169+
const relation =
170+
(defaultSchema ? candidates.find((candidate) => identifiersEqual(candidate.schema, defaultSchema)) : undefined) ||
171+
candidates[0];
168172
return { relation, page };
169173
}
170174

ui/chen/utils/sqlEditor.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ export function chenSqlDialect(dbType: string) {
2424

2525
export function chenSqlExtensions(dbType: string, completionSource?: ChenSqlCompletionSource): Extension {
2626
const dialect = chenSqlDialect(dbType);
27-
return [
28-
sql({ dialect }),
29-
completionSource ? dialect.language.data.of({ autocomplete: completionSource }) : []
30-
];
27+
return [sql({ dialect }), completionSource ? dialect.language.data.of({ autocomplete: completionSource }) : []];
3128
}
3229

3330
export function replaceChenSqlDocument(editor: Pick<EditorView, "dispatch" | "state">, value: string) {

ui/chen/utils/sqlMetadata.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import type {
77
} from "~/chen/types/sqlMetadata";
88

99
export interface ChenSqlMetadataClient {
10-
listRelations: (
11-
scope: ChenSqlMetadataScope,
12-
prefix: string,
13-
limit: number
14-
) => Promise<ChenRelationMetadataPage>;
10+
listRelations: (scope: ChenSqlMetadataScope, prefix: string, limit: number) => Promise<ChenRelationMetadataPage>;
1511
listColumns: (
1612
scope: ChenSqlMetadataScope,
1713
relations: ChenQualifiedRelation[]

0 commit comments

Comments
 (0)