-
Type:
Bug
-
Resolution: Fix Not Needed
-
Priority:
Minor - P4
-
Affects Version/s: None
-
Component/s: None
-
Environment:OS:
node.js / npm versions:
Additional info:
Follow-up from VSCODE-805.
Problem
updateCodeLensesForPlayground gates edit code lenses with resultsAreCollectionDocuments(playgroundResult.constructionOptions), which returns true when the construction options are absent. Two unrelated situations produce an absent value, and they are indistinguishable at that call site:
- @mongosh/shell-api omits construction options for a find or aggregate that runs inside a session (findOptions.session ? undefined : ... in collection.js). These rows are stored documents and should keep their lenses.
- src/language/worker.ts calls stripConstructionOptions whenever isSafeQueryResult is false - a .map()}}ed cursor, or an {{$out/$merge pipeline. These rows are not stored documents and should not be editable.
So {{db.events.aggregate([{ $group:
{ _id: '$status' }}]).map(d => d)}} bypasses the aggregation gate added in VSCODE-805 and still renders an Edit Document lens.
Residual risk
Low. Operator-carrying ids are still rejected per row by isValidDocumentId, so no wildcard filter can be built. What remains is a synthesised plain-value _id: a $group on _id: '$status' yields _id: "active", and editing that row fetches and overwrites a real document whose _id is literally "active". Requires .map() on top of a synthesising pipeline.
Suggested fix
Make the worker record why it stripped, rather than deleting silently, so the two cases can be told apart:
// worker.ts - stripConstructionOptions delete clone.data.result.constructionOptions; clone.data.result.isUncharacterised = true;
Then gate on that flag in editDocumentCodeLensProvider. Session-based queries keep their lenses; stripped results lose them. Needs a field on PlaygroundRunResult and touches the worker RPC payload, which is why it was kept out of VSCODE-805.
Notes
src/test/suite/editors/editDocumentCodeLensProvider.test.ts has a test named "keeps code lenses for a cursor with no construction options" that pins the current deliberate behaviour. It should be inverted as part of this fix.