diff --git a/src/complete.ts b/src/complete.ts index 0e64bfd..cb4b839 100644 --- a/src/complete.ts +++ b/src/complete.ts @@ -127,8 +127,8 @@ export function completeFromSchema(schema: {[table: string]: readonly (string | let idQuote = dialect?.spec.identifierQuotes?.[0] || '"' let defaultSchema = top.child(defaultSchemaName || "", idQuote) for (let table in schema) { - let parts = table.split("."), base = parts.length == 1 ? defaultSchema : top - for (let part of parts) base = base.child(part, idQuote) + let parts = table.split(/(? (b.boost || 0) - (a.boost || 0) || (a.label < b.label ? -1 : 1)) - .map(o => o.label) + .map(o => o.apply || o.label) .join(", ") } @@ -156,10 +156,10 @@ describe("SQL completion", () => { }) it("adds identifiers for non-word completions", () => { - ist(get("foo.b|", {schema: {foo: ["b c", "b-c", "bup"]}, dialect: PostgreSQL})! - .options.map(o => o.apply || o.label).join(), '"b c","b-c",bup') - ist(get("foo.b|", {schema: {foo: ["b c", "b-c", "bup"]}, dialect: MySQL})! - .options.map(o => o.apply || o.label).join(), '`b c`,`b-c`,bup') + ist(str(get("foo.b|", {schema: {foo: ["b c", "b-c", "bup"]}, dialect: PostgreSQL})), + '"b c", "b-c", bup') + ist(str(get("foo.b|", {schema: {foo: ["b c", "b-c", "bup"]}, dialect: MySQL})), + '`b c`, `b-c`, bup') }) it("supports nesting more than two deep", () => { @@ -169,4 +169,10 @@ describe("SQL completion", () => { ist(str(get("one.two.|", s)), "three") ist(str(get("one.two.three.|", s)), "four") }) + + it("supports escaped dots in table names", () => { + let s = {schema: {"db\\.conf": ["abc"]}} + ist(str(get("db|", s)), '"db.conf"') + ist(str(get('"db.conf".|', s)), "abc") + }) })