Skip to content

Query Tool autocomplete never reuses a result when there is text after the cursor #10819

Done

Description

@dpage

The completion source's validFor check compares the typed text with everything from the start of the word to the end of the document, not to the cursor. When there is any text after the cursor, which is the usual case when editing inside an existing query, the check always fails, so CodeMirror never filters the result it already has and sends a new autocomplete request on every pause.

Steps to reproduce

  1. Enable Autocomplete on key press.
  2. In the Query Tool, type SELECT FROM demo_table;, put the cursor after SELECT , and type dem slowly.
  3. Watch the network tab.

Expected

One request; later keystrokes filter its results whilst the typed text still extends the original word.

Actual

A new /sqleditor/autocomplete/ request on each pause. At the end of the document it works, because there the slice happens to end at the cursor.

Cause

web/pgadmin/tools/sqleditor/static/js/components/sections/Query.jsx:37 captures the whole document as fullSql, and line 48 checks text.startsWith(fullSql.slice(from)). CodeMirror passes text as sliceDoc(from, to), ending at the cursor, so with trailing text fullSql.slice(from) is always longer than text. Slicing to the cursor position at request time (fullSql.slice(from, head)) would fix it.

Open PR #10787, which reworks this completion source, keeps the same fullSql.slice(from) comparison (adding only a /^\w*$/ check), so it does not fix this as it stands.

Activity

  1. shuseng8 commented on Nov 26, 2026

    @shuseng8
    Contributor

    Hi @dpage, I'd like to take this one. I have a small fix ready that limits the validFor check to the cursor (fullSql.slice(from, head)), with Jest coverage for text after the cursor. I noticed #10787 now changes the same line as part of the debounce work. Would you like a standalone PR for this, or should it wait for #10787?

  2. dpage commented on Nov 26, 2026

    @dpage
    ContributorAuthor

    @shuseng8, thanks for offering, and I've assigned it to you. #10787 now rewrites the same validFor check (it compares against the completed word rather than everything to the end of the document), which should fix this too, so a standalone PR would only conflict with it. Could you wait for #10787 to land, then check whether your Jest case still finds anything? If it does, please send a PR on top of it; if not, a PR that just adds your test for text after the cursor would still be welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions