Skip to content

Commit d739406

Browse files
feat(copilot): optimize export with copilot experience VSCODE-655 (#880)
* feat(copilot): optimize export with copilot experience VSCODE-655 * feat: displays export to language list alphanumericaly
1 parent 50c385f commit d739406

11 files changed

+208
-294
lines changed

images/dark/export-to-language.svg

Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 4 additions & 0 deletions
Loading

package.json

Lines changed: 20 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@
259259
"title": "MongoDB: Change Active Connection"
260260
},
261261
{
262-
"command": "mdb.changeDriverSyntax",
262+
"command": "mdb.changeDriverSyntaxForExportToLanguage",
263263
"title": "MongoDB: Change Export To Language Driver Syntax"
264264
},
265265
{
@@ -283,40 +283,16 @@
283283
}
284284
},
285285
{
286-
"command": "mdb.exportCodeToPlayground",
287-
"title": "Export Code to Playground"
288-
},
289-
{
290-
"command": "mdb.exportToPython",
291-
"title": "MongoDB: Export To Python 3"
292-
},
293-
{
294-
"command": "mdb.exportToJava",
295-
"title": "MongoDB: Export To Java"
296-
},
297-
{
298-
"command": "mdb.exportToCsharp",
299-
"title": "MongoDB: Export To C#"
300-
},
301-
{
302-
"command": "mdb.exportToNode",
303-
"title": "MongoDB: Export To Node.js"
304-
},
305-
{
306-
"command": "mdb.exportToRuby",
307-
"title": "MongoDB: Export To Ruby"
308-
},
309-
{
310-
"command": "mdb.exportToGo",
311-
"title": "MongoDB: Export To Go"
312-
},
313-
{
314-
"command": "mdb.exportToRust",
315-
"title": "MongoDB: Export To Rust"
286+
"command": "mdb.selectTargetForExportToLanguage",
287+
"title": "MongoDB: Select Target For Export to Language",
288+
"icon": {
289+
"light": "images/light/export-to-language.svg",
290+
"dark": "images/dark/export-to-language.svg"
291+
}
316292
},
317293
{
318-
"command": "mdb.exportToPHP",
319-
"title": "MongoDB: Export To PHP"
294+
"command": "mdb.exportCodeToPlayground",
295+
"title": "Export Code to Playground"
320296
},
321297
{
322298
"command": "mdb.addConnection",
@@ -745,9 +721,14 @@
745721
}
746722
],
747723
"editor/title": [
724+
{
725+
"command": "mdb.selectTargetForExportToLanguage",
726+
"group": "navigation@1",
727+
"when": "mdb.isPlayground == true"
728+
},
748729
{
749730
"command": "mdb.runPlayground",
750-
"group": "navigation",
731+
"group": "navigation@2",
751732
"when": "mdb.isPlayground == true"
752733
}
753734
],
@@ -808,38 +789,6 @@
808789
"command": "mdb.runAllPlaygroundBlocks",
809790
"when": "mdb.isPlayground == true"
810791
},
811-
{
812-
"command": "mdb.exportToRuby",
813-
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
814-
},
815-
{
816-
"command": "mdb.exportToPython",
817-
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
818-
},
819-
{
820-
"command": "mdb.exportToJava",
821-
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
822-
},
823-
{
824-
"command": "mdb.exportToCsharp",
825-
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
826-
},
827-
{
828-
"command": "mdb.exportToNode",
829-
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
830-
},
831-
{
832-
"command": "mdb.exportToGo",
833-
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
834-
},
835-
{
836-
"command": "mdb.exportToRust",
837-
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
838-
},
839-
{
840-
"command": "mdb.exportToPHP",
841-
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
842-
},
843792
{
844793
"command": "mdb.refreshPlaygroundsFromTreeView",
845794
"when": "false"
@@ -873,7 +822,7 @@
873822
"when": "mdb.isPlayground"
874823
},
875824
{
876-
"command": "mdb.changeDriverSyntax",
825+
"command": "mdb.changeDriverSyntaxForExportToLanguage",
877826
"when": "false"
878827
},
879828
{
@@ -964,6 +913,10 @@
964913
"command": "mdb.runPlayground",
965914
"when": "false"
966915
},
916+
{
917+
"command": "mdb.selectTargetForExportToLanguage",
918+
"when": "false"
919+
},
967920
{
968921
"command": "mdb.exportCodeToPlayground",
969922
"when": "false"

src/commands/index.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,9 @@ enum EXTENSION_COMMANDS {
2020
MDB_FIX_THIS_INVALID_INTERACTIVE_SYNTAX = 'mdb.fixThisInvalidInteractiveSyntax',
2121
MDB_FIX_ALL_INVALID_INTERACTIVE_SYNTAX = 'mdb.fixAllInvalidInteractiveSyntax',
2222

23-
MDB_EXPORT_TO_PYTHON = 'mdb.exportToPython',
24-
MDB_EXPORT_TO_JAVA = 'mdb.exportToJava',
25-
MDB_EXPORT_TO_CSHARP = 'mdb.exportToCsharp',
26-
MDB_EXPORT_TO_NODE = 'mdb.exportToNode',
27-
MDB_EXPORT_TO_RUBY = 'mdb.exportToRuby',
28-
MDB_EXPORT_TO_GO = 'mdb.exportToGo',
29-
MDB_EXPORT_TO_RUST = 'mdb.exportToRust',
30-
MDB_EXPORT_TO_PHP = 'mdb.exportToPHP',
31-
MDB_CHANGE_DRIVER_SYNTAX = 'mdb.changeDriverSyntax',
23+
MDB_SELECT_TARGET_FOR_EXPORT_TO_LANGUAGE = 'mdb.selectTargetForExportToLanguage',
24+
MDB_EXPORT_TO_LANGUAGE = 'mdb.exportToLanguage',
25+
MDB_CHANGE_DRIVER_SYNTAX_FOR_EXPORT_TO_LANGUAGE = 'mdb.changeDriverSyntaxForExportToLanguage',
3226

3327
MDB_OPEN_MONGODB_DOCUMENT_FROM_CODE_LENS = 'mdb.openMongoDBDocumentFromCodeLens',
3428
MDB_OPEN_MONGODB_DOCUMENT_FROM_TREE = 'mdb.openMongoDBDocumentFromTree',

src/editors/exportToLanguageCodeLensProvider.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import * as vscode from 'vscode';
22

33
import EXTENSION_COMMANDS from '../commands';
4-
import {
5-
ExportToLanguage,
6-
isExportToLanguageResult,
7-
} from '../types/playgroundType';
4+
import { isExportToLanguageResult } from '../types/playgroundType';
85
import type PlaygroundResultProvider from './playgroundResultProvider';
96

7+
export const DEFAULT_EXPORT_TO_LANGUAGE_DRIVER_SYNTAX = true;
8+
109
export default class ExportToLanguageCodeLensProvider
1110
implements vscode.CodeLensProvider
1211
{
@@ -45,15 +44,15 @@ export default class ExportToLanguageCodeLensProvider
4544
}
4645

4746
if (
48-
this._playgroundResultProvider._playgroundResult?.language !==
49-
ExportToLanguage.CSHARP
47+
this._playgroundResultProvider._playgroundResult?.language !== 'csharp'
5048
) {
5149
driverSyntaxCodeLens.command = {
5250
title: this._playgroundResultProvider._playgroundResult
5351
.includeDriverSyntax
5452
? 'Exclude Driver Syntax'
5553
: 'Include Driver Syntax',
56-
command: EXTENSION_COMMANDS.MDB_CHANGE_DRIVER_SYNTAX,
54+
command:
55+
EXTENSION_COMMANDS.MDB_CHANGE_DRIVER_SYNTAX_FOR_EXPORT_TO_LANGUAGE,
5756
arguments: [
5857
!this._playgroundResultProvider._playgroundResult.includeDriverSyntax,
5958
],

src/editors/playgroundSelectionCodeActionProvider.ts

Lines changed: 27 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,15 @@ import * as vscode from 'vscode';
33
import EXTENSION_COMMANDS from '../commands';
44
import { isPlayground, getSelectedText } from '../utils/playground';
55

6-
const selectionCommands = [
7-
{
8-
name: 'Run selected playground blocks',
9-
command: EXTENSION_COMMANDS.MDB_RUN_SELECTED_PLAYGROUND_BLOCKS,
10-
},
11-
{
12-
name: 'Export To Python 3',
13-
command: EXTENSION_COMMANDS.MDB_EXPORT_TO_PYTHON,
14-
isCopilotRequired: true,
15-
},
16-
{
17-
name: 'Export To Java',
18-
command: EXTENSION_COMMANDS.MDB_EXPORT_TO_JAVA,
19-
isCopilotRequired: true,
20-
},
21-
{
22-
name: 'Export To C#',
23-
command: EXTENSION_COMMANDS.MDB_EXPORT_TO_CSHARP,
24-
isCopilotRequired: true,
25-
},
26-
{
27-
name: 'Export To Node.js',
28-
command: EXTENSION_COMMANDS.MDB_EXPORT_TO_NODE,
29-
isCopilotRequired: true,
30-
},
31-
{
32-
name: 'Export To Ruby',
33-
command: EXTENSION_COMMANDS.MDB_EXPORT_TO_RUBY,
34-
isCopilotRequired: true,
35-
},
36-
{
37-
name: 'Export To Go',
38-
command: EXTENSION_COMMANDS.MDB_EXPORT_TO_GO,
39-
isCopilotRequired: true,
40-
},
41-
{
42-
name: 'Export To Rust',
43-
command: EXTENSION_COMMANDS.MDB_EXPORT_TO_RUST,
44-
isCopilotRequired: true,
45-
},
46-
{
47-
name: 'Export To PHP',
48-
command: EXTENSION_COMMANDS.MDB_EXPORT_TO_PHP,
49-
isCopilotRequired: true,
50-
},
6+
export const EXPORT_TO_LANGUAGE_ALIASES = [
7+
{ id: 'csharp', alias: 'C#' },
8+
{ id: 'go', alias: 'Go' },
9+
{ id: 'java', alias: 'Java' },
10+
{ id: 'javascript', alias: 'Node.js' },
11+
{ id: 'php', alias: 'PHP' },
12+
{ id: 'python', alias: 'Python 3' },
13+
{ id: 'ruby', alias: 'Ruby' },
14+
{ id: 'rust', alias: 'Rust' },
5115
];
5216

5317
export default class PlaygroundSelectionCodeActionProvider
@@ -67,43 +31,40 @@ export default class PlaygroundSelectionCodeActionProvider
6731
readonly onDidChangeCodeLenses: vscode.Event<void> =
6832
this._onDidChangeCodeCodeAction.event;
6933

70-
createCodeAction({
71-
codeActionName,
72-
codeActionCommand,
73-
}: {
74-
codeActionName: string;
75-
codeActionCommand: string;
76-
}): vscode.CodeAction {
34+
createCodeAction(command: vscode.Command): vscode.CodeAction {
7735
const codeAction = new vscode.CodeAction(
78-
codeActionName,
36+
command.title,
7937
vscode.CodeActionKind.Empty
8038
);
81-
codeAction.command = {
82-
command: codeActionCommand,
83-
title: codeActionName,
84-
tooltip: codeActionName,
85-
};
39+
codeAction.command = command;
8640
return codeAction;
8741
}
8842

8943
provideCodeActions(): vscode.CodeAction[] | undefined {
9044
const editor = vscode.window.activeTextEditor;
91-
const codeActions: vscode.CodeAction[] = [];
9245
const copilot = vscode.extensions.getExtension('github.copilot-chat');
46+
let codeActions: vscode.CodeAction[] = [
47+
this.createCodeAction({
48+
title: 'Run selected playground blocks',
49+
command: EXTENSION_COMMANDS.MDB_RUN_SELECTED_PLAYGROUND_BLOCKS,
50+
}),
51+
];
9352

9453
if (!isPlayground(editor?.document.uri) || !getSelectedText()) {
9554
return;
9655
}
9756

98-
for (const { name, command, isCopilotRequired } of selectionCommands) {
99-
if (!isCopilotRequired || copilot?.isActive) {
100-
codeActions.push(
57+
if (copilot?.isActive) {
58+
codeActions = [
59+
...codeActions,
60+
...EXPORT_TO_LANGUAGE_ALIASES.map(({ id, alias }) =>
10161
this.createCodeAction({
102-
codeActionName: name,
103-
codeActionCommand: command,
62+
title: `Export To ${alias}`,
63+
command: EXTENSION_COMMANDS.MDB_EXPORT_TO_LANGUAGE,
64+
arguments: [id],
10465
})
105-
);
106-
}
66+
),
67+
];
10768
}
10869

10970
return codeActions;

0 commit comments

Comments
 (0)