diff --git a/images/dark/export-to-language.svg b/images/dark/export-to-language.svg
new file mode 100644
index 000000000..f04521be2
--- /dev/null
+++ b/images/dark/export-to-language.svg
@@ -0,0 +1,4 @@
+
+
diff --git a/images/light/export-to-language.svg b/images/light/export-to-language.svg
new file mode 100644
index 000000000..e9a7f64a4
--- /dev/null
+++ b/images/light/export-to-language.svg
@@ -0,0 +1,4 @@
+
+
diff --git a/package.json b/package.json
index 3d222e5af..aa670b06c 100644
--- a/package.json
+++ b/package.json
@@ -259,7 +259,7 @@
"title": "MongoDB: Change Active Connection"
},
{
- "command": "mdb.changeDriverSyntax",
+ "command": "mdb.changeDriverSyntaxForExportToLanguage",
"title": "MongoDB: Change Export To Language Driver Syntax"
},
{
@@ -283,40 +283,16 @@
}
},
{
- "command": "mdb.exportCodeToPlayground",
- "title": "Export Code to Playground"
- },
- {
- "command": "mdb.exportToPython",
- "title": "MongoDB: Export To Python 3"
- },
- {
- "command": "mdb.exportToJava",
- "title": "MongoDB: Export To Java"
- },
- {
- "command": "mdb.exportToCsharp",
- "title": "MongoDB: Export To C#"
- },
- {
- "command": "mdb.exportToNode",
- "title": "MongoDB: Export To Node.js"
- },
- {
- "command": "mdb.exportToRuby",
- "title": "MongoDB: Export To Ruby"
- },
- {
- "command": "mdb.exportToGo",
- "title": "MongoDB: Export To Go"
- },
- {
- "command": "mdb.exportToRust",
- "title": "MongoDB: Export To Rust"
+ "command": "mdb.selectTargetForExportToLanguage",
+ "title": "MongoDB: Select Target For Export to Language",
+ "icon": {
+ "light": "images/light/export-to-language.svg",
+ "dark": "images/dark/export-to-language.svg"
+ }
},
{
- "command": "mdb.exportToPHP",
- "title": "MongoDB: Export To PHP"
+ "command": "mdb.exportCodeToPlayground",
+ "title": "Export Code to Playground"
},
{
"command": "mdb.addConnection",
@@ -745,9 +721,14 @@
}
],
"editor/title": [
+ {
+ "command": "mdb.selectTargetForExportToLanguage",
+ "group": "navigation@1",
+ "when": "mdb.isPlayground == true"
+ },
{
"command": "mdb.runPlayground",
- "group": "navigation",
+ "group": "navigation@2",
"when": "mdb.isPlayground == true"
}
],
@@ -808,38 +789,6 @@
"command": "mdb.runAllPlaygroundBlocks",
"when": "mdb.isPlayground == true"
},
- {
- "command": "mdb.exportToRuby",
- "when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
- },
- {
- "command": "mdb.exportToPython",
- "when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
- },
- {
- "command": "mdb.exportToJava",
- "when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
- },
- {
- "command": "mdb.exportToCsharp",
- "when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
- },
- {
- "command": "mdb.exportToNode",
- "when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
- },
- {
- "command": "mdb.exportToGo",
- "when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
- },
- {
- "command": "mdb.exportToRust",
- "when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
- },
- {
- "command": "mdb.exportToPHP",
- "when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
- },
{
"command": "mdb.refreshPlaygroundsFromTreeView",
"when": "false"
@@ -873,7 +822,7 @@
"when": "mdb.isPlayground"
},
{
- "command": "mdb.changeDriverSyntax",
+ "command": "mdb.changeDriverSyntaxForExportToLanguage",
"when": "false"
},
{
@@ -964,6 +913,10 @@
"command": "mdb.runPlayground",
"when": "false"
},
+ {
+ "command": "mdb.selectTargetForExportToLanguage",
+ "when": "false"
+ },
{
"command": "mdb.exportCodeToPlayground",
"when": "false"
diff --git a/src/commands/index.ts b/src/commands/index.ts
index 9164d0a28..b13cebd1f 100644
--- a/src/commands/index.ts
+++ b/src/commands/index.ts
@@ -20,15 +20,9 @@ enum EXTENSION_COMMANDS {
MDB_FIX_THIS_INVALID_INTERACTIVE_SYNTAX = 'mdb.fixThisInvalidInteractiveSyntax',
MDB_FIX_ALL_INVALID_INTERACTIVE_SYNTAX = 'mdb.fixAllInvalidInteractiveSyntax',
- MDB_EXPORT_TO_PYTHON = 'mdb.exportToPython',
- MDB_EXPORT_TO_JAVA = 'mdb.exportToJava',
- MDB_EXPORT_TO_CSHARP = 'mdb.exportToCsharp',
- MDB_EXPORT_TO_NODE = 'mdb.exportToNode',
- MDB_EXPORT_TO_RUBY = 'mdb.exportToRuby',
- MDB_EXPORT_TO_GO = 'mdb.exportToGo',
- MDB_EXPORT_TO_RUST = 'mdb.exportToRust',
- MDB_EXPORT_TO_PHP = 'mdb.exportToPHP',
- MDB_CHANGE_DRIVER_SYNTAX = 'mdb.changeDriverSyntax',
+ MDB_SELECT_TARGET_FOR_EXPORT_TO_LANGUAGE = 'mdb.selectTargetForExportToLanguage',
+ MDB_EXPORT_TO_LANGUAGE = 'mdb.exportToLanguage',
+ MDB_CHANGE_DRIVER_SYNTAX_FOR_EXPORT_TO_LANGUAGE = 'mdb.changeDriverSyntaxForExportToLanguage',
MDB_OPEN_MONGODB_DOCUMENT_FROM_CODE_LENS = 'mdb.openMongoDBDocumentFromCodeLens',
MDB_OPEN_MONGODB_DOCUMENT_FROM_TREE = 'mdb.openMongoDBDocumentFromTree',
diff --git a/src/editors/exportToLanguageCodeLensProvider.ts b/src/editors/exportToLanguageCodeLensProvider.ts
index 09f071cbf..5b8feb444 100644
--- a/src/editors/exportToLanguageCodeLensProvider.ts
+++ b/src/editors/exportToLanguageCodeLensProvider.ts
@@ -1,12 +1,11 @@
import * as vscode from 'vscode';
import EXTENSION_COMMANDS from '../commands';
-import {
- ExportToLanguage,
- isExportToLanguageResult,
-} from '../types/playgroundType';
+import { isExportToLanguageResult } from '../types/playgroundType';
import type PlaygroundResultProvider from './playgroundResultProvider';
+export const DEFAULT_EXPORT_TO_LANGUAGE_DRIVER_SYNTAX = true;
+
export default class ExportToLanguageCodeLensProvider
implements vscode.CodeLensProvider
{
@@ -45,15 +44,15 @@ export default class ExportToLanguageCodeLensProvider
}
if (
- this._playgroundResultProvider._playgroundResult?.language !==
- ExportToLanguage.CSHARP
+ this._playgroundResultProvider._playgroundResult?.language !== 'csharp'
) {
driverSyntaxCodeLens.command = {
title: this._playgroundResultProvider._playgroundResult
.includeDriverSyntax
? 'Exclude Driver Syntax'
: 'Include Driver Syntax',
- command: EXTENSION_COMMANDS.MDB_CHANGE_DRIVER_SYNTAX,
+ command:
+ EXTENSION_COMMANDS.MDB_CHANGE_DRIVER_SYNTAX_FOR_EXPORT_TO_LANGUAGE,
arguments: [
!this._playgroundResultProvider._playgroundResult.includeDriverSyntax,
],
diff --git a/src/editors/playgroundSelectionCodeActionProvider.ts b/src/editors/playgroundSelectionCodeActionProvider.ts
index 592bac441..578e68ce4 100644
--- a/src/editors/playgroundSelectionCodeActionProvider.ts
+++ b/src/editors/playgroundSelectionCodeActionProvider.ts
@@ -3,51 +3,15 @@ import * as vscode from 'vscode';
import EXTENSION_COMMANDS from '../commands';
import { isPlayground, getSelectedText } from '../utils/playground';
-const selectionCommands = [
- {
- name: 'Run selected playground blocks',
- command: EXTENSION_COMMANDS.MDB_RUN_SELECTED_PLAYGROUND_BLOCKS,
- },
- {
- name: 'Export To Python 3',
- command: EXTENSION_COMMANDS.MDB_EXPORT_TO_PYTHON,
- isCopilotRequired: true,
- },
- {
- name: 'Export To Java',
- command: EXTENSION_COMMANDS.MDB_EXPORT_TO_JAVA,
- isCopilotRequired: true,
- },
- {
- name: 'Export To C#',
- command: EXTENSION_COMMANDS.MDB_EXPORT_TO_CSHARP,
- isCopilotRequired: true,
- },
- {
- name: 'Export To Node.js',
- command: EXTENSION_COMMANDS.MDB_EXPORT_TO_NODE,
- isCopilotRequired: true,
- },
- {
- name: 'Export To Ruby',
- command: EXTENSION_COMMANDS.MDB_EXPORT_TO_RUBY,
- isCopilotRequired: true,
- },
- {
- name: 'Export To Go',
- command: EXTENSION_COMMANDS.MDB_EXPORT_TO_GO,
- isCopilotRequired: true,
- },
- {
- name: 'Export To Rust',
- command: EXTENSION_COMMANDS.MDB_EXPORT_TO_RUST,
- isCopilotRequired: true,
- },
- {
- name: 'Export To PHP',
- command: EXTENSION_COMMANDS.MDB_EXPORT_TO_PHP,
- isCopilotRequired: true,
- },
+export const EXPORT_TO_LANGUAGE_ALIASES = [
+ { id: 'csharp', alias: 'C#' },
+ { id: 'go', alias: 'Go' },
+ { id: 'java', alias: 'Java' },
+ { id: 'javascript', alias: 'Node.js' },
+ { id: 'php', alias: 'PHP' },
+ { id: 'python', alias: 'Python 3' },
+ { id: 'ruby', alias: 'Ruby' },
+ { id: 'rust', alias: 'Rust' },
];
export default class PlaygroundSelectionCodeActionProvider
@@ -67,43 +31,40 @@ export default class PlaygroundSelectionCodeActionProvider
readonly onDidChangeCodeLenses: vscode.Event =
this._onDidChangeCodeCodeAction.event;
- createCodeAction({
- codeActionName,
- codeActionCommand,
- }: {
- codeActionName: string;
- codeActionCommand: string;
- }): vscode.CodeAction {
+ createCodeAction(command: vscode.Command): vscode.CodeAction {
const codeAction = new vscode.CodeAction(
- codeActionName,
+ command.title,
vscode.CodeActionKind.Empty
);
- codeAction.command = {
- command: codeActionCommand,
- title: codeActionName,
- tooltip: codeActionName,
- };
+ codeAction.command = command;
return codeAction;
}
provideCodeActions(): vscode.CodeAction[] | undefined {
const editor = vscode.window.activeTextEditor;
- const codeActions: vscode.CodeAction[] = [];
const copilot = vscode.extensions.getExtension('github.copilot-chat');
+ let codeActions: vscode.CodeAction[] = [
+ this.createCodeAction({
+ title: 'Run selected playground blocks',
+ command: EXTENSION_COMMANDS.MDB_RUN_SELECTED_PLAYGROUND_BLOCKS,
+ }),
+ ];
if (!isPlayground(editor?.document.uri) || !getSelectedText()) {
return;
}
- for (const { name, command, isCopilotRequired } of selectionCommands) {
- if (!isCopilotRequired || copilot?.isActive) {
- codeActions.push(
+ if (copilot?.isActive) {
+ codeActions = [
+ ...codeActions,
+ ...EXPORT_TO_LANGUAGE_ALIASES.map(({ id, alias }) =>
this.createCodeAction({
- codeActionName: name,
- codeActionCommand: command,
+ title: `Export To ${alias}`,
+ command: EXTENSION_COMMANDS.MDB_EXPORT_TO_LANGUAGE,
+ arguments: [id],
})
- );
- }
+ ),
+ ];
}
return codeActions;
diff --git a/src/mdbExtensionController.ts b/src/mdbExtensionController.ts
index 8077e60d2..8d254749d 100644
--- a/src/mdbExtensionController.ts
+++ b/src/mdbExtensionController.ts
@@ -24,10 +24,7 @@ import {
HelpExplorer,
} from './explorer';
import ExportToLanguageCodeLensProvider from './editors/exportToLanguageCodeLensProvider';
-import {
- ExportToLanguage,
- type ExportToLanguageResult,
-} from './types/playgroundType';
+import { type ExportToLanguageResult } from './types/playgroundType';
import EXTENSION_COMMANDS from './commands';
import type FieldTreeItem from './explorer/fieldTreeItem';
import type IndexListTreeItem from './explorer/indexListTreeItem';
@@ -252,51 +249,27 @@ export default class MDBExtensionController implements vscode.Disposable {
);
// ------ EXPORT TO LANGUAGE ------ //
- this.registerCommand(EXTENSION_COMMANDS.MDB_EXPORT_TO_PYTHON, () =>
- this._participantController.exportPlaygroundToLanguage(
- ExportToLanguage.PYTHON
- )
- );
- this.registerCommand(EXTENSION_COMMANDS.MDB_EXPORT_TO_JAVA, () =>
- this._participantController.exportPlaygroundToLanguage(
- ExportToLanguage.JAVA
- )
- );
- this.registerCommand(EXTENSION_COMMANDS.MDB_EXPORT_TO_CSHARP, () =>
- this._participantController.exportPlaygroundToLanguage(
- ExportToLanguage.CSHARP
- )
- );
- this.registerCommand(EXTENSION_COMMANDS.MDB_EXPORT_TO_NODE, () =>
- this._participantController.exportPlaygroundToLanguage(
- ExportToLanguage.JAVASCRIPT
- )
- );
- this.registerCommand(EXTENSION_COMMANDS.MDB_EXPORT_TO_RUBY, () =>
- this._participantController.exportPlaygroundToLanguage(
- ExportToLanguage.RUBY
- )
- );
- this.registerCommand(EXTENSION_COMMANDS.MDB_EXPORT_TO_GO, () =>
- this._participantController.exportPlaygroundToLanguage(
- ExportToLanguage.GO
- )
- );
- this.registerCommand(EXTENSION_COMMANDS.MDB_EXPORT_TO_RUST, () =>
- this._participantController.exportPlaygroundToLanguage(
- ExportToLanguage.RUST
- )
+ this.registerCommand(
+ EXTENSION_COMMANDS.MDB_SELECT_TARGET_FOR_EXPORT_TO_LANGUAGE,
+ () => this._participantController.selectTargetForExportToLanguage()
);
- this.registerCommand(EXTENSION_COMMANDS.MDB_EXPORT_TO_PHP, () =>
- this._participantController.exportPlaygroundToLanguage(
- ExportToLanguage.PHP
- )
+ this.registerCommand(
+ EXTENSION_COMMANDS.MDB_EXPORT_TO_LANGUAGE,
+ (language: string) =>
+ this._participantController.exportPlaygroundToLanguage(language)
);
-
this.registerCommand(
- EXTENSION_COMMANDS.MDB_CHANGE_DRIVER_SYNTAX,
+ EXTENSION_COMMANDS.MDB_CHANGE_DRIVER_SYNTAX_FOR_EXPORT_TO_LANGUAGE,
(includeDriverSyntax: boolean) =>
- this._participantController.changeDriverSyntax(includeDriverSyntax)
+ this._participantController.changeDriverSyntaxForExportToLanguage(
+ includeDriverSyntax
+ )
+ );
+ this.registerParticipantCommand(
+ EXTENSION_COMMANDS.SHOW_EXPORT_TO_LANGUAGE_RESULT,
+ (data: ExportToLanguageResult) => {
+ return this._playgroundController.showExportToLanguageResult(data);
+ }
);
// ------ DOCUMENTS ------ //
@@ -332,12 +305,6 @@ export default class MDBExtensionController implements vscode.Disposable {
);
}
);
- this.registerParticipantCommand(
- EXTENSION_COMMANDS.SHOW_EXPORT_TO_LANGUAGE_RESULT,
- (data: ExportToLanguageResult) => {
- return this._playgroundController.showExportToLanguageResult(data);
- }
- );
this.registerCommand(
EXTENSION_COMMANDS.CONNECT_WITH_PARTICIPANT,
(data: { id?: string; command?: string }) => {
diff --git a/src/participant/participant.ts b/src/participant/participant.ts
index 303b19554..2e1928150 100644
--- a/src/participant/participant.ts
+++ b/src/participant/participant.ts
@@ -47,11 +47,10 @@ import { isPlayground, getSelectedText, getAllText } from '../utils/playground';
import type { DataService } from 'mongodb-data-service';
import { ParticipantErrorTypes } from './participantErrorTypes';
import type PlaygroundResultProvider from '../editors/playgroundResultProvider';
-import {
- type ExportToLanguageResult,
- isExportToLanguageResult,
-} from '../types/playgroundType';
+import { isExportToLanguageResult } from '../types/playgroundType';
import { PromptHistory } from './prompts/promptHistory';
+import { DEFAULT_EXPORT_TO_LANGUAGE_DRIVER_SYNTAX } from '../editors/exportToLanguageCodeLensProvider';
+import { EXPORT_TO_LANGUAGE_ALIASES } from '../editors/playgroundSelectionCodeActionProvider';
const log = createLogger('participant');
@@ -59,7 +58,7 @@ const NUM_DOCUMENTS_TO_SAMPLE = 3;
const MONGODB_DOCS_LINK = 'https://www.mongodb.com/docs/';
-interface NamespaceQuickPicks {
+interface ParticipantQuickPicks {
label: string;
data: string;
}
@@ -498,7 +497,7 @@ export default class ParticipantController {
async getDatabaseQuickPicks(
command: ParticipantCommand
- ): Promise {
+ ): Promise {
const dataService = this._connectionController.getActiveDataService();
if (!dataService) {
// Run a blank command to get the user to connect first.
@@ -561,7 +560,7 @@ export default class ParticipantController {
}: {
command: ParticipantCommand;
databaseName: string;
- }): Promise {
+ }): Promise {
const dataService = this._connectionController.getActiveDataService();
if (!dataService) {
// Run a blank command to get the user to connect first.
@@ -1639,6 +1638,34 @@ export default class ParticipantController {
});
}
+ async selectLanguageWithQuickPick(): Promise {
+ const targetLanguages = EXPORT_TO_LANGUAGE_ALIASES.map(
+ ({ alias }) => alias
+ );
+ const selectedQuickPickItem = await vscode.window.showQuickPick(
+ targetLanguages,
+ {
+ placeHolder: 'Export to...',
+ }
+ );
+ return selectedQuickPickItem;
+ }
+
+ async selectTargetForExportToLanguage(): Promise {
+ const languageAlias = await this.selectLanguageWithQuickPick();
+ const language = EXPORT_TO_LANGUAGE_ALIASES.find(
+ (item) => item.alias === languageAlias
+ );
+ if (!language) {
+ return false;
+ }
+ await vscode.commands.executeCommand(
+ EXTENSION_COMMANDS.MDB_EXPORT_TO_LANGUAGE,
+ language.id
+ );
+ return true;
+ }
+
async exportCodeToPlayground(): Promise {
const selectedText = getSelectedText();
const codeToExport = selectedText || getAllText();
@@ -1705,19 +1732,26 @@ export default class ParticipantController {
}
async _exportPlaygroundToLanguageWithCancelModal({
- codeToTranspile,
+ prompt,
language,
includeDriverSyntax,
- }: Omit): Promise {
+ }: {
+ prompt: string;
+ language: string;
+ includeDriverSyntax: boolean;
+ }): Promise {
+ const languageById = EXPORT_TO_LANGUAGE_ALIASES.find(
+ (item) => item.id === language
+ );
const progressResult = await vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
- title: `Exporting playground to ${language}...`,
+ title: `Exporting playground to ${languageById?.alias || language}...`,
cancellable: true,
},
async (progress, token): Promise => {
const modelInput = await Prompts.exportToLanguage.buildMessages({
- request: { prompt: codeToTranspile },
+ request: { prompt },
language,
includeDriverSyntax,
});
@@ -1860,7 +1894,9 @@ Please see our [FAQ](https://www.mongodb.com/docs/generative-ai-faq/) for more i
.map((connection) => connection.name);
}
- async changeDriverSyntax(includeDriverSyntax: boolean): Promise {
+ async changeDriverSyntaxForExportToLanguage(
+ includeDriverSyntax: boolean
+ ): Promise {
if (
!this._playgroundResultProvider._playgroundResult ||
!isExportToLanguageResult(
@@ -1873,10 +1909,9 @@ Please see our [FAQ](https://www.mongodb.com/docs/generative-ai-faq/) for more i
return false;
}
- return this._transpile({
- ...this._playgroundResultProvider._playgroundResult,
- includeDriverSyntax,
- });
+ const { prompt, language } =
+ this._playgroundResultProvider._playgroundResult;
+ return this._transpile({ prompt, language, includeDriverSyntax });
}
async exportPlaygroundToLanguage(language: string): Promise {
@@ -1890,8 +1925,8 @@ Please see our [FAQ](https://www.mongodb.com/docs/generative-ai-faq/) for more i
}
const selectedText = getSelectedText();
- const codeToTranspile = selectedText || getAllText();
- let includeDriverSyntax = false;
+ const prompt = selectedText || getAllText();
+ let includeDriverSyntax = DEFAULT_EXPORT_TO_LANGUAGE_DRIVER_SYNTAX;
if (
this._playgroundResultProvider._playgroundResult &&
@@ -1901,58 +1936,62 @@ Please see our [FAQ](https://www.mongodb.com/docs/generative-ai-faq/) for more i
this._playgroundResultProvider._playgroundResult.includeDriverSyntax;
}
- return this._transpile({
- codeToTranspile,
- language,
- includeDriverSyntax,
- });
+ return this._transpile({ prompt, language, includeDriverSyntax });
}
async _transpile({
- codeToTranspile,
+ prompt,
language,
includeDriverSyntax,
- }: Omit): Promise {
- log.info(`Exporting to the '${language}' language...`);
+ }: {
+ prompt: string;
+ language: string;
+ includeDriverSyntax: boolean;
+ }): Promise {
+ log.info(`Exporting to the '${language}' language.`);
try {
const transpiledContent =
await this._exportPlaygroundToLanguageWithCancelModal({
- codeToTranspile,
+ prompt,
language,
includeDriverSyntax,
});
if (!transpiledContent) {
- return true;
+ return false;
}
log.info(`The playground was exported to ${language}`, {
- codeToTranspile,
+ prompt,
language,
includeDriverSyntax,
});
+ this._telemetryService.trackPlaygroundExportedToLanguageExported({
+ language,
+ exported_code_length: transpiledContent?.length || 0,
+ with_driver_syntax: includeDriverSyntax,
+ });
await vscode.commands.executeCommand(
EXTENSION_COMMANDS.SHOW_EXPORT_TO_LANGUAGE_RESULT,
{
+ prompt,
content: transpiledContent,
- codeToTranspile,
language,
includeDriverSyntax,
}
);
-
- this._telemetryService.trackPlaygroundExportedToLanguageExported({
- language,
- exported_code_length: transpiledContent?.length || 0,
- with_driver_syntax: includeDriverSyntax,
- });
} catch (error) {
log.error(`Export to ${language} failed`, error);
const printableError = formatError(error);
+ const languageById = EXPORT_TO_LANGUAGE_ALIASES.find(
+ (item) => item.id === language
+ );
void vscode.window.showErrorMessage(
- `Unable to export to ${language}: ${printableError.message}`
+ `Unable to export to ${languageById?.alias || language}: ${
+ printableError.message
+ }`
);
}
diff --git a/src/test/suite/editors/exportToLanguageCodeLensProvider.test.ts b/src/test/suite/editors/exportToLanguageCodeLensProvider.test.ts
index 89192c591..b0eb03545 100644
--- a/src/test/suite/editors/exportToLanguageCodeLensProvider.test.ts
+++ b/src/test/suite/editors/exportToLanguageCodeLensProvider.test.ts
@@ -1,7 +1,9 @@
import { beforeEach } from 'mocha';
import chai from 'chai';
-import ExportToLanguageCodeLensProvider from '../../../editors/exportToLanguageCodeLensProvider';
+import ExportToLanguageCodeLensProvider, {
+ DEFAULT_EXPORT_TO_LANGUAGE_DRIVER_SYNTAX,
+} from '../../../editors/exportToLanguageCodeLensProvider';
import PlaygroundResultProvider from '../../../editors/playgroundResultProvider';
import StorageController from '../../../storage/storageController';
import { ExtensionContextStub } from '../stubs';
@@ -14,8 +16,8 @@ const expect = chai.expect;
const DEFAULT_EXPORT_TO_LANGUAGE_RESULT = {
content: '123',
- codeToTranspile: '123',
- includeDriverSyntax: false,
+ prompt: '123',
+ includeDriverSyntax: DEFAULT_EXPORT_TO_LANGUAGE_DRIVER_SYNTAX,
language: 'shell',
};
@@ -57,7 +59,7 @@ suite('Export To Language Code Lens Provider Test Suite', function () {
);
});
- test('renders the include driver syntax code lens by default for shell', () => {
+ test('renders the exclude driver syntax code lens by default for shell', () => {
testPlaygroundResultProvider.setPlaygroundResult(
DEFAULT_EXPORT_TO_LANGUAGE_RESULT
);
@@ -66,7 +68,7 @@ suite('Export To Language Code Lens Provider Test Suite', function () {
expect(codeLenses).to.exist;
if (codeLenses) {
expect(codeLenses.length).to.be.equal(1);
- expect(codeLenses[0].command?.title).to.be.equal('Include Driver Syntax');
+ expect(codeLenses[0].command?.title).to.be.equal('Exclude Driver Syntax');
}
});
diff --git a/src/test/suite/editors/playgroundSelectionCodeActionProvider.test.ts b/src/test/suite/editors/playgroundSelectionCodeActionProvider.test.ts
index 0df3f9efc..c3e3393cb 100644
--- a/src/test/suite/editors/playgroundSelectionCodeActionProvider.test.ts
+++ b/src/test/suite/editors/playgroundSelectionCodeActionProvider.test.ts
@@ -9,7 +9,9 @@ import { PlaygroundController } from '../../../editors';
import { TEST_DATABASE_URI } from '../dbTestHelper';
import { ExtensionContextStub } from '../stubs';
import { mockTextEditor } from '../stubs';
-import ExportToLanguageCodeLensProvider from '../../../editors/exportToLanguageCodeLensProvider';
+import ExportToLanguageCodeLensProvider, {
+ DEFAULT_EXPORT_TO_LANGUAGE_DRIVER_SYNTAX,
+} from '../../../editors/exportToLanguageCodeLensProvider';
const expect = chai.expect;
@@ -207,7 +209,7 @@ suite('Playground Selection Code Action Provider Test Suite', function () {
});
});
- test('renders the include driver syntax code action and changes it to exclude', async () => {
+ test('renders the exclude driver syntax code action and changes it to include', async () => {
const codeActions = testCodeActionProvider.provideCodeActions();
if (!codeActions) {
@@ -216,14 +218,14 @@ suite('Playground Selection Code Action Provider Test Suite', function () {
}
expect(codeActions.length).to.be.equal(TOTAL_CODEACTIONS_COUNT);
- const actionCommand = codeActions[2].command;
+ const actionCommand = codeActions[3].command;
if (!actionCommand) {
expect.fail('Action command not found');
return false;
}
- expect(actionCommand.command).to.be.equal('mdb.exportToJava');
+ expect(actionCommand.command).to.be.equal('mdb.exportToLanguage');
expect(actionCommand.title).to.be.equal('Export To Java');
await vscode.commands.executeCommand(actionCommand.command);
@@ -231,9 +233,9 @@ suite('Playground Selection Code Action Provider Test Suite', function () {
mdbTestExtension.testExtensionController._playgroundResultProvider.setPlaygroundResult(
{
content: 'Berlin',
- codeToTranspile: 'Berlin',
+ prompt: 'Berlin',
language: 'java',
- includeDriverSyntax: false,
+ includeDriverSyntax: DEFAULT_EXPORT_TO_LANGUAGE_DRIVER_SYNTAX,
}
);
@@ -243,15 +245,15 @@ suite('Playground Selection Code Action Provider Test Suite', function () {
let lensesObj = { lenses: codeLenses };
expect(lensesObj).to.have.nested.property(
'lenses[0].command.title',
- 'Include Driver Syntax'
+ 'Exclude Driver Syntax'
);
mdbTestExtension.testExtensionController._playgroundResultProvider.setPlaygroundResult(
{
content: 'Berlin',
- codeToTranspile: 'Berlin',
+ prompt: 'Berlin',
language: 'java',
- includeDriverSyntax: true,
+ includeDriverSyntax: !DEFAULT_EXPORT_TO_LANGUAGE_DRIVER_SYNTAX,
}
);
@@ -260,7 +262,7 @@ suite('Playground Selection Code Action Provider Test Suite', function () {
lensesObj = { lenses: codeLenses };
expect(lensesObj).to.have.nested.property(
'lenses[0].command.title',
- 'Exclude Driver Syntax'
+ 'Include Driver Syntax'
);
});
});
@@ -284,10 +286,10 @@ suite('Playground Selection Code Action Provider Test Suite', function () {
if (codeActions) {
expect(codeActions.length).to.be.equal(TOTAL_CODEACTIONS_COUNT);
- const actionCommand = codeActions[3].command;
+ const actionCommand = codeActions[1].command;
if (actionCommand) {
- expect(actionCommand.command).to.be.equal('mdb.exportToCsharp');
+ expect(actionCommand.command).to.be.equal('mdb.exportToLanguage');
expect(actionCommand.title).to.be.equal('Export To C#');
await vscode.commands.executeCommand(actionCommand.command);
@@ -319,18 +321,18 @@ suite('Playground Selection Code Action Provider Test Suite', function () {
if (codeActions) {
expect(codeActions.length).to.be.equal(TOTAL_CODEACTIONS_COUNT);
- const actionCommand = codeActions[1].command;
+ const actionCommand = codeActions[6].command;
if (actionCommand) {
- expect(actionCommand.command).to.be.equal('mdb.exportToPython');
+ expect(actionCommand.command).to.be.equal('mdb.exportToLanguage');
expect(actionCommand.title).to.be.equal('Export To Python 3');
mdbTestExtension.testExtensionController._playgroundResultProvider.setPlaygroundResult(
{
content: 'Does not matter',
- codeToTranspile: "use('db'); db.coll.find({ name: '22' })",
+ prompt: "use('db'); db.coll.find({ name: '22' })",
language: 'python',
- includeDriverSyntax: false,
+ includeDriverSyntax: DEFAULT_EXPORT_TO_LANGUAGE_DRIVER_SYNTAX,
}
);
@@ -341,7 +343,7 @@ suite('Playground Selection Code Action Provider Test Suite', function () {
const lensesObj = { lenses: codeLenses };
expect(lensesObj).to.have.nested.property(
'lenses[0].command.title',
- 'Include Driver Syntax'
+ 'Exclude Driver Syntax'
);
}
}
@@ -367,18 +369,18 @@ suite('Playground Selection Code Action Provider Test Suite', function () {
if (codeActions) {
expect(codeActions.length).to.be.equal(TOTAL_CODEACTIONS_COUNT);
- const actionCommand = codeActions[5].command;
+ const actionCommand = codeActions[7].command;
if (actionCommand) {
- expect(actionCommand.command).to.be.equal('mdb.exportToRuby');
+ expect(actionCommand.command).to.be.equal('mdb.exportToLanguage');
expect(actionCommand.title).to.be.equal('Export To Ruby');
mdbTestExtension.testExtensionController._playgroundResultProvider.setPlaygroundResult(
{
content: 'Does not matter',
- codeToTranspile: "use('db'); db.coll.find({ name: '22' })",
+ prompt: "use('db'); db.coll.find({ name: '22' })",
language: 'ruby',
- includeDriverSyntax: false,
+ includeDriverSyntax: DEFAULT_EXPORT_TO_LANGUAGE_DRIVER_SYNTAX,
}
);
@@ -390,7 +392,7 @@ suite('Playground Selection Code Action Provider Test Suite', function () {
const lensesObj = { lenses: codeLenses };
expect(lensesObj).to.have.nested.property(
'lenses[0].command.title',
- 'Include Driver Syntax'
+ 'Exclude Driver Syntax'
);
}
}
@@ -416,18 +418,18 @@ suite('Playground Selection Code Action Provider Test Suite', function () {
if (codeActions) {
expect(codeActions.length).to.be.equal(TOTAL_CODEACTIONS_COUNT);
- const actionCommand = codeActions[6].command;
+ const actionCommand = codeActions[2].command;
if (actionCommand) {
- expect(actionCommand.command).to.be.equal('mdb.exportToGo');
+ expect(actionCommand.command).to.be.equal('mdb.exportToLanguage');
expect(actionCommand.title).to.be.equal('Export To Go');
mdbTestExtension.testExtensionController._playgroundResultProvider.setPlaygroundResult(
{
content: 'Does not matter',
- codeToTranspile: "use('db'); db.coll.find({ name: '22' })",
+ prompt: "use('db'); db.coll.find({ name: '22' })",
language: 'go',
- includeDriverSyntax: false,
+ includeDriverSyntax: DEFAULT_EXPORT_TO_LANGUAGE_DRIVER_SYNTAX,
}
);
@@ -439,7 +441,7 @@ suite('Playground Selection Code Action Provider Test Suite', function () {
const lensesObj = { lenses: codeLenses };
expect(lensesObj).to.have.nested.property(
'lenses[0].command.title',
- 'Include Driver Syntax'
+ 'Exclude Driver Syntax'
);
}
}
@@ -465,18 +467,18 @@ suite('Playground Selection Code Action Provider Test Suite', function () {
if (codeActions) {
expect(codeActions.length).to.be.equal(TOTAL_CODEACTIONS_COUNT);
- const actionCommand = codeActions[7].command;
+ const actionCommand = codeActions[8].command;
if (actionCommand) {
- expect(actionCommand.command).to.be.equal('mdb.exportToRust');
+ expect(actionCommand.command).to.be.equal('mdb.exportToLanguage');
expect(actionCommand.title).to.be.equal('Export To Rust');
mdbTestExtension.testExtensionController._playgroundResultProvider.setPlaygroundResult(
{
content: 'Does not matter',
- codeToTranspile: "use('db'); db.coll.find({ name: '22' })",
+ prompt: "use('db'); db.coll.find({ name: '22' })",
language: 'rust',
- includeDriverSyntax: false,
+ includeDriverSyntax: DEFAULT_EXPORT_TO_LANGUAGE_DRIVER_SYNTAX,
}
);
@@ -488,7 +490,7 @@ suite('Playground Selection Code Action Provider Test Suite', function () {
const lensesObj = { lenses: codeLenses };
expect(lensesObj).to.have.nested.property(
'lenses[0].command.title',
- 'Include Driver Syntax'
+ 'Exclude Driver Syntax'
);
}
}
@@ -514,18 +516,18 @@ suite('Playground Selection Code Action Provider Test Suite', function () {
if (codeActions) {
expect(codeActions.length).to.be.equal(TOTAL_CODEACTIONS_COUNT);
- const actionCommand = codeActions[8].command;
+ const actionCommand = codeActions[5].command;
if (actionCommand) {
- expect(actionCommand.command).to.be.equal('mdb.exportToPHP');
+ expect(actionCommand.command).to.be.equal('mdb.exportToLanguage');
expect(actionCommand.title).to.be.equal('Export To PHP');
mdbTestExtension.testExtensionController._playgroundResultProvider.setPlaygroundResult(
{
content: 'Does not matter',
- codeToTranspile: "use('db'); db.coll.find({ name: '22' })",
+ prompt: "use('db'); db.coll.find({ name: '22' })",
language: 'php',
- includeDriverSyntax: false,
+ includeDriverSyntax: DEFAULT_EXPORT_TO_LANGUAGE_DRIVER_SYNTAX,
}
);
@@ -537,7 +539,7 @@ suite('Playground Selection Code Action Provider Test Suite', function () {
const lensesObj = { lenses: codeLenses };
expect(lensesObj).to.have.nested.property(
'lenses[0].command.title',
- 'Include Driver Syntax'
+ 'Exclude Driver Syntax'
);
}
}
diff --git a/src/types/playgroundType.ts b/src/types/playgroundType.ts
index 07067b8af..38bdc80e7 100644
--- a/src/types/playgroundType.ts
+++ b/src/types/playgroundType.ts
@@ -2,15 +2,15 @@ import type * as vscode from 'vscode';
import type { NodeDriverServiceProvider } from '@mongosh/service-provider-node-driver';
export type PlaygroundRunResult = {
- namespace?: string;
- type?: string;
content: any;
language?: string;
+ namespace?: string;
+ type?: string;
};
export type ExportToLanguageResult = {
+ prompt: string;
content: string;
- codeToTranspile: string;
language: string;
includeDriverSyntax: boolean;
};
@@ -18,7 +18,7 @@ export type ExportToLanguageResult = {
export function isExportToLanguageResult(
result: PlaygroundRunResult | ExportToLanguageResult
): result is ExportToLanguageResult {
- return (result as ExportToLanguageResult).codeToTranspile !== undefined;
+ return (result as ExportToLanguageResult).prompt !== undefined;
}
export type ShellEvaluateResult = {
@@ -36,17 +36,6 @@ export interface PlaygroundTextAndSelection {
selection: vscode.Selection;
}
-export enum ExportToLanguage {
- PYTHON = 'python',
- JAVA = 'java',
- CSHARP = 'csharp',
- JAVASCRIPT = 'javascript',
- RUBY = 'ruby',
- GO = 'go',
- RUST = 'rust',
- PHP = 'php',
-}
-
// MongoClientOptions is the second argument of NodeDriverServiceProvider.connect(connectionStr, options).
export type MongoClientOptions = NonNullable<
Parameters<(typeof NodeDriverServiceProvider)['connect']>[1]