11import { EditorState } from "@codemirror/state"
22import { CompletionContext , CompletionResult , CompletionSource } from "@codemirror/autocomplete"
3- import { schemaCompletionSource , keywordCompletionSource , PostgreSQL , MySQL , SQLConfig , SQLDialect } from "@codemirror/lang-sql"
3+ import { schemaCompletionSource , keywordCompletionSource , PostgreSQL , MySQL , SQLConfig , SQLDialect , MSSQL } from "@codemirror/lang-sql"
44import ist from "ist"
55
66function get ( doc : string , conf : SQLConfig & { explicit ?: boolean , keywords ?: boolean } = { } ) {
@@ -94,6 +94,11 @@ describe("SQL completion", () => {
9494 ist ( str ( get ( 'select "other"."users"."|' , { schema : schema2 } ) ) , '"id", "name"' )
9595 } )
9696
97+ it ( "completes column names in bracket quoted tables with MSSQL" , ( ) => {
98+ ist ( str ( get ( "select [public].[users].|" , { schema : schema2 , dialect : MSSQL } ) ) , "email, id" )
99+ ist ( str ( get ( "select [other].[users].|" , { schema : schema2 , dialect : MSSQL } ) ) , "id, name" )
100+ } )
101+
97102 it ( "completes column names of aliased tables" , ( ) => {
98103 ist ( str ( get ( "select u.| from users u" , { schema : schema1 } ) ) , "address, id, name" )
99104 ist ( str ( get ( "select u.| from users as u" , { schema : schema1 } ) ) , "address, id, name" )
@@ -126,6 +131,11 @@ describe("SQL completion", () => {
126131 ist ( str ( get ( 'select a| from a.b as ab join auto au' , { schema : schema2 } ) ) , "ab, au, other, public" )
127132 } )
128133
134+ it ( "completes bracket quoted aliases with MSSQL" , ( ) => {
135+ ist ( str ( get ( "select u.| from public.users [u]" , { schema : schema2 , dialect : MSSQL } ) ) , "email, id" )
136+ ist ( str ( get ( "select [u].| from public.users u" , { schema : schema2 , dialect : MSSQL } ) ) , "email, id" )
137+ } )
138+
129139 it ( "includes closing quote in completion" , ( ) => {
130140 let r = get ( 'select "u|"' , { schema : schema1 } )
131141 ist ( r ! . to , 10 )
@@ -147,6 +157,7 @@ describe("SQL completion", () => {
147157
148158 it ( "supports alternate quoting styles" , ( ) => {
149159 ist ( str ( get ( "select `u|" , { dialect : MySQL , schema : schema1 } ) ) , "`products`, `users`" )
160+ ist ( str ( get ( "select [u|" , { dialect : MSSQL , schema : schema1 } ) ) , "[products], [users]" )
150161 } )
151162
152163 it ( "doesn't complete without identifier" , ( ) => {
@@ -173,6 +184,13 @@ describe("SQL completion", () => {
173184 'Column, cell' )
174185 } )
175186
187+ it ( "can add MSSQL-style brackets as identifier quotes" , ( ) => {
188+ let dialect = SQLDialect . define ( { ...MSSQL . spec , identifierQuotes : '[' } ) ;
189+ let config = { schema : { "Foo" : [ "Bar" ] } , dialect : dialect } ;
190+
191+ ist ( str ( get ( "[Foo].b|" , config ) ) , "[Bar]" ) ;
192+ } )
193+
176194 it ( "supports nesting more than two deep" , ( ) => {
177195 let s = { schema : { "one.two.three" : [ "four" ] } }
178196 ist ( str ( get ( "o|" , s ) ) , "one" )
0 commit comments