From 15cd6107855a5b4357bc24763931d21b443b7bf3 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 11 Dec 2023 15:44:25 +0100 Subject: [PATCH] Quote completions with upper-case characters FIX: Make sure table and column completions with upper-case characters are quoted. See https://discuss.codemirror.net/t/postgresql-autocomplete-incorrect-for-quoted-tables/7543/3 --- src/complete.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/complete.ts b/src/complete.ts index 86cfb34..63595c4 100644 --- a/src/complete.ts +++ b/src/complete.ts @@ -88,7 +88,7 @@ function getAliases(doc: Text, at: SyntaxNode) { function maybeQuoteCompletions(quote: string | null, completions: readonly Completion[]) { if (!quote) return completions - return completions.map(c => ({...c, label: quote + c.label + quote, apply: undefined})) + return completions.map(c => ({...c, label: c.label[0] == quote ? c.label : quote + c.label + quote, apply: undefined})) } const Span = /^\w*$/, QuotedSpan = /^[`'"]?\w*[`'"]?$/ @@ -115,7 +115,7 @@ class CompletionLevel { } function nameCompletion(label: string, type: string, idQuote: string): Completion { - if (!/[^\w\xb5-\uffff]/.test(label)) return {label, type} + if (/^[a-z_][a-z_\d]*$/.test(label)) return {label, type} return {label, type, apply: idQuote + label + idQuote} }