feat: documentdb-query language — CompletionItemProvider, HoverProvider, acorn validation#518
Merged
tnaum-ms merged 11 commits intofeature/shell-integrationfrom Mar 16, 2026
Conversation
Implements the architecture POC from docs/plan/03.5-finalize-architecture.md:
- Register 'documentdb-query' custom language ID with Monaco
- Import JS Monarch tokenizer from basic-languages/javascript for syntax
highlighting (relaxed quoting, BSON constructors, regex literals)
- Custom CompletionItemProvider using documentdb-constants package
(query operators, BSON constructors — no JS globals noise)
- URI-based routing for editor context (filter/project/sort/aggregation)
- Wire QueryEditor filter, project, sort editors to use new language
- Remove old JSON schema pipeline (setJsonSchema, basicFindQuerySchema,
2-second delay hack) — replaced by static documentdb-constants completions
- 41 Jest tests covering languageConfig and completion provider logic
Does NOT include:
- Dynamic field completions (Step 4)
- acorn validation/squiggles (Step 4)
- Aggregation pipeline support (Step 8)
POC Pass Criteria (requires manual verification):
1. Highlights { unquoted: 1, 'single': 2, "double": 3 } without squiggles
2. Highlights ObjectId("...") as function call
3. Ctrl+Space shows only DocumentDB operators (no JS globals)
4. Webpack bundle builds successfully (verified: no ts.worker.js loaded)
- Implemented dynamic field completions using a completion store. - Added mapping function for field completion items to improve sorting and display. - Introduced hover provider for inline documentation on operators and BSON constructors. - Developed a comprehensive validator for documentdb-query expressions, including syntax error detection and typo suggestions for BSON constructors. - Created unit tests for completion store, hover provider, and query validator to ensure functionality and reliability. - Updated existing completion provider to integrate new features and improve overall performance.
Contributor
There was a problem hiding this comment.
Pull request overview
Introduces a custom documentdb-query Monaco language for the Collection View query editors, shifting autocompletion/hover/validation away from JSON-schema-based Monaco JSON features and enabling relaxed “DocumentDB API expression” syntax (unquoted keys, BSON constructors, etc.) across filter/projection/sort parsing.
Changes:
- Add a
documentdb-queryMonaco language with JS Monarch tokenization, custom completions, and hover help (backed by@vscode-documentdb/documentdb-constants). - Add a pure validator using
acorn/acorn-walkand wire it into the QueryEditor with debounced Monaco markers. - Replace JSON-schema autocompletion (schema generation + JSON worker) with field-completion data fetched via tRPC and stored in a completion context.
Reviewed changes
Copilot reviewed 24 out of 25 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/webviews/documentdbQuery/registerLanguage.ts | Registers custom Monaco language, tokenizer, completion + hover providers. |
| src/webviews/documentdbQuery/languageConfig.ts | Defines language ID + URI scheme and helpers for editor context routing. |
| src/webviews/documentdbQuery/languageConfig.test.ts | Unit tests for URI build/parse utilities and constants. |
| src/webviews/documentdbQuery/index.ts | Barrel exports for language registration, validator, and completion store. |
| src/webviews/documentdbQuery/documentdbQueryValidator.ts | Adds acorn-based syntax + near-miss BSON constructor diagnostics. |
| src/webviews/documentdbQuery/documentdbQueryValidator.test.ts | Unit tests for validator behavior and distance helper. |
| src/webviews/documentdbQuery/documentdbQueryHoverProvider.ts | Hover content for operators/BSON constructors via constants registry. |
| src/webviews/documentdbQuery/documentdbQueryHoverProvider.test.ts | Unit tests for hover matching behavior. |
| src/webviews/documentdbQuery/documentdbQueryCompletionProvider.ts | Maps constants + field data into Monaco completion items. |
| src/webviews/documentdbQuery/documentdbQueryCompletionProvider.test.ts | Unit tests for completion mapping and store integration. |
| src/webviews/documentdbQuery/completionStore.ts | In-webview session completion context store for dynamic fields. |
| src/webviews/documentdbQuery/completionStore.test.ts | Unit tests for completion context store operations. |
| src/webviews/documentdb/collectionView/components/queryEditor/QueryEditor.tsx | Switches editors to documentdb-query, adds debounced validation + model URIs, and cleanup. |
| src/webviews/documentdb/collectionView/collectionViewRouter.ts | Replaces schema-returning endpoint with field-completion-data endpoint. |
| src/webviews/documentdb/collectionView/collectionViewContext.ts | Removes setJsonSchema API from context. |
| src/webviews/documentdb/collectionView/CollectionView.tsx | Fetches field completion data and stores it for completions (instead of pushing JSON schema). |
| src/utils/json/data-api/autocomplete/generateMongoFindJsonSchema.ts | Removes JSON schema generator previously used for Monaco JSON autocompletion. |
| src/utils/json/data-api/autocomplete/basicMongoFindFilterSchema.json | Removes fallback JSON schema used when no field data was available. |
| src/documentdb/utils/toFilterQuery.ts | Uses @mongodb-js/shell-bson-parser (Loose) for filter parsing and updates error messaging. |
| src/documentdb/utils/toFilterQuery.test.ts | Updates tests for shell-bson-parser behavior and broader BSON constructor support. |
| src/documentdb/ClusterSession.ts | Parses projection/sort with shell-bson-parser (Loose) to match updated filter parsing. |
| src/documentdb/ClustersClient.ts | Parses projection/sort with shell-bson-parser (Loose) and updates user-facing error strings. |
| package.json | Adds shell-bson-parser + acorn/acorn-walk dependencies. |
| package-lock.json | Locks new dependencies and updates related transitive versions. |
| l10n/bundle.l10n.json | Updates localized strings to reflect relaxed syntax and removes unused message. |
Use a shared registrationPromise to prevent duplicate provider registrations when multiple editors call registerDocumentDBQueryLanguage() before the first async import resolves.
Report fieldCompletionDataFetchFailed event when getFieldCompletionData fails, so silent field-completion degradation is visible in telemetry.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements Step 4 — Filter CompletionItemProvider of the shell integration feature (#508). Registers a custom
documentdb-queryMonaco language with intelligent autocomplete, hover docs, and real-time validation for the Collection View query editors (filter, project, sort).Plan:
docs/plan/04-filter-completion-provider.mdWhat's included
Custom Language Registration
documentdb-querylanguage ID — registered once (idempotent), reused across all query editorsdocumentdb://{filter|project|sort}/{sessionId}for per-editor context routingCompletionItemProvider
documentdb-constants— query operators, BSON constructors, system variables, filtered by editor type via meta tag presets (FILTER_COMPLETION_META,PROJECTION_COMPLETION_META)SchemaAnalyzer— field names with display type, sparse indicator, and pre-escapedinsertTextfor dotted/special-character field names$prefix range fix — extends the word range backward when the cursor follows$, preventing double-dollar insertion (e.g.,$$gt)0_), universal second (1_), non-matching last (2_) — all operators remain visible for discoverabilityHoverProvider
$-prefixed operator or BSON constructorValidation (acorn)
acorn.parseExpressionAt()detects malformed expressions in real time (300ms debounce)acorn-walktraverses the AST; unknown function calls and member-expression objects within Levenshtein distance ≤ 2 of a BSON constructor or known global produce "Did you mean 'X'?" warningsObjctId("abc")) and member calls (Daate.now(),Maht.min())Query Parser Replacement
toFilterQuery.ts(hand-rolled regex parser supporting only 4 BSON constructors) with@mongodb-js/shell-bson-parser— a battle-tested parser that handles relaxed JavaScript syntax including all BSON constructors,Date.now(),Math.*, regex literals, and nested expressionstoFilterQuery.tsas a thin wrapper for backward compatibility — delegates toshell-bson-parserinternallyLegacy Pipeline Removal
generateMongoFindJsonSchema()andbasicMongoFindFilterSchema.json— the old 10-operator JSON Schema approach, replaced by 308 operators fromdocumentdb-constantsgetAutocompletionSchematRPC endpoint — replaced bygetFieldCompletionDatawhich pushesFieldCompletionData[]to the webviewWiring
session.getKnownFields()→toFieldCompletionItems()→completionStoreclearCompletionContext(sessionId)prevents stale dataArchitecture
Key decisions
documentdb-query(Option E)acorn+acorn-walk@mongodb-js/shell-bson-parserDaate.now()andObjctId()patterns0_/1_/2_) not exclusionTests
documentdbQueryCompletionProvider.test.ts(48 tests),documentdbQueryValidator.test.ts(32 tests)Deferred to Step 4.5
docs/plan/04.5-context-sensitive-completions.md.