Skip to content

Commit

Permalink
Quote completions with upper-case characters
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marijnh committed Dec 11, 2023
1 parent 4b7b256 commit 15cd610
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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*[`'"]?$/
Expand All @@ -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}
}

Expand Down

1 comment on commit 15cd610

@adityatoshniwal
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But in PostgreSQL the quote logic is completely different.

Please sign in to comment.