diff --git a/src/editors/codeActionProvider.ts b/src/editors/codeActionProvider.ts index 49ed43469..884fc202a 100644 --- a/src/editors/codeActionProvider.ts +++ b/src/editors/codeActionProvider.ts @@ -6,7 +6,7 @@ import { ExportToLanguageMode } from '../types/playgroundType'; export default class CodeActionProvider implements vscode.CodeActionProvider { _onDidChangeCodeCodeAction: vscode.EventEmitter = new vscode.EventEmitter(); selection?: vscode.Selection; - mode?: string; + mode?: ExportToLanguageMode; static readonly providedCodeActionKinds = [vscode.CodeActionKind.QuickFix]; @@ -19,7 +19,7 @@ export default class CodeActionProvider implements vscode.CodeActionProvider { readonly onDidChangeCodeLenses: vscode.Event = this ._onDidChangeCodeCodeAction.event; - refresh({ selection, mode }: { selection?: vscode.Selection, mode?: string }): void { + refresh({ selection, mode }: { selection?: vscode.Selection, mode?: ExportToLanguageMode }): void { this.selection = selection; this.mode = mode; this._onDidChangeCodeCodeAction.fire(); diff --git a/src/editors/playgroundController.ts b/src/editors/playgroundController.ts index ca3ee40d6..9318d7859 100644 --- a/src/editors/playgroundController.ts +++ b/src/editors/playgroundController.ts @@ -364,20 +364,6 @@ export default class PlaygroundController { } } - _getDocumentLanguage(playgroundResult: PlaygroundResult): string { - if (!playgroundResult) { - return 'plaintext'; - } - - const { type, content } = playgroundResult; - - if (type && type in ExportToLanguages) { - return type; - } - - return (typeof content === 'object' && content !== null) ? 'json' : 'plaintext'; - } - async _openPlaygroundResult(): Promise { this._playgroundResultViewProvider.setPlaygroundResult( this._playgroundResult @@ -392,7 +378,7 @@ export default class PlaygroundController { await this._showResultAsVirtualDocument(); if (this._playgroundResultTextDocument) { - const language = this._getDocumentLanguage(this._playgroundResult); + const language = this._playgroundResult?.language || 'plaintext'; await vscode.languages.setTextDocumentLanguage( this._playgroundResultTextDocument, @@ -599,7 +585,7 @@ export default class PlaygroundController { 'Please select one or more lines in the playground.' ); - return Promise.resolve(true); + return true; } try { @@ -645,8 +631,9 @@ export default class PlaygroundController { namespace: namespace.databaseName && namespace.collectionName ? `${namespace.databaseName}.${namespace.collectionName}` : null, - type: language, - content: imports ? `${imports}\n\n${transpiledExpression}` : transpiledExpression + type: null, + content: imports ? `${imports}\n\n${transpiledExpression}` : transpiledExpression, + language }; log.info(`Export to ${language} language result`, this._playgroundResult); diff --git a/src/editors/playgroundResultProvider.ts b/src/editors/playgroundResultProvider.ts index a7f3d3ae7..005482825 100644 --- a/src/editors/playgroundResultProvider.ts +++ b/src/editors/playgroundResultProvider.ts @@ -25,7 +25,8 @@ implements vscode.TextDocumentContentProvider { this._playgroundResult = { namespace: null, type: null, - content: undefined + content: undefined, + language: null }; } @@ -47,13 +48,13 @@ implements vscode.TextDocumentContentProvider { return 'undefined'; } - const { type, content } = this._playgroundResult; + const { type, content, language } = this._playgroundResult; if (type === 'undefined') { return 'undefined'; } - if (type && (type === 'string' || type in ExportToLanguages)) { + if (type === 'string' || (language && Object.values(ExportToLanguages).includes(language as ExportToLanguages))) { return this._playgroundResult.content; } diff --git a/src/language/worker.ts b/src/language/worker.ts index 627706113..aa2734615 100644 --- a/src/language/worker.ts +++ b/src/language/worker.ts @@ -42,7 +42,8 @@ const executeAll = async ( outputLines.push({ type, content: printable, - namespace: null + namespace: null, + language: null }); } } @@ -52,16 +53,21 @@ const executeAll = async ( source && source.namespace ? `${source.namespace.db}.${source.namespace.collection}` : null; - const content = - type === 'Cursor' || type === 'AggregationCursor' ? - JSON.parse(EJSON.stringify(printable.documents)) : - typeof printable === 'string' - ? printable - : JSON.parse(EJSON.stringify(printable)); + let content = ''; + + if (type === 'Cursor' || type === 'AggregationCursor') { + content = JSON.parse(EJSON.stringify(printable.documents)); + } else { + content = typeof printable === 'string' + ? printable + : JSON.parse(EJSON.stringify(printable)); + } + const result: PlaygroundResult = { namespace, type: type ? type : typeof printable, - content + content, + language: (typeof content === 'object' && content !== null) ? 'json' : 'plaintext' }; return [null, { outputLines, result }]; diff --git a/src/test/suite/editors/codeActionProvider.test.ts b/src/test/suite/editors/codeActionProvider.test.ts index cc264adfe..e8d4a6854 100644 --- a/src/test/suite/editors/codeActionProvider.test.ts +++ b/src/test/suite/editors/codeActionProvider.test.ts @@ -9,7 +9,7 @@ import CodeActionProvider from '../../../editors/codeActionProvider'; import { ExplorerController } from '../../../explorer'; import { LanguageServerController } from '../../../language'; import { PlaygroundController } from '../../../editors'; -import { PlaygroundResult } from '../../../types/playgroundType'; +import { PlaygroundResult, ExportToLanguageMode } from '../../../types/playgroundType'; import { mdbTestExtension } from '../stubbableMdbExtension'; import { TestExtensionContext } from '../stubs'; @@ -104,7 +104,7 @@ suite('Code Action Provider Test Suite', function () { } as vscode.Selection; const testCodeActionProvider = new CodeActionProvider(); - testCodeActionProvider.refresh({ selection, mode: 'OTHER' }); + testCodeActionProvider.refresh({ selection, mode: ExportToLanguageMode.OTHER }); const codeActions = testCodeActionProvider.provideCodeActions(); @@ -120,7 +120,7 @@ suite('Code Action Provider Test Suite', function () { await vscode.commands.executeCommand(actionCommand.command); - const expectedResult = { namespace: null, type: 'number', content: 123 }; + const expectedResult = { namespace: null, type: 'number', content: 123, language: 'plaintext' }; expect(mdbTestExtension.testExtensionController._playgroundController._playgroundResult).to.be.deep.equal(expectedResult); expect(mdbTestExtension.testExtensionController._playgroundController._isPartialRun).to.be.equal(true); } @@ -133,7 +133,7 @@ suite('Code Action Provider Test Suite', function () { start: { line: 0, character: 0 }, end: { line: 0, character: 14 } } as vscode.Selection; - const mode = 'QUERY'; + const mode = ExportToLanguageMode.QUERY; mdbTestExtension.testExtensionController._playgroundController._selectedText = textFromEditor; mdbTestExtension.testExtensionController._playgroundController._codeActionProvider.selection = selection; @@ -163,12 +163,12 @@ suite('Code Action Provider Test Suite', function () { await vscode.commands.executeCommand(actionCommand.command); - const expectedResult = { namespace: null, type: 'java', content: 'new Document("name", "22")' }; + const expectedResult = { namespace: null, type: null, content: 'new Document("name", "22")', language: 'java' }; const codeLenses = mdbTestExtension.testExtensionController._playgroundController._exportToLanguageCodeLensProvider.provideCodeLenses(); expect(codeLenses.length).to.be.equal(3); - // Only java supports builders. + // Only java queries supports builders. await vscode.commands.executeCommand('mdb.changeExportToLanguageAddons', { ...mdbTestExtension.testExtensionController._playgroundController._exportToLanguageCodeLensProvider._exportToLanguageAddons, builders: true @@ -186,7 +186,7 @@ suite('Code Action Provider Test Suite', function () { start: { line: 0, character: 0 }, end: { line: 0, character: 14 } } as vscode.Selection; - const mode = 'QUERY'; + const mode = ExportToLanguageMode.QUERY; mdbTestExtension.testExtensionController._playgroundController._selectedText = textFromEditor; mdbTestExtension.testExtensionController._playgroundController._codeActionProvider.selection = selection; @@ -218,8 +218,9 @@ suite('Code Action Provider Test Suite', function () { const expectedResult = { namespace: null, - type: 'csharp', - content: 'new BsonDocument(\"name\", \"22\")' + type: null, + content: 'new BsonDocument(\"name\", \"22\")', + language: 'csharp' }; expect(mdbTestExtension.testExtensionController._playgroundController._playgroundResult).to.be.deep.equal(expectedResult); @@ -244,7 +245,7 @@ suite('Code Action Provider Test Suite', function () { start: { line: 0, character: 24 }, end: { line: 0, character: 38 } } as vscode.Selection; - const mode = 'QUERY'; + const mode = ExportToLanguageMode.QUERY; mdbTestExtension.testExtensionController._playgroundController._selectedText = "{ name: '22' }"; mdbTestExtension.testExtensionController._playgroundController._codeActionProvider.selection = selection; @@ -276,8 +277,9 @@ suite('Code Action Provider Test Suite', function () { let expectedResult: PlaygroundResult = { namespace: null, - type: 'python', - content: "{\n 'name': '22'\n}" + type: null, + content: "{\n 'name': '22'\n}", + language: 'python' }; expect(mdbTestExtension.testExtensionController._playgroundController._playgroundResult).to.be.deep.equal(expectedResult); @@ -291,8 +293,9 @@ suite('Code Action Provider Test Suite', function () { expectedResult = { namespace: 'db.coll', - type: 'python', - content: "# Requires the PyMongo package.\n# https://api.mongodb.com/python/current\n\nclient = MongoClient('mongodb://localhost:27018/?readPreference=primary&appname=mongodb-vscode+0.0.0-dev.0&directConnection=true&ssl=false')\nresult = client['db']['coll'].aggregate({\n 'name': '22'\n})" + type: null, + content: "# Requires the PyMongo package.\n# https://api.mongodb.com/python/current\n\nclient = MongoClient('mongodb://localhost:27018/?readPreference=primary&appname=mongodb-vscode+0.0.0-dev.0&directConnection=true&ssl=false')\nresult = client['db']['coll'].aggregate({\n 'name': '22'\n})", + language: 'python' }; expect(mdbTestExtension.testExtensionController._playgroundController._playgroundResult).to.be.deep.equal(expectedResult); diff --git a/src/test/suite/editors/editDocumentCodeLensProvider.test.ts b/src/test/suite/editors/editDocumentCodeLensProvider.test.ts index 218ea1172..9d12b721a 100644 --- a/src/test/suite/editors/editDocumentCodeLensProvider.test.ts +++ b/src/test/suite/editors/editDocumentCodeLensProvider.test.ts @@ -123,7 +123,8 @@ suite('Edit Document Code Lens Provider Test Suite', () => { testCodeLensProvider.updateCodeLensesForPlayground({ namespace: 'db.coll', type: 'Document', - content: { _id: '93333a0d-83f6-4e6f-a575-af7ea6187a4a' } + content: { _id: '93333a0d-83f6-4e6f-a575-af7ea6187a4a' }, + language: 'json' }); const codeLens = testCodeLensProvider.provideCodeLenses(); @@ -164,7 +165,8 @@ suite('Edit Document Code Lens Provider Test Suite', () => { content: [ { _id: '93333a0d-83f6-4e6f-a575-af7ea6187a4a' }, { _id: '21333a0d-83f6-4e6f-a575-af7ea6187444' } - ] + ], + language: 'json' }); const codeLens = testCodeLensProvider.provideCodeLenses(); @@ -226,7 +228,8 @@ suite('Edit Document Code Lens Provider Test Suite', () => { $date: '2014-04-04T21:23:13.331Z' } } - ] + ], + language: 'json' }); const codeLens = testCodeLensProvider.provideCodeLenses(); diff --git a/src/test/suite/editors/exportToLanguageCodeLensProvider.test.ts b/src/test/suite/editors/exportToLanguageCodeLensProvider.test.ts index 011c3eb47..330a26285 100644 --- a/src/test/suite/editors/exportToLanguageCodeLensProvider.test.ts +++ b/src/test/suite/editors/exportToLanguageCodeLensProvider.test.ts @@ -2,6 +2,7 @@ import { beforeEach } from 'mocha'; import chai from 'chai'; import ExportToLanguageCodeLensProvider from '../../../editors/exportToLanguageCodeLensProvider'; +import { ExportToLanguageMode } from '../../../types/playgroundType'; const expect = chai.expect; @@ -55,7 +56,7 @@ suite('Export To Language Code Lens Provider Test Suite', function () { }); test('has the use builders code lens when builders is false, language is java, and mode is query', () => { - testExportToLanguageCodeLensProvider.refresh({ ...defaults, mode: 'QUERY', language: 'java' }); + testExportToLanguageCodeLensProvider.refresh({ ...defaults, mode: ExportToLanguageMode.QUERY, language: 'java' }); const codeLenses = testExportToLanguageCodeLensProvider.provideCodeLenses(); @@ -64,7 +65,7 @@ suite('Export To Language Code Lens Provider Test Suite', function () { }); test('has the use raw query code lens when builders is true, language is java, and mode is query', () => { - testExportToLanguageCodeLensProvider.refresh({ ...defaults, builders: true, mode: 'QUERY', language: 'java' }); + testExportToLanguageCodeLensProvider.refresh({ ...defaults, builders: true, mode: ExportToLanguageMode.QUERY, language: 'java' }); const codeLenses = testExportToLanguageCodeLensProvider.provideCodeLenses(); @@ -73,7 +74,7 @@ suite('Export To Language Code Lens Provider Test Suite', function () { }); test('does not have the use raw query code lens when builders is true, language is java, and mode is plain text', () => { - testExportToLanguageCodeLensProvider.refresh({ ...defaults, builders: true, mode: 'OTHER', language: 'java' }); + testExportToLanguageCodeLensProvider.refresh({ ...defaults, builders: true, mode: ExportToLanguageMode.OTHER, language: 'java' }); const codeLenses = testExportToLanguageCodeLensProvider.provideCodeLenses(); diff --git a/src/test/suite/editors/playgroundController.test.ts b/src/test/suite/editors/playgroundController.test.ts index 2975b4431..349058cee 100644 --- a/src/test/suite/editors/playgroundController.test.ts +++ b/src/test/suite/editors/playgroundController.test.ts @@ -474,105 +474,6 @@ suite('Playground Controller Test Suite', function () { activeTestEditorMock ); }); - - test('getDocumentLanguage returns json if content is object', async () => { - await vscode.workspace - .getConfiguration('mdb') - .update('confirmRunAll', false); - const language = testPlaygroundController._getDocumentLanguage({ - namespace: null, - type: 'object', - content: { - test: 'value' - } - }); - - expect(language).to.be.equal('json'); - }); - - test('getDocumentLanguage returns json if content is array', async () => { - await vscode.workspace - .getConfiguration('mdb') - .update('confirmRunAll', false); - const language = testPlaygroundController._getDocumentLanguage({ - namespace: null, - type: 'object', - content: [{ - test: 'value' - }] - }); - - expect(language).to.be.equal('json'); - }); - - test('getDocumentLanguage returns json if content is object with BSON value', async () => { - await vscode.workspace - .getConfiguration('mdb') - .update('confirmRunAll', false); - const language = testPlaygroundController._getDocumentLanguage({ - namespace: null, - type: 'object', - content: { - _id: { - $oid: '5d973ae7443762aae72a160' - } - } - }); - - expect(language).to.be.equal('json'); - }); - - test('getDocumentLanguage returns plaintext if content is string', async () => { - await vscode.workspace - .getConfiguration('mdb') - .update('confirmRunAll', false); - const language = testPlaygroundController._getDocumentLanguage({ - namespace: null, - type: 'string', - content: 'I am a string' - }); - - expect(language).to.be.equal('plaintext'); - }); - - test('getDocumentLanguage returns plaintext if content is number', async () => { - await vscode.workspace - .getConfiguration('mdb') - .update('confirmRunAll', false); - const language = testPlaygroundController._getDocumentLanguage({ - namespace: null, - type: 'number', - content: 12 - }); - - expect(language).to.be.equal('plaintext'); - }); - - test('getDocumentLanguage returns plaintext if content is undefined', async () => { - await vscode.workspace - .getConfiguration('mdb') - .update('confirmRunAll', false); - const language = testPlaygroundController._getDocumentLanguage({ - namespace: null, - type: null, - content: undefined - }); - - expect(language).to.be.equal('plaintext'); - }); - - test('getDocumentLanguage returns plaintext if content is null', async () => { - await vscode.workspace - .getConfiguration('mdb') - .update('confirmRunAll', false); - const language = testPlaygroundController._getDocumentLanguage({ - namespace: null, - type: null, - content: null - }); - - expect(language).to.be.equal('plaintext'); - }); }); }); }); diff --git a/src/test/suite/editors/playgroundResultProvider.test.ts b/src/test/suite/editors/playgroundResultProvider.test.ts index 5e78e7e4b..85e7ae57f 100644 --- a/src/test/suite/editors/playgroundResultProvider.test.ts +++ b/src/test/suite/editors/playgroundResultProvider.test.ts @@ -48,7 +48,8 @@ suite('Playground Result Provider Test Suite', () => { { namespace: null, type: null, - content: undefined + content: undefined, + language: null } ); }); @@ -64,7 +65,8 @@ suite('Playground Result Provider Test Suite', () => { content: { _id: '93333a0d-83f6-4e6f-a575-af7ea6187a4a', name: 'Berlin' - } + }, + language: 'json' }; testPlaygroundResultViewProvider.setPlaygroundResult(playgroundResult); @@ -83,7 +85,8 @@ suite('Playground Result Provider Test Suite', () => { testPlaygroundResultViewProvider._playgroundResult = { namespace: 'db.berlin', type: 'undefined', - content: null + content: null, + language: 'plaintext' }; const result = testPlaygroundResultViewProvider.provideTextDocumentContent(); @@ -100,7 +103,8 @@ suite('Playground Result Provider Test Suite', () => { testPlaygroundResultViewProvider._playgroundResult = { namespace: 'db.berlin', type: 'object', - content: null + content: null, + language: 'plaintext' }; const result = testPlaygroundResultViewProvider.provideTextDocumentContent(); @@ -117,7 +121,8 @@ suite('Playground Result Provider Test Suite', () => { testPlaygroundResultViewProvider._playgroundResult = { namespace: 'db.berlin', type: 'number', - content: 4 + content: 4, + language: 'plaintext' }; const result = testPlaygroundResultViewProvider.provideTextDocumentContent(); @@ -134,7 +139,8 @@ suite('Playground Result Provider Test Suite', () => { testPlaygroundResultViewProvider._playgroundResult = { namespace: 'db.berlin', type: 'object', - content: [] + content: [], + language: 'json' }; const result = testPlaygroundResultViewProvider.provideTextDocumentContent(); @@ -151,7 +157,8 @@ suite('Playground Result Provider Test Suite', () => { testPlaygroundResultViewProvider._playgroundResult = { namespace: 'db.berlin', type: 'object', - content: {} + content: {}, + language: 'json' }; const result = testPlaygroundResultViewProvider.provideTextDocumentContent(); @@ -168,7 +175,8 @@ suite('Playground Result Provider Test Suite', () => { testPlaygroundResultViewProvider._playgroundResult = { namespace: 'db.berlin', type: 'boolean', - content: true + content: true, + language: 'plaintext' }; const result = testPlaygroundResultViewProvider.provideTextDocumentContent(); @@ -185,7 +193,8 @@ suite('Playground Result Provider Test Suite', () => { testPlaygroundResultViewProvider._playgroundResult = { namespace: 'db.berlin', type: 'string', - content: 'Berlin' + content: 'Berlin', + language: 'plaintext' }; const result = testPlaygroundResultViewProvider.provideTextDocumentContent(); @@ -211,7 +220,8 @@ suite('Playground Result Provider Test Suite', () => { const playgroundResult = { namespace: 'db.berlin', type: 'Cursor', - content + content, + language: 'json' }; const mockRefresh: any = sinon.fake(); @@ -242,7 +252,8 @@ suite('Playground Result Provider Test Suite', () => { const playgroundResult = { namespace: 'db.berlin', type: 'Document', - content + content, + language: 'json' }; const mockRefresh: any = sinon.fake(); @@ -273,7 +284,8 @@ suite('Playground Result Provider Test Suite', () => { content: [ { _id: 1, item: 'abc', price: 10, quantity: 2, date: new Date('2014-03-01T08:00:00Z') }, { _id: 2, item: 'jkl', price: 20, quantity: 1, date: new Date('2014-03-01T09:00:00Z') } - ] + ], + language: 'json' }; const connectionId = '1c8c2b06-fbfb-40b7-bd8a-bd1f8333a487'; diff --git a/src/test/suite/language/mongoDBService.test.ts b/src/test/suite/language/mongoDBService.test.ts index 181b7ed17..ccf00a494 100644 --- a/src/test/suite/language/mongoDBService.test.ts +++ b/src/test/suite/language/mongoDBService.test.ts @@ -985,7 +985,7 @@ suite('MongoDBService Test Suite', () => { ); const expectedResult = { outputLines: [], - result: { namespace: null, type: 'number', content: 2 } + result: { namespace: null, type: 'number', content: 2, language: 'plaintext' } }; expect(result).to.deep.equal(expectedResult); @@ -1015,7 +1015,7 @@ suite('MongoDBService Test Suite', () => { ); const expectedResult = { outputLines: [], - result: { namespace: null, type: 'number', content: 3 } + result: { namespace: null, type: 'number', content: 3, language: 'plaintext' } }; expect(result).to.deep.equal(expectedResult); @@ -1032,7 +1032,7 @@ suite('MongoDBService Test Suite', () => { ); const firstRes = { outputLines: [], - result: { namespace: null, type: 'number', content: 2 } + result: { namespace: null, type: 'number', content: 2, language: 'plaintext' } }; expect(firstEvalResult).to.deep.equal(firstRes); @@ -1046,7 +1046,7 @@ suite('MongoDBService Test Suite', () => { ); const secondRes = { outputLines: [], - result: { namespace: null, type: 'number', content: 3 } + result: { namespace: null, type: 'number', content: 3, language: 'plaintext' } }; expect(secondEvalResult).to.deep.equal(secondRes); @@ -1072,7 +1072,102 @@ suite('MongoDBService Test Suite', () => { _id: { $oid: '5fb292760ece2dc9c0362075' } - } + }, + language: 'json' + } + }; + + expect(result).to.deep.equal(expectedResult); + }); + + test('evaluate returns an object', async () => { + const source = new CancellationTokenSource(); + const result = await testMongoDBService.executeAll( + { + connectionId: 'pineapple', + codeToEvaluate: `const obj = { name: "a short string" }; + obj` + }, + source.token + ); + const expectedResult = { + outputLines: [], + result: { + namespace: null, + type: 'object', + content: { + name: 'a short string' + }, + language: 'json' + } + }; + + expect(result).to.deep.equal(expectedResult); + }); + + test('evaluate returns an array', async () => { + const source = new CancellationTokenSource(); + const result = await testMongoDBService.executeAll( + { + connectionId: 'pineapple', + codeToEvaluate: `const arr = [{ name: "a short string" }]; + arr` + }, + source.token + ); + const expectedResult = { + outputLines: [], + result: { + namespace: null, + type: 'object', + content: [{ + name: 'a short string' + }], + language: 'json' + } + }; + + expect(result).to.deep.equal(expectedResult); + }); + + test('evaluate returns undefined', async () => { + const source = new CancellationTokenSource(); + const result = await testMongoDBService.executeAll( + { + connectionId: 'pineapple', + codeToEvaluate: 'undefined' + }, + source.token + ); + const expectedResult = { + outputLines: [], + result: { + namespace: null, + type: 'undefined', + content: null, + language: 'plaintext' + } + }; + + expect(result).to.deep.equal(expectedResult); + }); + + test('evaluate returns null', async () => { + const source = new CancellationTokenSource(); + const result = await testMongoDBService.executeAll( + { + connectionId: 'pineapple', + codeToEvaluate: 'null' + }, + source.token + ); + const expectedResult = { + outputLines: [], + result: { + namespace: null, + type: 'object', + content: null, + language: 'plaintext' } }; @@ -1094,7 +1189,8 @@ suite('MongoDBService Test Suite', () => { result: { namespace: null, type: 'string', - content: 'A single line string' + content: 'A single line string', + language: 'plaintext' } }; @@ -1120,7 +1216,8 @@ suite('MongoDBService Test Suite', () => { type: 'string', content: `vscode is - awesome` + awesome`, + language: 'plaintext' } }; @@ -1138,12 +1235,12 @@ suite('MongoDBService Test Suite', () => { ); const expectedResult = { outputLines: [ - { namespace: null, type: null, content: 'Hello' }, - { namespace: null, type: null, content: 1 }, - { namespace: null, type: null, content: 2 }, - { namespace: null, type: null, content: 3 } + { namespace: null, type: null, content: 'Hello', language: null }, + { namespace: null, type: null, content: 1, language: null }, + { namespace: null, type: null, content: 2, language: null }, + { namespace: null, type: null, content: 3, language: null } ], - result: { namespace: null, type: 'number', content: 42 } + result: { namespace: null, type: 'number', content: 42, language: 'plaintext' } }; expect(result).to.deep.equal(expectedResult); diff --git a/src/test/suite/mdbExtensionController.test.ts b/src/test/suite/mdbExtensionController.test.ts index 0e340fc81..34792d197 100644 --- a/src/test/suite/mdbExtensionController.test.ts +++ b/src/test/suite/mdbExtensionController.test.ts @@ -1532,7 +1532,7 @@ suite('MDBExtensionController Test Suite', function () { ); }); - test('mdb.createIndexFromTreeView should create a MongoDB playground with search template', async () => { + test('mdb.createIndexFromTreeView should create a MongoDB playground with index template', async () => { const mockOpenTextDocument: any = sinon.fake.resolves('untitled'); sinon.replace(vscode.workspace, 'openTextDocument', mockOpenTextDocument); diff --git a/src/test/suite/stubs.ts b/src/test/suite/stubs.ts index 3895c45e3..1a34f62c7 100644 --- a/src/test/suite/stubs.ts +++ b/src/test/suite/stubs.ts @@ -244,7 +244,7 @@ class MockLanguageServerController { executeAll(/* codeToEvaluate: string */): Promise { return Promise.resolve({ outputLines: [], - result: { namespace: null, type: null, content: 'Result' } + result: { namespace: null, type: null, content: 'Result', language: 'plaintext' } }); } diff --git a/src/test/suite/telemetry/telemetryService.test.ts b/src/test/suite/telemetry/telemetryService.test.ts index 895270fb6..55db670bb 100644 --- a/src/test/suite/telemetry/telemetryService.test.ts +++ b/src/test/suite/telemetry/telemetryService.test.ts @@ -343,7 +343,7 @@ suite('Telemetry Controller Test Suite', () => { test('convert AggregationCursor shellApiType to aggregation telemetry type', () => { const res = { outputLines: [], - result: { namespace: null, type: 'AggregationCursor', content: '' } + result: { namespace: null, type: 'AggregationCursor', content: '', language: 'plaintext' }, }; const type = testTelemetryService.getPlaygroundResultType(res); @@ -353,7 +353,7 @@ suite('Telemetry Controller Test Suite', () => { test('convert BulkWriteResult shellApiType to other telemetry type', () => { const res = { outputLines: [], - result: { namespace: null, type: 'BulkWriteResult', content: '' } + result: { namespace: null, type: 'BulkWriteResult', content: '', language: 'plaintext' } }; const type = testTelemetryService.getPlaygroundResultType(res); @@ -363,7 +363,7 @@ suite('Telemetry Controller Test Suite', () => { test('convert Collection shellApiType to other telemetry type', () => { const res = { outputLines: [], - result: { namespace: null, type: 'Collection', content: '' } + result: { namespace: null, type: 'Collection', content: '', language: 'plaintext' } }; const type = testTelemetryService.getPlaygroundResultType(res); @@ -373,7 +373,7 @@ suite('Telemetry Controller Test Suite', () => { test('convert Cursor shellApiType to other telemetry type', () => { const res = { outputLines: [], - result: { namespace: null, type: 'Cursor', content: '' } + result: { namespace: null, type: 'Cursor', content: '', language: 'plaintext' } }; const type = testTelemetryService.getPlaygroundResultType(res); @@ -383,7 +383,7 @@ suite('Telemetry Controller Test Suite', () => { test('convert Database shellApiType to other telemetry type', () => { const res = { outputLines: [], - result: { namespace: null, type: 'Database', content: '' } + result: { namespace: null, type: 'Database', content: '', language: 'plaintext' } }; const type = testTelemetryService.getPlaygroundResultType(res); @@ -393,7 +393,7 @@ suite('Telemetry Controller Test Suite', () => { test('convert DeleteResult shellApiType to other telemetry type', () => { const res = { outputLines: [], - result: { namespace: null, type: 'DeleteResult', content: '' } + result: { namespace: null, type: 'DeleteResult', content: '', language: 'plaintext' } }; const type = testTelemetryService.getPlaygroundResultType(res); @@ -403,7 +403,7 @@ suite('Telemetry Controller Test Suite', () => { test('convert InsertManyResult shellApiType to other telemetry type', () => { const res = { outputLines: [], - result: { namespace: null, type: 'InsertManyResult', content: '' } + result: { namespace: null, type: 'InsertManyResult', content: '', language: 'plaintext' } }; const type = testTelemetryService.getPlaygroundResultType(res); @@ -413,7 +413,7 @@ suite('Telemetry Controller Test Suite', () => { test('convert InsertOneResult shellApiType to other telemetry type', () => { const res = { outputLines: [], - result: { namespace: null, type: 'InsertOneResult', content: '' } + result: { namespace: null, type: 'InsertOneResult', content: '', language: 'plaintext' } }; const type = testTelemetryService.getPlaygroundResultType(res); @@ -423,7 +423,7 @@ suite('Telemetry Controller Test Suite', () => { test('convert ReplicaSet shellApiType to other telemetry type', () => { const res = { outputLines: [], - result: { namespace: null, type: 'ReplicaSet', content: '' } + result: { namespace: null, type: 'ReplicaSet', content: '', language: 'plaintext' } }; const type = testTelemetryService.getPlaygroundResultType(res); @@ -433,7 +433,7 @@ suite('Telemetry Controller Test Suite', () => { test('convert Shard shellApiType to other telemetry type', () => { const res = { outputLines: [], - result: { namespace: null, type: 'Shard', content: '' } + result: { namespace: null, type: 'Shard', content: '', language: 'plaintext' } }; const type = testTelemetryService.getPlaygroundResultType(res); @@ -443,7 +443,7 @@ suite('Telemetry Controller Test Suite', () => { test('convert ShellApi shellApiType to other telemetry type', () => { const res = { outputLines: [], - result: { namespace: null, type: 'ShellApi', content: '' } + result: { namespace: null, type: 'ShellApi', content: '', language: 'plaintext' } }; const type = testTelemetryService.getPlaygroundResultType(res); @@ -453,7 +453,7 @@ suite('Telemetry Controller Test Suite', () => { test('convert UpdateResult shellApiType to other telemetry type', () => { const res = { outputLines: [], - result: { namespace: null, type: 'UpdateResult', content: '' } + result: { namespace: null, type: 'UpdateResult', content: '', language: 'plaintext' } }; const type = testTelemetryService.getPlaygroundResultType(res); @@ -463,7 +463,7 @@ suite('Telemetry Controller Test Suite', () => { test('return other telemetry type if evaluation returns a string', () => { const res = { outputLines: [], - result: { namespace: null, type: null, content: '2' } + result: { namespace: null, type: null, content: '2', language: 'plaintext' } }; const type = testTelemetryService.getPlaygroundResultType(res); diff --git a/src/types/playgroundType.ts b/src/types/playgroundType.ts index 71e0b7906..993391fa8 100644 --- a/src/types/playgroundType.ts +++ b/src/types/playgroundType.ts @@ -4,6 +4,7 @@ export type OutputItem = { namespace: string | null; type: string | null; content: any; + language: string | null; }; export type PlaygroundDebug = OutputItem[] | undefined; @@ -28,7 +29,7 @@ export interface ExportToLanguageAddons { driverSyntax: boolean; builders: boolean; language: string; - mode?: string; + mode?: ExportToLanguageMode; } export interface PlaygroundTextAndSelection {