Skip to content

Step 7.2: Pre-Shell Critical Items (F11, F12, F14)#560

Merged
tnaum-ms merged 15 commits intofeature/shell-integrationfrom
dev/tnaum/pre-shell-wrap-up
Apr 8, 2026
Merged

Step 7.2: Pre-Shell Critical Items (F11, F12, F14)#560
tnaum-ms merged 15 commits intofeature/shell-integrationfrom
dev/tnaum/pre-shell-wrap-up

Conversation

@tnaum-ms
Copy link
Copy Markdown
Collaborator

@tnaum-ms tnaum-ms commented Apr 8, 2026

Step 7.2: Pre-Shell Critical Items

Completes pre-shell cleanup items deferred from Steps 6–7. These harden the playground foundation before the interactive shell (Step 9).

Changes

7.2.1: @microsoft/documentdb-vscode-shell-runtime Package Extraction (P0)

Extracts the @mongosh wrapper into a standalone workspace package with a clean DocumentDBShellRuntime API. Both the query playground and the future interactive shell consume this.

  • DocumentDBShellRuntime — public API: evaluate(code, dbName) → ShellEvaluationResult
  • DocumentDBServiceProvider — extends NodeDriverServiceProvider with DocumentDB metadata
  • CommandInterceptor — pre-eval routing for help/help()
  • ResultTransformer — normalizes @MongoSH ShellResult (cursor unwrap, array subclass normalization)
  • HelpProvider — DocumentDB-specific help text (verified commands only)
  • Integrated into PlaygroundEvaluator.ts and playgroundWorker.ts (replaced ~130 lines of inline code)
  • 32 unit tests

7.2.2: @mongosh Main Bundle Extraction — F14 (P1)

Removes all @mongosh modules from the main extension bundle by routing help commands through the worker.

  • main.js: 12.76 MB → 6.79 MB (−47%)
  • @mongosh is now only in the worker bundle (playgroundWorker.js)
  • Zero @mongosh imports in the main bundle

7.2.3: Wire displayBatchSize from Settings — F11 (P1)

Wires the documentDB.shell.batchSize setting end-to-end so users can control how many documents are returned per cursor iteration.

  • Setting renamed: documentDB.mongoShell.batchSizedocumentDB.shell.batchSize (type: integer)
  • Read per-eval (not at init time) so changes take effect on next run
  • Moved displayBatchSize from init to eval message in worker protocol
  • Uses instanceState.displayBatchSizeFromDBQuery directly (not config.set() which silently fails without an evaluation listener)
  • Result truncation hint uses cursorHasMore from @MongoSH (with displayBatchSize length heuristic as fallback)
  • PlaygroundDiagnostics provider: warns when .limit(N) exceeds batch size, with comment/string-aware detection and "Open Settings" quick-fix

7.2.4: Help Text Accuracy — F12 (P2)

Audits help text to only list verified-working DocumentDB commands.

  • Removed db.adminCommand({...}) (most admin commands unsupported)
  • Marked db.runCommand({...}) as "limited support"
  • 2 new tests for the above

7.2.5: Structure-Aware Block Detection — F13 (P2, Skipped)

Evaluated 4 options (blank-line, bracket-aware, semicolon-terminated, hybrid). Decided to keep the current blank-line splitting — simple, predictable, and the interactive shell will use a different input model.

Additional Fixes

Hover provider: Fixed console.log showing $log operator docs — when the character before the hovered word is . (property access), the $-prefix operator lookup is now suppressed.

cursorHasMore threading: Added cursorHasMore?: boolean to all result types, extracted in ResultTransformer before normalizing cursor results, threaded through worker IPC. Formatter shows truncation hint only when the cursor actually has more documents. Worker has a fallback check on raw printable for robustness.

Test Results

  • Shell-runtime package: 41 tests passing
  • Playground completions: 84 tests passing (17 hover/edge-case TDD tests)
  • All existing tests unaffected

tnaum-ms added 6 commits April 7, 2026 21:46
Extract the @MongoSH evaluation pipeline from PlaygroundEvaluator and
playgroundWorker into a standalone workspace package that both the
scratchpad and future interactive shell (Step 9) will consume.

Package components:
- DocumentDBShellRuntime: public API — evaluate(code, dbName) → ShellEvaluationResult
- DocumentDBServiceProvider: extends NodeDriverServiceProvider with DocumentDB metadata
- CommandInterceptor: pre-eval routing for help/help()
- HelpProvider: DocumentDB-specific help text (verified commands only)
- ResultTransformer: normalizes @MongoSH ShellResult (cursor unwrap, array subclass)

Integration:
- PlaygroundEvaluator: uses CommandInterceptor for help interception on main thread
- playgroundWorker: replaces ~130 lines of inline @MongoSH setup with runtime.evaluate()
- Worker owns MongoClient lifecycle; runtime only uses it

Tests: 32 unit tests covering CommandInterceptor, HelpProvider, ResultTransformer
Remove CommandInterceptor usage from PlaygroundEvaluator so the main
bundle has zero @MongoSH imports. Help commands now go through the
worker like all other code — simpler, one code path.

The shell-runtime package is only imported by playgroundWorker.ts
(separate webpack entry point), keeping @MongoSH isolated to the
worker bundle.

Bundle impact: main.js 12.76 MB → 6.79 MB (-5.97 MB, -47%)
Expand help command matching to cover tagged template literal syntax
(e.g. help``) in addition to bare `help` and `help()`. This ensures
the DocumentDB-specific help text is always shown regardless of how
the user invokes the help command.
- Rename setting: documentDB.mongoShell.batchSize → documentDB.shell.batchSize
- Read batch size per-eval via getBatchSizeSetting() (not at init time)
- Move displayBatchSize from init to eval message in worker protocol
- Add ShellEvalOptions type to shell-runtime for per-eval overrides
- Set instanceState.displayBatchSizeFromDBQuery directly (config.set()
  silently fails without evaluationListener.setConfig)
- Show batch size hint in result formatter when output may be truncated
- Add PlaygroundDiagnostics: warns when .limit(N) exceeds batch size
- Update l10n strings
- Remove em dash from .limit() diagnostic message, reference setting key
- Quick-fix label now shows 'currently N' instead of bare number
- Update l10n strings
- Remove db.adminCommand (most admin commands unsupported on DocumentDB)
- Mark db.runCommand as 'limited support'
- Fix column alignment in help text
- Add 2 tests: adminCommand absent, runCommand with limited-support qualifier
@tnaum-ms tnaum-ms requested a review from a team as a code owner April 8, 2026 09:16
@tnaum-ms tnaum-ms mentioned this pull request Apr 7, 2026
17 tasks
@tnaum-ms tnaum-ms requested a review from Copilot April 8, 2026 09:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the Query Playground execution pipeline ahead of the interactive shell work by extracting the @mongosh wrapper into a reusable workspace package, removing @mongosh from the main extension bundle, and wiring the per-eval display batch size setting end-to-end (plus related UX).

Changes:

  • Extracts @microsoft/documentdb-vscode-shell-runtime to encapsulate @mongosh evaluation, help interception, and result normalization.
  • Routes Query Playground evaluation (and help) through the worker + new runtime, enabling removal of @mongosh from the main bundle.
  • Renames and wires documentDB.shell.batchSize, adds cursor batch-size hinting, and introduces diagnostics/quick-fixes around .limit(N) vs batch size.

Reviewed changes

Copilot reviewed 23 out of 26 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tsconfig.json Adds TS project reference for the new documentdb-shell-runtime workspace package.
src/extensionVariables.ts Renames the batch size setting key constant to documentDB.shell.batchSize.
src/extension.ts Registers PlaygroundDiagnostics on activation.
src/documentdb/playground/workerTypes.ts Moves displayBatchSize from init to per-eval worker messages.
src/documentdb/playground/resultFormatter.ts Adds optional displayBatchSize to render a cursor batch-size hint.
src/documentdb/playground/playgroundWorker.ts Replaces inline @mongosh setup with DocumentDBShellRuntime and forwards displayBatchSize per eval.
src/documentdb/playground/PlaygroundEvaluator.ts Removes main-thread help interception; passes per-eval batch size to worker via getBatchSizeSetting().
src/documentdb/playground/PlaygroundDiagnostics.ts New diagnostics + quick-fix provider warning when .limit(N) exceeds display batch size.
src/commands/playground/executePlaygroundCode.ts Passes batch size into result formatting for cursor hinting.
packages/documentdb-shell-runtime/tsconfig.json New TS config for the extracted runtime package (composite build output to dist/).
packages/documentdb-shell-runtime/src/types.ts Defines public runtime result/callback/options types.
packages/documentdb-shell-runtime/src/ResultTransformer.ts Normalizes @mongosh ShellResult printable values (cursor unwrap, array normalization) and extracts source namespace.
packages/documentdb-shell-runtime/src/ResultTransformer.test.ts Unit tests for result normalization and source extraction.
packages/documentdb-shell-runtime/src/index.ts Public entrypoint exports runtime components and types.
packages/documentdb-shell-runtime/src/HelpProvider.ts Centralizes DocumentDB-verified help text and Help evaluation result.
packages/documentdb-shell-runtime/src/HelpProvider.test.ts Unit tests for help content and unsupported command exclusions.
packages/documentdb-shell-runtime/src/DocumentDBShellRuntime.ts Implements the runtime: command interception, per-eval instance setup, batch size wiring, console output routing.
packages/documentdb-shell-runtime/src/DocumentDBServiceProvider.ts Wraps NodeDriverServiceProvider with DocumentDB product metadata creation helper.
packages/documentdb-shell-runtime/src/CommandInterceptor.ts Intercepts help / help() (including tagged template form) before @mongosh evaluation.
packages/documentdb-shell-runtime/src/CommandInterceptor.test.ts Unit tests for help interception patterns and non-matches.
packages/documentdb-shell-runtime/package.json Declares the new workspace package, scripts, and @mongosh dependencies.
packages/documentdb-shell-runtime/jest.config.js Adds a dedicated Jest config for the new package tests.
package.json Adds dependency on @microsoft/documentdb-vscode-shell-runtime and renames/settings schema for documentDB.shell.batchSize.
package-lock.json Locks the new workspace dependency link.
l10n/bundle.l10n.json Adds localized strings for diagnostics and batch-size hinting.
jest.config.js Includes the new package in the monorepo Jest projects list.

tnaum-ms added 7 commits April 8, 2026 11:26
- Skip .limit(N) matches inside comments and string literals
- Skip if the same line already contains .toArray()
- Remove the .toArray() quick-fix (inserted at wrong position in chains)
- Keep only the 'Open Settings' quick-fix action
- Add cursorHasMore to ShellEvaluationResult, SerializableExecutionResult,
  and ExecutionResult types
- Extract cursorHasMore in ResultTransformer before discarding the
  { cursorHasMore, documents } wrapper
- Thread cursorHasMore through worker IPC and PlaygroundEvaluator
- Replace length-equality heuristic in resultFormatter with cursorHasMore
- Remove unused displayBatchSize parameter from formatResult()
- Add 4 tests for cursorHasMore extraction
Prevents fractional values like 12.5 from being accepted.
- Worker now proactively checks result.printable for cursorHasMore
  before EJSON serialization strips it
- ResultTransformer extraction is primary, worker check is fallback
- Formatter uses cursorHasMore when available, falls back to
  displayBatchSize length heuristic if undefined
- Restores displayBatchSize parameter in formatResult as fallback
Hovering on 'log' in 'console.log' no longer shows $log operator docs.
When the character before the word is '.', skip the $-prefix candidate
in getPlaygroundHoverContent().
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 25 out of 28 changed files in this pull request and generated 3 comments.

tnaum-ms added 2 commits April 8, 2026 13:32
- Drop displayBatchSize fallback heuristic in formatter; only show
  truncation hint when cursorHasMore === true
- Use typeof === 'boolean' check instead of Boolean() coercion for
  cursorHasMore fallback extraction in worker
- Import shared PLAYGROUND_LANGUAGE_ID constant in PlaygroundDiagnostics
  instead of hardcoding the string
@tnaum-ms tnaum-ms merged commit 26a2c02 into feature/shell-integration Apr 8, 2026
5 checks passed
@tnaum-ms tnaum-ms deleted the dev/tnaum/pre-shell-wrap-up branch April 8, 2026 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants