Skip to content

feat(editor): language-aware query authoring for MongoDB and PostgreSQL - #2102

Merged
datlechin merged 3 commits into
mainfrom
feat/2095-query-authoring
Aug 13, 2026
Merged

feat(editor): language-aware query authoring for MongoDB and PostgreSQL#2102
datlechin merged 3 commits into
mainfrom
feat/2095-query-authoring

Conversation

@datlechin

@datlechin datlechin commented Aug 13, 2026

Copy link
Copy Markdown
Member

Closes #2095 (all but the two items under "Not in this PR").

Query authoring was SQL-only. SQLCompletionAdapter hardcoded the SQL engine and never read PluginManager.editorLanguage(for:), so MongoDB went through the SQL pipeline. The issue says the MQL dot path returns an empty list. It is worse than that: SQLContextAnalyzer never matches a SQL clause on JavaScript text, so everything fell through to .unknown and the popup offered SELECT, INSERT and collection names inside db.users.find({...}).

The fix is a language seam rather than a special case, because no SQL clause vocabulary can describe db.orders.aggregate([{$match: ...}]).

Wrong results, fixed

db.orders.aggregate([...]).limit(10) silently dropped the .limit(10). The chained-options parser was gated on case .find, so every non-find operation discarded its chain with no error. The driver's only backstop is PluginRowLimits.emergencyMax, so that query could return up to 5,000,000 documents instead of 10.

Chained cursor methods now translate into pipeline stages ($sort, $skip, $limit, in cursor order), which needs no change to MongoOperation.aggregate and so no ABI break. Unknown chained methods and chaining onto a call that returns no cursor now throw instead of being dropped.

Language routing

QueryCompletionService is resolved from EditorLanguage, which was already plumbed and already drives six other behaviour branches. .sql routes to the existing engine unchanged, so the 30 SQL-family plugins are untouched. .javascript routes to the new MQL service.

The adapter is now QueryCompletionAdapter and owns only debounce, session, insertion and the delegate conformance. SQL-specific empty-prefix suppression moved into SQLCompletionService where it belongs, and window extraction moved into the services, which collapses three overlapping windowing layers (adapter, CompletionEngine, SQLContextAnalyzer) into one.

MongoDB completion

MongoContextAnalyzer is a structural bracket-frame scanner over NSString, not a regex. It classifies eleven positions and tracks string literals, escapes and both comment forms, so a brace inside a string does not open a document.

The operator sets are deliberately separate. Offering $match inside a filter, or $gte where a stage belongs, is worse than offering nothing, and $set/$unset mean different things as update operators and as pipeline stages.

Position Offered
db. collections, then database methods
db.users. collection methods
filter document field names, then query operators
projection document field names, then projection operators
update document update operators
array-form update the six stages an update pipeline allows
pipeline stage stage operators
inside a stage expression operators, accumulators, $$ variables, $field paths

Field names come from the sampled document schema the sidebar already builds. Nothing in the buffer is evaluated to produce a list, which is deliberate: MONGOSH-2635 is a mongosh bug where Tab-completion ran a property getter and deleted a collection.

PostgreSQL

SQLDialectDescriptor gains operators: [SQLOperatorDescriptor] with per-operator summary, category and applicable types. PostgreSQL declares 60, correctly scoped so the jsonb-only operators (@>, ?, ?|, ?&, @?, @@) are not offered as if json accepted them.

Keywords go from 84 to about 500 including 130 multi-word constructs, functions from 43 to about 400, data types from 28 to about 90. SQLContextAnalyzer learns ::, which becomes a new .castTarget clause offering type names in the spelling people write. pgAdmin is the only client that completes casts and it leaks catalog spellings such as int4 and bpchar.

Corrections the research turned up and the data reflects: random_normal and erf are PG16, not 17. uuidv4/uuidv7 are PG18, not 17, while uuid_extract_timestamp is 17. regexp_count and friends are PG15. @@@ is not a PG17 operator.

ABI

Additive, no currentPluginKitVersion bump. The existing 14-parameter init keeps its exact signature and gains only @_disfavoredOverload, which is compile-time and does not change the mangled symbol; a new 15-parameter init is favored. withCaseSensitivityStyle forwards operators explicitly, which it would otherwise have silently dropped.

scripts/check-pluginkit-abi.sh main reports a diff. Normalizing the attribute away, the one removed line is re-added byte-identical and the other 91 lines are new declarations, so no symbol disappeared. This PR needs the abi-additive label.

Testing

46 new tests: 24 for MongoContextAnalyzer, 13 for chained cursor methods and write options, 9 for nested field paths. swiftlint lint --strict is clean on the app scope (1333 files) and on the plugin and test files that SwiftLint's included: TablePro scope skips by default. Suites run green: MongoShellParser, MongoShellParserChainedMethod, MongoContextAnalyzer, BsonFieldPath, BsonDocumentFlattener, SQLContextAnalyzer, SQLDialectDescriptor, SQLFormatterService, CompletionEngine, SQLSchemaProvider, QueryCompletionAdapterLifecycle.

The AllPlugins target builds, which matters here: MongoDB is registry-only, so PR CI does not compile it and a break in MongoDBPluginDriver would otherwise pass every check.

No UI automation. The completion popup is a nonactivatingPanel driven by a 50 ms debounce, which is not deterministic under XCUITest; the position logic it depends on is covered by the analyzer unit tests instead.

Also in this PR

Nested MongoDB field paths. unionColumns stays flat because the grid renders a nested object as one JSON column, so a separate fieldPaths walker reports dotted paths: address, address.city, address.zip, and paths inside objects an array holds. It rides a new sampleFieldPaths driver requirement with a default of [], which is correct for every SQL driver and additive for ABI. Cached per collection with in-flight coalescing, cleared on database switch and refresh. No client checked ships this.

Write options. db.users.updateOne({...}, {...}, {upsert: true}) used to drop the third argument silently, so an upsert quietly did nothing. upsert, arrayFilters and hint now reach the server, and the result reports upsertedCount alongside modifiedCount. The parser only emits the new .write case when an options argument is present, so an older MongoDB plugin binary keeps working on the two-argument forms it already understood.

Language-routed formatting. QueryFormatterFactory keyed on the same EditorLanguage. MongoShellFormatter lays documents out by nesting depth, keeping short ones inline, and never reformats inside a string literal. Cmd+Shift+F used to run the SQL tokenizer over MQL.

Not in this PR

Named so they are not mistaken for done:

  • Inline diagnostics. The editor is not an NSTextView: CodeEditTextView.TextView is an NSView with a hand-rolled NSTextInputClient and its own layout manager, so setTemporaryAttributes and addRenderingAttribute are both unreachable. EmphasisManager.underline(color:) is the seam and needs no vendored change, but a gutter marker does, since GutterView has no per-line marker primitive. Worth knowing: TextKit 2 rendering attributes silently ignore underlineStyle, verified by pixel-diff and documented nowhere.
  • Enum values from pg_enum in a comparison. Unclaimed by every client checked, and cheap.

Related

TextViewController+Lifecycle.swift:327 triggers completion with no hasMarkedText() guard, and the vendored CodeSuggestion module has no marked-text awareness at all, while the apply path is guarded. That is a CJK composition bug independent of this issue. QueryCompletionAdapter now guards both its trigger and apply paths; the vendored gap remains.

@mintlify

mintlify Bot commented Aug 13, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
TablePro 🟢 Ready View Preview Aug 13, 2026, 10:42 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@datlechin datlechin added the abi-additive PluginKit ABI diff reviewed as additive; no version bump needed label Aug 13, 2026
@datlechin
datlechin merged commit 5329e3f into main Aug 13, 2026
4 checks passed
@datlechin
datlechin deleted the feat/2095-query-authoring branch August 13, 2026 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

abi-additive PluginKit ABI diff reviewed as additive; no version bump needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query authoring for MongoDB and PostgreSQL needs real autocomplete, dialect data, and diagnostics

1 participant