Skip to content

Highlighter's SQL lexer (sql-highlight.js) still duplicates literal/comment rules and diverges on '' escapes #141

Description

@BorisTyshkevich

Found while shipping #139 (shared SQL span-scanner)

#139 unified the literal/comment lexer shared by src/core/sql-split.js
(splitStatements) and src/core/query-params.js (detectParams) into
src/core/sql-spans.js scanSpans. But a third SQL lexer still lives in
src/core/sql-highlight.js tokenize (the editor highlighter + its maskLiterals
mask, used for bracket matching #24, signature help #27, and auto-close), and its
string-scanning rules differ:

  • tokenize (src/core/sql-highlight.js:57-66) does not honor doubled-quote
    ('') escapes — its loop stops at the first unescaped closing quote. So
    'it''s' tokenizes as 'it' (string) + s (ident) + ' (unterminated
    string), whereas scanSpans / splitStatements correctly treat 'it''s' as
    one literal.

Impact (low, pre-existing): cosmetic mis-highlighting of a string containing a
doubled single-quote, and — via maskLiterals — a slightly wrong literal mask
there, so bracket-matching / auto-close / signature-help can misbehave while the
caret is inside such a string. Not a correctness bug in query execution (split and
param detection use the correct scanSpans).

Why deferred from #139: scanSpans yields only coarse code/string/comment
spans; the highlighter needs finer token types (keyword / func / number /
operator / ident), so it can't consume scanSpans as-is. Unifying means either
extending scanSpans to a full tokenizer or layering the highlighter's
type-classification on top of the shared literal/comment pass — a bigger change
than #139's scope (which named only sql-split + query-params).

Proposal: either (a) fix tokenize's string loop to honor '' (and \)
consistently with scanSpans, or (b) rebuild the highlighter on top of the shared
span pass so all three consumers share one set of literal/comment rules. See the
docstring note in src/core/sql-spans.js for the code-vs-comment-vs-string
distinction that must be preserved.

file:line — src/core/sql-highlight.js:57-66 (tokenize string branch).

Metadata

Metadata

Assignees

No one assigned

    Labels

    inboxFiled mid-task; not yet triaged into the roadmap

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions