@@ -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 (?: f r o m | j o i n | u p d a t e | i n t o ) \s + ( (?: [ a - z _ ] [ \w $ ] * \. ) ? [ a - z _ ] [ \w $ ] * ) ? $ / i
114- ) ;
117+ const relationMatch = beforeCursor . match ( / \b (?: f r o m | j o i n | u p d a t e | i n t o ) \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 (?: f r o m | j o i n | u p d a t e | i n t o ) \s + ( [ a - z _ ] [ \w $ ] * (?: \s * \. \s * [ a - z _ ] [ \w $ ] * ) ? ) (?: \s + (?: a s \s + ) ? ( [ a - z _ ] [ \w $ ] * ) ) ? / gi;
120+ const relationPattern =
121+ / \b (?: f r o m | j o i n | u p d a t e | i n t o ) \s + ( [ a - z _ ] [ \w $ ] * (?: \s * \. \s * [ a - z _ ] [ \w $ ] * ) ? ) (?: \s + (?: a s \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
0 commit comments