@@ -101,14 +101,14 @@ class CompletionLevel {
101101 list : Completion [ ] = [ ]
102102 children : { [ name : string ] : CompletionLevel } | undefined = undefined
103103
104- constructor ( readonly idQuote : string ) { }
104+ constructor ( readonly idQuote : string , readonly idCaseInsensitive ?: boolean ) { }
105105
106106 child ( name : string ) {
107107 let children = this . children || ( this . children = Object . create ( null ) )
108108 let found = children [ name ]
109109 if ( found ) return found
110- if ( name && ! this . list . some ( c => c . label == name ) ) this . list . push ( nameCompletion ( name , "type" , this . idQuote ) )
111- return ( children [ name ] = new CompletionLevel ( this . idQuote ) )
110+ if ( name && ! this . list . some ( c => c . label == name ) ) this . list . push ( nameCompletion ( name , "type" , this . idQuote , this . idCaseInsensitive ) )
111+ return ( children [ name ] = new CompletionLevel ( this . idQuote , this . idCaseInsensitive ) )
112112 }
113113
114114 maybeChild ( name : string ) {
@@ -123,7 +123,7 @@ class CompletionLevel {
123123
124124 addCompletions ( completions : readonly ( Completion | string ) [ ] ) {
125125 for ( let option of completions )
126- this . addCompletion ( typeof option == "string" ? nameCompletion ( option , "property" , this . idQuote ) : option )
126+ this . addCompletion ( typeof option == "string" ? nameCompletion ( option , "property" , this . idQuote , this . idCaseInsensitive ) : option )
127127 }
128128
129129 addNamespace ( namespace : SQLNamespace ) {
@@ -154,8 +154,9 @@ class CompletionLevel {
154154 }
155155}
156156
157- function nameCompletion ( label : string , type : string , idQuote : string ) : Completion {
158- if ( / ^ [ a - z _ ] [ a - z _ \d ] * $ / . test ( label ) ) return { label, type}
157+ function nameCompletion ( label : string , type : string , idQuote : string , idCaseInsensitive : boolean ) : Completion {
158+ const regex = new RegExp ( "^[a-z_][a-z_\\d]*$" , idCaseInsensitive ? 'i' : undefined ) ;
159+ if ( regex . test ( label ) ) return { label, type}
159160 return { label, type, apply : idQuote + label + idQuote }
160161}
161162
@@ -168,7 +169,7 @@ export function completeFromSchema(schema: SQLNamespace,
168169 defaultTableName ?: string , defaultSchemaName ?: string ,
169170 dialect ?: SQLDialect ) : CompletionSource {
170171 let idQuote = dialect ?. spec . identifierQuotes ?. [ 0 ] || '"'
171- let top = new CompletionLevel ( idQuote )
172+ let top = new CompletionLevel ( idQuote , dialect ?. spec . identifierCaseInsensitive )
172173 let defaultSchema = defaultSchemaName ? top . child ( defaultSchemaName ) : null
173174 top . addNamespace ( schema )
174175 if ( tables ) ( defaultSchema || top ) . addCompletions ( tables )
0 commit comments