Skip to content

Commit eebb3f6

Browse files
refactor: tests and commands clean up VSCODE-383 Tests and command palette clean up (#489)
* feat: replace mongodb language with javascript in playgrounds * feat: use js grammar only * feat: save playgrounds as mongodb ext * docs: add comment about read-only root * refactor: clean up * refactor: better handling new files * refactor: drop fragment * feat: add mongodb grammar injection * refactor: restore update-grammar script * docs: update contributing page * refactor: update-grammar * feat: update mongodb injection grammar * test: update for playgrounds in js * refactor: reformat * refactor: restore snippets * refactor: clean up * build: bump vscode engine * build: clean up dependencies * refactor: reforamt * build: try with prev npm * build: try old deps * refactor: reformat * test: use activeTextEditor from the playground controller * refactor: os homedir * refactor: clean up * refactor: address pr comments * test: try bigger timeout * test: less playground documents open * test: clean up * test: assert.strictEqual * test: mock text flaky text document * test: fake vscode messages and get rid of some any * refactor: command palette clean up * refactor: stub status view * test: use sandbox instead of directly using sinon * fix: add mdb prefix
1 parent a1bf127 commit eebb3f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1429
-1592
lines changed

package.json

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
},
109109
{
110110
"view": "mongoDBPlaygroundsExplorer",
111-
"contents": "No '.mongodb' playground files found in the workspace.\n[Create New Playground](command:mdb.createNewPlaygroundFromPlaygroundExplorer)"
111+
"contents": "No MongoDB playground files found in the workspace.\n[Create New Playground](command:mdb.createNewPlaygroundFromTreeView)"
112112
}
113113
],
114114
"languages": [
@@ -175,10 +175,6 @@
175175
"command": "mdb.createPlayground",
176176
"title": "MongoDB: Create MongoDB Playground"
177177
},
178-
{
179-
"command": "mdb.refreshPlaygrounds",
180-
"title": "MongoDB: Refresh Playgrounds List"
181-
},
182178
{
183179
"command": "mdb.refreshPlaygroundsFromTreeView",
184180
"title": "Refresh",
@@ -187,16 +183,12 @@
187183
"dark": "images/dark/refresh.svg"
188184
}
189185
},
190-
{
191-
"command": "mdb.createNewPlaygroundFromViewAction",
192-
"title": "Create MongoDB Playground"
193-
},
194186
{
195187
"command": "mdb.createNewPlaygroundFromOverviewPage",
196188
"title": "Create MongoDB Playground"
197189
},
198190
{
199-
"command": "mdb.createNewPlaygroundFromPlaygroundExplorer",
191+
"command": "mdb.createNewPlaygroundFromTreeView",
200192
"title": "Create MongoDB Playground",
201193
"icon": {
202194
"light": "images/light/add.svg",
@@ -296,7 +288,7 @@
296288
}
297289
},
298290
{
299-
"command": "mdb.openPlaygroundFromTreeItem",
291+
"command": "mdb.openPlaygroundFromTreeView",
300292
"title": "Open Playground"
301293
},
302294
{
@@ -407,11 +399,7 @@
407399
"menus": {
408400
"view/title": [
409401
{
410-
"command": "mdb.createNewPlaygroundFromViewAction",
411-
"when": "view == mongoDBPlaygroundsExplorer"
412-
},
413-
{
414-
"command": "mdb.createNewPlaygroundFromPlaygroundExplorer",
402+
"command": "mdb.createNewPlaygroundFromTreeView",
415403
"when": "view == mongoDBPlaygroundsExplorer",
416404
"group": "navigation@1"
417405
},
@@ -476,7 +464,7 @@
476464
"group": "5@2"
477465
},
478466
{
479-
"command": "mdb.openPlaygroundFromTreeItem",
467+
"command": "mdb.openPlaygroundFromTreeView",
480468
"when": "view == mongoDBPlaygroundsExplorer && viewItem == playgroundsTreeItem",
481469
"group": "1@1"
482470
},
@@ -630,6 +618,10 @@
630618
}
631619
],
632620
"commandPalette": [
621+
{
622+
"command": "mdb.disconnect",
623+
"when": "mdb.connectedToMongoDB == true"
624+
},
633625
{
634626
"command": "mdb.saveMongoDBDocument",
635627
"when": "editorLangId == json"
@@ -644,23 +636,23 @@
644636
},
645637
{
646638
"command": "mdb.exportToRuby",
647-
"when": "mdb.isPlayground == true"
639+
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true"
648640
},
649641
{
650642
"command": "mdb.exportToPython",
651-
"when": "mdb.isPlayground == true"
643+
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true"
652644
},
653645
{
654646
"command": "mdb.exportToJava",
655-
"when": "mdb.isPlayground == true"
647+
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true"
656648
},
657649
{
658650
"command": "mdb.exportToCsharp",
659-
"when": "mdb.isPlayground == true"
651+
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true"
660652
},
661653
{
662654
"command": "mdb.exportToNode",
663-
"when": "mdb.isPlayground == true"
655+
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true"
664656
},
665657
{
666658
"command": "mdb.refreshPlaygroundsFromTreeView",
@@ -678,16 +670,12 @@
678670
"command": "mdb.addConnectionWithURI",
679671
"when": "false"
680672
},
681-
{
682-
"command": "mdb.createNewPlaygroundFromViewAction",
683-
"when": "false"
684-
},
685673
{
686674
"command": "mdb.createNewPlaygroundFromOverviewPage",
687675
"when": "false"
688676
},
689677
{
690-
"command": "mdb.createNewPlaygroundFromPlaygroundExplorer",
678+
"command": "mdb.createNewPlaygroundFromTreeView",
691679
"when": "false"
692680
},
693681
{
@@ -715,7 +703,7 @@
715703
"when": "false"
716704
},
717705
{
718-
"command": "mdb.openPlaygroundFromTreeItem",
706+
"command": "mdb.openPlaygroundFromTreeView",
719707
"when": "false"
720708
},
721709
{

src/commands/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,16 @@ enum EXTENSION_COMMANDS {
2626
MDB_SAVE_MONGODB_DOCUMENT = 'mdb.saveMongoDBDocument',
2727

2828
MDB_CHANGE_ACTIVE_CONNECTION = 'mdb.changeActiveConnection',
29-
MDB_REFRESH_PLAYGROUNDS = 'mdb.refreshPlaygrounds',
3029

3130
MDB_CODELENS_SHOW_MORE_DOCUMENTS = 'mdb.codeLens.showMoreDocumentsClicked',
3231

3332
// Commands from the tree view.
3433
MDB_ADD_CONNECTION = 'mdb.addConnection',
3534
MDB_ADD_CONNECTION_WITH_URI = 'mdb.addConnectionWithURI',
3635
MDB_REFRESH_PLAYGROUNDS_FROM_TREE_VIEW = 'mdb.refreshPlaygroundsFromTreeView',
37-
MDB_OPEN_PLAYGROUND_FROM_TREE_VIEW = 'mdb.openPlaygroundFromTreeItem',
36+
MDB_OPEN_PLAYGROUND_FROM_TREE_VIEW = 'mdb.openPlaygroundFromTreeView',
3837
MDB_CONNECT_TO_CONNECTION_TREE_VIEW = 'mdb.connectToConnectionTreeItem',
39-
MDB_CREATE_PLAYGROUND_FROM_VIEW_ACTION = 'mdb.createNewPlaygroundFromViewAction',
40-
MDB_CREATE_PLAYGROUND_FROM_PLAYGROUND_EXPLORER = 'mdb.createNewPlaygroundFromPlaygroundExplorer',
38+
MDB_CREATE_PLAYGROUND_FROM_TREE_VIEW = 'mdb.createNewPlaygroundFromTreeView',
4139
MDB_DISCONNECT_FROM_CONNECTION_TREE_VIEW = 'mdb.disconnectFromConnectionTreeItem',
4240
MDB_REFRESH_CONNECTION = 'mdb.refreshConnection',
4341
MDB_COPY_CONNECTION_STRING = 'mdb.copyConnectionString',

src/connectionController.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,12 @@ export default class ConnectionController {
491491
// Send metrics to Segment
492492
this.sendTelemetry(dataService, connectionType);
493493

494+
void vscode.commands.executeCommand(
495+
'setContext',
496+
'mdb.connectedToMongoDB',
497+
true
498+
);
499+
494500
return {
495501
successfullyConnected: true,
496502
connectionErrorMessage: '',
@@ -570,6 +576,12 @@ export default class ConnectionController {
570576
await this._activeDataService.disconnect();
571577
void vscode.window.showInformationMessage('MongoDB disconnected.');
572578
this._activeDataService = null;
579+
580+
void vscode.commands.executeCommand(
581+
'setContext',
582+
'mdb.connectedToMongoDB',
583+
false
584+
);
573585
} catch (error) {
574586
// Show an error, however we still reset the active connection to free up the extension.
575587
void vscode.window.showErrorMessage(

src/editors/playgroundController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ export default class PlaygroundController {
598598
!isPlayground(this._activeTextEditor.document.uri)
599599
) {
600600
void vscode.window.showErrorMessage(
601-
"Please open a '.mongodb' playground file before running it."
601+
'Please open a MongoDB playground file before running it.'
602602
);
603603

604604
return Promise.resolve(false);
@@ -616,7 +616,7 @@ export default class PlaygroundController {
616616
!isPlayground(this._activeTextEditor.document.uri)
617617
) {
618618
void vscode.window.showErrorMessage(
619-
"Please open a '.mongodb' playground file before running it."
619+
'Please open a MongoDB playground file before running it.'
620620
);
621621

622622
return Promise.resolve(false);

src/explorer/collectionTreeItem.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ export default class CollectionTreeItem
8383

8484
isDropped = false;
8585

86+
iconPath: { light: string; dark: string };
87+
8688
constructor(
8789
collection: CollectionModelType,
8890
databaseName: string,

src/explorer/documentListTreeItem.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ export default class DocumentListTreeItem
108108

109109
isExpanded: boolean;
110110

111+
iconPath: { light: string; dark: string };
112+
111113
constructor(
112114
collectionName: string,
113115
databaseName: string,

src/explorer/fieldTreeItem.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ export default class FieldTreeItem
173173

174174
isExpanded: boolean;
175175

176+
iconPath: string | { light: string; dark: string };
177+
176178
constructor(
177179
field: SchemaFieldType,
178180
isExpanded: boolean,

src/explorer/schemaTreeItem.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ export default class SchemaTreeItem
5959
hasClickedShowMoreFields: boolean;
6060
hasMoreFieldsToShow: boolean;
6161

62+
iconPath: { light: string; dark: string };
63+
6264
constructor(
6365
collectionName: string,
6466
databaseName: string,

src/language/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88

99
The language server protocol [(LSP)](https://microsoft.github.io/language-server-protocol/specification) is mainly used as a tool between the editor (the client) and a language smartness provider (the server) to integrate features like autocomplete, go to definition, find all references, list document symbols, signature help and much more. You can find the complete list of supported features in [the official documentation](https://code.visualstudio.com/api/language-extensions/language-server-extension-guide).
1010

11-
We can also extend the mongodb language server and client with custom methods to leverage it as a background worker. Because the language server is a separate JSON RPC enabled process, we can add RPC definitions for:
12-
13-
- Execute playground .mongodb scripts with mongosh repl evaluator thingie
14-
- Schema analysis and caching
11+
We extend the mongodb language server and client with custom methods to leverage it as a background worker.
1512

1613
### Debugging
1714

src/language/languageServerController.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ export default class LanguageServerController {
116116
}
117117

118118
deactivate(): void {
119-
if (!this._client) {
120-
return undefined;
121-
}
122-
123119
// Stop the language server
124120
void this._client.stop();
125121
}

0 commit comments

Comments
 (0)