Skip to content

Fix SQL mode showing each table entry twice#1775

Open
alex-fedotyev wants to merge 1 commit intografana:mainfrom
alex-fedotyev:cursor/fix-sql-duplicate-tables-a922
Open

Fix SQL mode showing each table entry twice#1775
alex-fedotyev wants to merge 1 commit intografana:mainfrom
alex-fedotyev:cursor/fix-sql-duplicate-tables-a922

Conversation

@alex-fedotyev
Copy link
Copy Markdown
Contributor

Type of Change

Please check the relevant option.

  • 🚀 Feature
  • 🐛 Bug Fix
  • 📝 Documentation
  • 🧹 Refactor / Chore

Bug Fix

What is the bug?

In SQL mode, each table entry appears twice (or more) in the autocomplete suggestions. registerSQL() in sqlProvider.ts calls monaco.languages.registerCompletionItemProvider() and registerDocumentFormattingEditProvider() every time the SQL editor mounts, but never disposes of the previous registrations. Since Monaco stacks providers rather than replacing them, each editor remount (e.g. switching between Builder and SQL mode, or navigating between panels) adds another provider returning the same suggestions, causing duplicate table entries that multiply with each remount.

How to reproduce

  1. Open a ClickHouse datasource query editor and switch to SQL mode
  2. Start typing a FROM clause to trigger table autocomplete — observe suggestions
  3. Switch to Builder mode, then back to SQL mode
  4. Trigger table autocomplete again — each table now appears twice
  5. Repeat switching — duplicates multiply with each remount

Related Issues

Closes HDX-3957


Please check that:

  • Tests for this change have been added/updated.
  • Documentation has been added/updated (where applicable).

Special notes for your reviewer

This is a minimal, targeted fix. The root cause is that Monaco's registerCompletionItemProvider and registerDocumentFormattingEditProvider return IDisposable objects that must be disposed to remove the provider. Without disposal, providers accumulate and each one independently returns the full set of suggestions, leading to duplicates.

registerSQL() now returns an SQLRegistration object that captures both disposables and exposes a dispose() method. SqlEditor stores this in a ref and calls dispose() in onEditorWillUnmount.

All 64 existing test suites (592 tests) continue to pass.

Dispose Monaco completion and formatting providers on editor unmount.
Previously, registerSQL() called monaco.languages.registerCompletionItemProvider
and registerDocumentFormattingEditProvider without tracking the returned disposables.
Since Monaco stacks providers rather than replacing them, each editor remount added
another provider returning the same suggestions, causing duplicate table entries.

Now registerSQL() returns an SQLRegistration object with a dispose() method, and
SqlEditor calls dispose() in onEditorWillUnmount to clean up stale providers.

Co-authored-by: Alex Fedotyev <alex-fedotyev@users.noreply.github.com>
@cla-assistant
Copy link
Copy Markdown

cla-assistant bot commented Apr 11, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@cla-assistant
Copy link
Copy Markdown

cla-assistant bot commented Apr 11, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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

Labels

None yet

Projects

Status: Incoming

Development

Successfully merging this pull request may close these issues.

2 participants