You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Query Tool autocomplete never reuses a result when there is text after the cursor #10819
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
Enable Autocomplete on key press.
In the Query Tool, type SELECT FROM demo_table;, put the cursor after SELECT , and type dem slowly.
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.
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?
@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.
Activity
shuseng8 commentedon Nov 26, 2026
Hi @dpage, I'd like to take this one. I have a small fix ready that limits the
validForcheck 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?dpage commentedon Nov 26, 2026
@shuseng8, thanks for offering, and I've assigned it to you. #10787 now rewrites the same
validForcheck (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.Add a regression test for Query Tool autocomplete reuse when there is…
Add a regression test for Query Tool autocomplete reuse when there is…