Step 7 WI-1: Scratchpad IntelliSense — Shell API type definitions + TS Server Plugin#543
Open
tnaum-ms wants to merge 9 commits intofeature/shell-integrationfrom
Open
Step 7 WI-1: Scratchpad IntelliSense — Shell API type definitions + TS Server Plugin#543tnaum-ms wants to merge 9 commits intofeature/shell-integrationfrom
tnaum-ms wants to merge 9 commits intofeature/shell-integrationfrom
Conversation
…ions Create the DocumentDB-scoped .d.ts file that declares the shell API surface available in scratchpad (.documentdb) files. This provides: - BSON type classes (ObjectId, UUID, Int32, Long, Decimal128, etc.) - BSON constructor functions (ObjectId(), ISODate(), NumberInt(), etc.) - Shell globals (db, use, help, print, sleep, version, EJSON) - Database interface with 14 methods (getCollection, runCommand, etc.) - Collection interface with 25 methods (find, insertOne, aggregate, etc.) - FindCursor interface with 18 chainable methods (limit, sort, etc.) - AggregationCursor interface with 8 methods (toArray, explain, etc.) - Result types (InsertOneResult, UpdateResult, DeleteResult, etc.) All JSDoc content is original writing — not copied from MongoDB docs. Only DocumentDB-supported methods are included.
Add a TypeScript server plugin that injects the DocumentDB shell API type definitions into the TypeScript project context for scratchpad files (language ID: documentdb-scratchpad). The plugin uses the getExternalFiles() API to tell the TS server to include our .d.ts file, enabling: - db. method chain completions - Cursor method completions (.limit(), .sort(), etc.) - BSON constructor completions (ObjectId(), ISODate(), etc.) - JSDoc-powered hover documentation - Signature help for method parameters Implementation: - src/documentdb/scratchpad/tsPlugin/index.ts: Plugin module - webpack.config.ext.js: New entry point + CopyWebpackPlugin for .d.ts - package.json: typescriptServerPlugins contribution point
…activation - configurationDefaults for documentdb-scratchpad: enable string literal completions (editor.quickSuggestions.strings: true) without global changes - Use .documentdb.js as sole file extension (drop bare .documentdb — never shipped) - Force-activate VS Code TypeScript extension on scratchpad file open (our custom language ID isn't in TS auto-activation list)
14 tasks
Add a custom vscode.CompletionItemProvider for scratchpad files that provides DocumentDB-specific completions the TS service can't handle: - scratchpadContextDetector.ts: Two-stage cursor context detection Stage 1: JS-level (top-level, db., collection., cursor chain, method arg) Stage 2: Query-object (reuses cursorContext.ts from collection view) - completionRegistry.ts: Static catalog of shell globals (S1), database methods (S2), collection methods (S3), find cursor methods (S4), and aggregation cursor methods (S5) - ScratchpadCompletionItemProvider.ts: Main provider class - Top-level: globals + BSON constructors - db.*: database methods + dynamic collection names from SchemaStore - db.<collection>.*: collection methods with frequency-based sorting - Cursor chains: find cursor or aggregation cursor methods - Method arguments: query operators, field names, type-aware sorting - String literals: collection names inside getCollection()/use() Registered in ClustersExtension.ts alongside CodeLens and block highlighter.
Add 80 TDD behavior tests covering: - Context detection (18 tests): S1-S6 cursor positions + method arg detection - Completion registry (62 tests): S1-S5 required entries, exclusions, sort ordering, snippet quality, and description completeness Tests follow the same TDD contract pattern as the collection view's completionBehavior.test.ts — tests define the behavior specification and must not be auto-fixed on failure.
Fixes from L1/L2/N test results:
1. Fix L1.4/L1.5: .d.ts index signature changed from
'DocumentDBCollection | ((...args) => unknown)' to just
'DocumentDBCollection'. The union type caused TS to resolve
db.users.find() as Array.find instead of our collection method,
and hover showed 'any' instead of JSDoc.
2. Fix L2.2: Double-dollar ($$regex) when selecting $-prefixed operators.
Added replaceRange computation that extends back 1 character when
preceded by '$', matching the same fix from the collection view.
3. Fix L2.3: Unquoted dotted field names (e.g. 'address.city' inserted
without quotes, causing syntax errors). Fields containing dots,
spaces, or hyphens are now auto-quoted.
4. Fix L2.3: db.getCollection('restaurants').find({}) didn't provide
field completions. Added resolveCollectionName() that extracts the
collection name from the getCollection('name') string argument.
5. Fix L2.5: String literal completions inside getCollection('|') now
work. Added checkStringLiteralContext() that detects string position
BEFORE the method argument handler runs.
6. Fix lint: remove useless escape in regex character class.
The typescriptServerPlugins contribution point resolves the 'name' field
as an npm package name from <extensionPath>/node_modules/ (as documented
by VS Code). Previous attempts used relative file paths which don't work
because extensionPath varies between dev host (dist/) and VSIX (root/).
Fix: Create a package.json stub at dist/node_modules/documentdb-scratchpad-ts-plugin/
with 'main' pointing to ../../scratchpadTsPlugin.js. This allows the TS
server to resolve our plugin via standard npm package resolution:
require('documentdb-scratchpad-ts-plugin')
→ dist/node_modules/documentdb-scratchpad-ts-plugin/package.json
→ main: ../../scratchpadTsPlugin.js
→ dist/scratchpadTsPlugin.js
The stub is copied to dist/ by CopyWebpackPlugin during build.
Verified: included in VSIX, resolves correctly with TS's resolveJSModule().
Also: cleaned up debug logging from ClustersExtension and tsPlugin.
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.
Goal
Add IntelliSense (autocompletion, hover docs, signature help) to DocumentDB scratchpad (
.documentdb.js) files.This is Work Item 1 (Foundation) of Step 7: Scratchpad CompletionItemProvider.
What's included
.d.tstype definitions (854 lines, original JSDoc).d.tsinto scratchpad files.documentdb.jsas sole extension, TS activationWhat it enables
When a user opens a
.documentdb.jsscratchpad file, they get:db.method completions (getCollection, runCommand, aggregate, etc.)db.users.collection method completions (find, insertOne, updateOne, etc.).limit(),.sort(),.toArray(), etc.)ObjectId(),ISODate(),UUID(), etc.)