Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Export to language VSCODE-296 #366

Merged
merged 7 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 62 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@
"command": "mdb.changeActiveConnection",
"title": "MongoDB: Change Active Connection"
},
{
"command": "mdb.changeExportToLanguageAddons",
"title": "MongoDB: Change Export To Language Addons"
},
{
"command": "mdb.runSelectedPlaygroundBlocks",
"title": "MongoDB: Run Selected Lines From Playground"
Expand All @@ -246,6 +250,22 @@
"dark": "images/dark/play.svg"
}
},
{
"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"
},
{
"command": "mdb.addConnection",
"title": "Add MongoDB Connection",
Expand Down Expand Up @@ -613,6 +633,10 @@
"command": "mdb.changeActiveConnection",
"when": "false"
},
{
"command": "mdb.changeExportToLanguageAddons",
"when": "false"
},
{
"command": "mdb.copyConnectionString",
"when": "false"
Expand Down Expand Up @@ -876,6 +900,7 @@
"@mongosh/shell-api": "^1.0.4",
"analytics-node": "^5.0.0",
"bson": "^4.4.1",
"bson-transpilers": "^1.2.0",
"classnames": "^2.3.1",
"debug": "^4.3.2",
"dotenv": "^8.2.0",
Expand Down Expand Up @@ -928,6 +953,7 @@
"chai-json-schema": "^1.5.1",
"chalk": "^4.1.2",
"cli-ux": "^5.6.3",
"context-map-webpack-plugin": "^0.1.0",
"cross-env": "^7.0.3",
"css-loader": "^3.4.2",
"depcheck": "^1.4.2",
Expand Down
6 changes: 6 additions & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ enum EXTENSION_COMMANDS {
MDB_RUN_ALL_PLAYGROUND_BLOCKS = 'mdb.runAllPlaygroundBlocks',
MDB_RUN_ALL_OR_SELECTED_PLAYGROUND_BLOCKS = 'mdb.runPlayground',

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_CHANGE_EXPORT_TO_LANGUAGE_ADDONS = 'mdb.changeExportToLanguageAddons',

MDB_OPEN_MONGODB_DOCUMENT_FROM_CODE_LENS = 'mdb.openMongoDBDocumentFromCodeLens',
MDB_OPEN_MONGODB_DOCUMENT_FROM_TREE = 'mdb.openMongoDBDocumentFromTree',
MDB_SAVE_MONGODB_DOCUMENT = 'mdb.saveMongoDBDocument',
Expand Down
67 changes: 58 additions & 9 deletions src/editors/codeActionProvider.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,78 @@
import * as vscode from 'vscode';

import EXTENSION_COMMANDS from '../commands';
import PlaygroundController from './playgroundController';
import { ExportToLanguageMode } from '../types/playgroundType';

export default class CodeActionProvider implements vscode.CodeActionProvider {
_playgroundController: PlaygroundController;
_onDidChangeCodeCodeAction: vscode.EventEmitter<void> = new vscode.EventEmitter<void>();
selection?: vscode.Selection;
mode?: ExportToLanguageMode;

static readonly providedCodeActionKinds = [vscode.CodeActionKind.QuickFix];

constructor(playgroundController: PlaygroundController) {
this._playgroundController = playgroundController;
constructor() {
vscode.workspace.onDidChangeConfiguration(() => {
this._onDidChangeCodeCodeAction.fire();
});
}

readonly onDidChangeCodeLenses: vscode.Event<void> = this
._onDidChangeCodeCodeAction.event;

refresh({ selection, mode }: { selection?: vscode.Selection, mode?: ExportToLanguageMode }): void {
this.selection = selection;
this.mode = mode;
this._onDidChangeCodeCodeAction.fire();
}

provideCodeActions(): vscode.CodeAction[] | undefined {
if (!this._playgroundController._selectedText) {
if (!this.selection) {
return;
}

const commandAction = new vscode.CodeAction('Run selected playground blocks', vscode.CodeActionKind.Empty);

commandAction.command = {
const codeActions: vscode.CodeAction[] = [];
const runSelectedPlaygroundBlockCommand = new vscode.CodeAction('Run selected playground blocks', vscode.CodeActionKind.Empty);
runSelectedPlaygroundBlockCommand.command = {
command: EXTENSION_COMMANDS.MDB_RUN_SELECTED_PLAYGROUND_BLOCKS,
title: 'Run selected playground blocks',
tooltip: 'Run selected playground blocks'
};
codeActions.push(runSelectedPlaygroundBlockCommand);

if (this.mode === ExportToLanguageMode.QUERY || this.mode === ExportToLanguageMode.AGGREGATION) {
const exportToPythonCommand = new vscode.CodeAction('Export To Python 3', vscode.CodeActionKind.Empty);
exportToPythonCommand.command = {
command: EXTENSION_COMMANDS.MDB_EXPORT_TO_PYTHON,
title: 'Export To Python 3',
tooltip: 'Export To Python 3'
};
codeActions.push(exportToPythonCommand);

const exportToJavaCommand = new vscode.CodeAction('Export To Java', vscode.CodeActionKind.Empty);
exportToJavaCommand.command = {
command: EXTENSION_COMMANDS.MDB_EXPORT_TO_JAVA,
title: 'Export To Java',
tooltip: 'Export To Java'
};
codeActions.push(exportToJavaCommand);

const exportToCsharpCommand = new vscode.CodeAction('Export To C#', vscode.CodeActionKind.Empty);
exportToCsharpCommand.command = {
command: EXTENSION_COMMANDS.MDB_EXPORT_TO_CSHARP,
title: 'Export To C#',
tooltip: 'Export To C#'
};
codeActions.push(exportToCsharpCommand);

const exportToJSCommand = new vscode.CodeAction('Export To Node', vscode.CodeActionKind.Empty);
exportToJSCommand.command = {
command: EXTENSION_COMMANDS.MDB_EXPORT_TO_NODE,
title: 'Export To Node',
tooltip: 'Export To Node'
};
codeActions.push(exportToJSCommand);
}

return [commandAction];
return codeActions;
}
}
12 changes: 12 additions & 0 deletions src/editors/editorsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as vscode from 'vscode';
import { EJSON } from 'bson';

import ActiveConnectionCodeLensProvider from './activeConnectionCodeLensProvider';
import ExportToLanguageCodeLensProvider from './exportToLanguageCodeLensProvider';
import CodeActionProvider from './codeActionProvider';
import ConnectionController from '../connectionController';
import CollectionDocumentsCodeLensProvider from './collectionDocumentsCodeLensProvider';
Expand Down Expand Up @@ -95,6 +96,7 @@ export default class EditorsController {
_telemetryService: TelemetryService;
_playgroundResultViewProvider: PlaygroundResultProvider;
_activeConnectionCodeLensProvider: ActiveConnectionCodeLensProvider;
_exportToLanguageCodeLensProvider: ExportToLanguageCodeLensProvider;
_editDocumentCodeLensProvider: EditDocumentCodeLensProvider;
_collectionDocumentsCodeLensProvider: CollectionDocumentsCodeLensProvider;

Expand All @@ -106,6 +108,7 @@ export default class EditorsController {
telemetryService: TelemetryService,
playgroundResultViewProvider: PlaygroundResultProvider,
activeConnectionCodeLensProvider: ActiveConnectionCodeLensProvider,
exportToLanguageCodeLensProvider: ExportToLanguageCodeLensProvider,
codeActionProvider: CodeActionProvider,
editDocumentCodeLensProvider: EditDocumentCodeLensProvider
) {
Expand Down Expand Up @@ -135,6 +138,7 @@ export default class EditorsController {
);
this._playgroundResultViewProvider = playgroundResultViewProvider;
this._activeConnectionCodeLensProvider = activeConnectionCodeLensProvider;
this._exportToLanguageCodeLensProvider = exportToLanguageCodeLensProvider;
this._collectionDocumentsCodeLensProvider = new CollectionDocumentsCodeLensProvider(
this._collectionDocumentsOperationsStore
);
Expand Down Expand Up @@ -399,6 +403,14 @@ export default class EditorsController {
this._activeConnectionCodeLensProvider
)
);
this._context.subscriptions.push(
vscode.languages.registerCodeLensProvider(
{
scheme: PLAYGROUND_RESULT_SCHEME
},
this._exportToLanguageCodeLensProvider
)
);
this._context.subscriptions.push(
vscode.languages.registerCodeLensProvider(
{
Expand Down
Loading