Skip to content

fix(editor): avoid duplicating schemas in table completions - #715

Open
mikevillari wants to merge 2 commits into
libredb:mainfrom
mikevillari:fix/schema-qualified-completions
Open

fix(editor): avoid duplicating schemas in table completions#715
mikevillari wants to merge 2 commits into
libredb:mainfrom
mikevillari:fix/schema-qualified-completions

Conversation

@mikevillari

@mikevillari mikevillari commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

WARNING CORE_CAPABILITIES

Description

Accepting a qualified table suggestion can produce sample.sample.demo, because Monaco replaces only the current word while the provider inserts the complete qualified name. Longer prefixes such as sample.dem also lose the suggestion because table filtering ignores the typed qualifier.

Filter table suggestions using the qualifier plus current word and replace that entire span. After a dot, offer matching schema tables when direct table/alias column lookup yields no columns.

Type of Change

  • Bug fix

Related Issue

Closes #705

Changes Made

  • Account for typed qualifiers in table filtering and replacement ranges.
  • Preserve direct table/alias column completion precedence.
  • Add eight cases covering empty/short/long prefixes, mixed case, multi-part qualifiers, unqualified insertion, and an alias sharing a schema name.

Testing

  • Four initial regressions fail before implementation: sample.d inserts sample.sample.demo; sample., sample.de, and sample.dem have no matching suggestion.
  • Focused completion tests: 55 passes, zero failures, including the eight new cases.
  • Full bun run test: 14,721 passes, zero failures, all 34 component groups.
  • Full bun run test:coverage and threshold check: 46,329/46,329 lines (100%).
  • Format, lint, typecheck, knip, chart/channel/README/security guards, build:lib, and diff checks pass.
  • Real Monaco browser fixture: all four qualified prefixes apply to SELECT * FROM sample.demo using the real editor model.
  • Registered the actual provider with the real Monaco suggestion widget; clicking sample.demo from the popup produces the correct query without duplication.
  • Both published files match tested local source exactly.

Test Environment

macOS arm64; Node 26.5.0; Bun 1.4.2; GNU Bash 5.2.37; Helm 4.1.3; 7-Zip 26.03.

Checklist

  • Focused provider and regression-test changes.
  • Existing completion behavior covered.
  • No dependencies added.

Additional Notes

AI-assisted implementation and validation. Browser verification used an isolated local fixture with the installed Monaco distribution and the actual bundled provider, not a full application deployment or a database query. The automation attempt to accept with Tab failed, so keyboard acceptance is not claimed; popup mouse acceptance and real-model edit application were verified.

Production bun run build remains for CI: the same base/dependency set hit a local Turbopack worker-port permission error in #706 even after a broader-permission retry. That environment-limited production build was not repeated here. Lint reports existing warnings without errors.

@cevheri cevheri added loop:needs-moderator-action Flagged by the maintainer loop: suspicious content or a decision only a human can make core-capabilities labels Sep 9, 2026
@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@cevheri

cevheri commented Sep 9, 2026

Copy link
Copy Markdown
Member

Thanks, the diagnosis is right and the tests assert the applied edit rather than the range, which is the correct shape for this bug. I reproduced both original failures on main before reading the fix.

One blocking finding. Table labels are not always schema qualified: postgres.ts:1478 emits bare names for the public schema, and mysql.ts:1040, oracle.ts:863, druid, sqlite, libsql and duckdb emit bare names for every table. Filtering on qualifier + prefix drops those. Measured on your branch: SELECT * FROM public.dem with label demo produced a suggestion on main and produces none here, same for mydb.dem. The reported case is fixed, but a case that worked has stopped working.

A four line fallback covers both, and your 33 tests still pass with it:

const typedQualifier = line.substring(0, word.startColumn - 1).match(/((?:[\w$]+\.)+)$/)?.[1] ?? "";
const qualifiedMatch = schemaCompletionCache.tableItems.some((table) =>
  table.labelLower.startsWith(typedQualifier.toLowerCase() + prefix),
);
const qualifier = typedQualifier && qualifiedMatch ? typedQualifier : "";

Keep the dot branch guard on the effective qualifier: switching it to typedQualifier makes unknown. offer every table and breaks the existing empty-suggestions test.

Please add a bare-label case to the new test block so this cannot regress again. No live engines needed: the provider only ever sees tableItems, so a parameterised label shape covers all seventeen.

@cevheri cevheri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

commented

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

Labels

core-capabilities loop:needs-moderator-action Flagged by the maintainer loop: suspicious content or a decision only a human can make

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] autocomplete for tables with schema behaves unexpectedly

2 participants