Skip to content

Commit bc1d017

Browse files
alenakhineikaRhys Howell
andauthored
VSCODE-119: Do not check for babel config (#98)
* fix: do not check for babel config * Add sinon types, bump shell-api version, fix typing errors in tests * build: rename badge * refactor: trigger azure Co-authored-by: Rhys Howell <rhys@[email protected]>
1 parent 266b36e commit bc1d017

12 files changed

+740
-181
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MongoDB for VS Code ![PREVIEW](https://img.shields.io/badge/-PREVIEW-orange)
22

3-
[![Build Status](https://dev.azure.com/team-compass/vscode/_apis/build/status/mongodb-js.vscode?branchName=master)](https://dev.azure.com/team-compass/vscode/_build/latest?definitionId=6&branchName=master)
3+
[![Build Status](https://dev.azure.com/team-compass/vscode/_apis/build/status/mongodb-js.vscode?branchName=master)](https://dev.azure.com/team-compass/vscode/_build/latest?definitionId=10&branchName=master)
44

55
MongoDB for VS Code makes it easy to work with MongoDB, whether your own instance or in [MongoDB Atlas](https://www.mongodb.com/cloud/atlas/register).
66

@@ -25,15 +25,15 @@ MongoDB Playgrounds are the most convenient way to prototype and execute CRUD op
2525

2626
![Playgrounds](resources/screenshots/playground.png)
2727

28-
*Make sure you are connected to a server or cluster before using a playground. You can't run a playground and you won't get completions if you are not connected.*
28+
_Make sure you are connected to a server or cluster before using a playground. You can't run a playground and you won't get completions if you are not connected._
2929

3030
### Quick access to the MongoDB Shell
3131

3232
Launch the MongoDB Shell from the command palette to quickly connect to the same cluster you have active in VS Code.
3333

3434
![MongoDB Shell](resources/screenshots/shell-launcher.png)
3535

36-
*The shell binary needs to be in your `$PATH`. This functionality has some issues on Windows, we'll release an update with a fix soon.*
36+
_The shell binary needs to be in your `$PATH`. This functionality has some issues on Windows, we'll release an update with a fix soon._
3737

3838
### Terraform snippet for MongoDB Atlas
3939

@@ -56,7 +56,7 @@ If you use Terraform to manage your infrastructure, MongoDB for VS Code helps yo
5656

5757
## Additional Settings
5858

59-
*These global settings affect how MongoDB for VS Code provides intelligent autocomplete inside snippets and string literals (off by default). Changing the default configuration may affect the behavior and performance of other extensions and of VS Code itself. If you do not change the default settings, you can still trigger intelligent autocomplete inside a snippet or string literal with `Ctrl+Space`.*
59+
_These global settings affect how MongoDB for VS Code provides intelligent autocomplete inside snippets and string literals (off by default). Changing the default configuration may affect the behavior and performance of other extensions and of VS Code itself. If you do not change the default settings, you can still trigger intelligent autocomplete inside a snippet or string literal with `Ctrl+Space`._
6060

6161
- `editor.suggest.snippetsPreventQuickSuggestions`: By default, VS Code prevents code completion in snippet mode (editing placeholders in inserted code). Setting this to `false` allows snippet (eg. `$match`, `$addFields`) and field completion based on the document schema for the `db.collection.aggregate()` expressions.
6262
- `editor.quickSuggestions`: By default, VS Code prevents code completion inside string literals. To enable database names completions for `use('dbName')` expression use this configuration:
@@ -93,6 +93,7 @@ npm run local-install
9393
This will compile and package MongoDB for VS Code into a `.vsix` file and add the extension to your VS Code.
9494

9595
To install this locally on windows:
96+
9697
```shell
9798
npm install
9899
.\node_modules\.bin\vsce.cmd package

package-lock.json

Lines changed: 645 additions & 125 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,9 @@
608608
"@fortawesome/free-solid-svg-icons": "^5.13.0",
609609
"@fortawesome/react-fontawesome": "^0.1.9",
610610
"@leafygreen-ui/toggle": "^3.0.0",
611-
"@mongosh/browser-runtime-electron": "0.0.1-alpha.14",
612-
"@mongosh/service-provider-server": "0.0.1-alpha.14",
613-
"@mongosh/shell-api": "0.0.1-alpha.14",
611+
"@mongosh/browser-runtime-electron": "0.0.1-alpha.15",
612+
"@mongosh/service-provider-server": "0.0.1-alpha.15",
613+
"@mongosh/shell-api": "0.0.1-alpha.15",
614614
"analytics-node": "^3.4.0-beta.1",
615615
"bson": "^4.0.3",
616616
"classnames": "^2.2.6",
@@ -644,6 +644,7 @@
644644
"@types/node": "^13.7.1",
645645
"@types/react": "^16.9.25",
646646
"@types/react-dom": "^16.9.5",
647+
"@types/sinon": "^9.0.1",
647648
"@types/vscode": "^1.41.0",
648649
"@types/ws": "^7.2.4",
649650
"@typescript-eslint/eslint-plugin": "^2.19.2",

src/editors/editorsController.ts

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ const log = createLogger('editors controller');
2626
export default class EditorsController {
2727
_connectionController: ConnectionController;
2828
_collectionDocumentsOperationsStore = new CollectionDocumentsOperationsStore();
29-
3029
_collectionViewProvider: CollectionDocumentsProvider;
3130
_documentViewProvider: DocumentProvider;
3231

33-
constructor(context: vscode.ExtensionContext, connectionController: ConnectionController) {
32+
constructor(
33+
context: vscode.ExtensionContext,
34+
connectionController: ConnectionController
35+
) {
3436
log.info('activating...');
3537
this._connectionController = connectionController;
3638

@@ -42,18 +44,23 @@ export default class EditorsController {
4244

4345
context.subscriptions.push(
4446
vscode.workspace.registerTextDocumentContentProvider(
45-
VIEW_COLLECTION_SCHEME, collectionViewProvider
47+
VIEW_COLLECTION_SCHEME,
48+
collectionViewProvider
4649
)
4750
);
4851
this._collectionViewProvider = collectionViewProvider;
4952

50-
context.subscriptions.push(vscode.languages.registerCodeLensProvider(
51-
{
52-
scheme: VIEW_COLLECTION_SCHEME,
53-
language: 'json'
54-
},
55-
new CollectionDocumentsCodeLensProvider(this._collectionDocumentsOperationsStore)
56-
));
53+
context.subscriptions.push(
54+
vscode.languages.registerCodeLensProvider(
55+
{
56+
scheme: VIEW_COLLECTION_SCHEME,
57+
language: 'json'
58+
},
59+
new CollectionDocumentsCodeLensProvider(
60+
this._collectionDocumentsOperationsStore
61+
)
62+
)
63+
);
5764

5865
const documentViewProvider = new DocumentProvider(
5966
connectionController,
@@ -62,7 +69,8 @@ export default class EditorsController {
6269

6370
context.subscriptions.push(
6471
vscode.workspace.registerTextDocumentContentProvider(
65-
VIEW_DOCUMENT_SCHEME, documentViewProvider
72+
VIEW_DOCUMENT_SCHEME,
73+
documentViewProvider
6674
)
6775
);
6876
this._documentViewProvider = documentViewProvider;
@@ -81,7 +89,9 @@ export default class EditorsController {
8189
value: documentId
8290
});
8391

84-
const documentIdUriQuery = `${DOCUMENT_ID_URI_IDENTIFIER}=${encodeURIComponent(documentIdString)}`;
92+
const documentIdUriQuery = `${DOCUMENT_ID_URI_IDENTIFIER}=${encodeURIComponent(
93+
documentIdString
94+
)}`;
8595
const namespaceUriQuery = `${NAMESPACE_URI_IDENTIFIER}=${namespace}`;
8696

8797
// We attach the current time to ensure a new editor window is opened on
@@ -90,19 +100,24 @@ export default class EditorsController {
90100

91101
// The part of the URI after the scheme and before the query is the file name.
92102
const textDocumentUri = vscode.Uri.parse(
93-
`${VIEW_DOCUMENT_SCHEME}:${namespace}: ${JSON.stringify(documentId)} - ${Date.now()}.json${uriQuery}`
103+
`${VIEW_DOCUMENT_SCHEME}:${namespace}: ${JSON.stringify(
104+
documentId
105+
)} - ${Date.now()}.json${uriQuery}`
94106
);
95107
return new Promise((resolve, reject) => {
96108
vscode.workspace.openTextDocument(textDocumentUri).then((doc) => {
97-
vscode.window.showTextDocument(doc, { preview: false }).then(
98-
() => resolve(true),
99-
reject
100-
);
109+
vscode.window
110+
.showTextDocument(doc, { preview: false })
111+
.then(() => resolve(true), reject);
101112
}, reject);
102113
});
103114
}
104115

105-
static getViewCollectionDocumentsUri(operationId, namespace, connectionId): vscode.Uri {
116+
static getViewCollectionDocumentsUri(
117+
operationId,
118+
namespace,
119+
connectionId
120+
): vscode.Uri {
106121
// We attach a unique id to the query so that it creates a new file in
107122
// the editor and so that we can virtually manage the amount of docs shown.
108123
const operationIdUriQuery = `${OPERATION_ID_URI_IDENTIFIER}=${operationId}`;
@@ -129,32 +144,42 @@ export default class EditorsController {
129144
);
130145
return new Promise((resolve, reject) => {
131146
vscode.workspace.openTextDocument(uri).then((doc) => {
132-
vscode.window.showTextDocument(doc, { preview: false }).then(
133-
() => resolve(true),
134-
reject
135-
);
147+
vscode.window
148+
.showTextDocument(doc, { preview: false })
149+
.then(() => resolve(true), reject);
136150
}, reject);
137151
});
138152
}
139153

140-
onViewMoreCollectionDocuments(operationId: string, connectionId: string, namespace: string): Promise<boolean> {
154+
onViewMoreCollectionDocuments(
155+
operationId: string,
156+
connectionId: string,
157+
namespace: string
158+
): Promise<boolean> {
141159
log.info('view more collection documents', namespace);
142160

143161
// A user might click to fetch more documents multiple times,
144162
// this ensures it only performs one fetch at a time.
145-
if (this._collectionDocumentsOperationsStore.operations[operationId].isCurrentlyFetchingMoreDocuments) {
163+
if (
164+
this._collectionDocumentsOperationsStore.operations[operationId]
165+
.isCurrentlyFetchingMoreDocuments
166+
) {
146167
vscode.window.showErrorMessage('Already fetching more documents...');
147168
return Promise.resolve(false);
148169
}
149170

150171
// Ensure we're still connected to the correct connection.
151172
if (connectionId !== this._connectionController.getActiveConnectionId()) {
152-
vscode.window.showErrorMessage(`Unable to view more documents: no longer connected to ${connectionId}`);
173+
vscode.window.showErrorMessage(
174+
`Unable to view more documents: no longer connected to ${connectionId}`
175+
);
153176
return Promise.resolve(false);
154177
}
155178

156179
if (!this._collectionViewProvider) {
157-
return Promise.reject(new Error('No registered collection view provider.'));
180+
return Promise.reject(
181+
new Error('No registered collection view provider.')
182+
);
158183
}
159184

160185
const uri = EditorsController.getViewCollectionDocumentsUri(
@@ -163,7 +188,9 @@ export default class EditorsController {
163188
connectionId
164189
);
165190

166-
this._collectionDocumentsOperationsStore.increaseOperationDocumentLimit(operationId);
191+
this._collectionDocumentsOperationsStore.increaseOperationDocumentLimit(
192+
operationId
193+
);
167194

168195
// Notify the document provider to update with the new document limit.
169196
this._collectionViewProvider.onDidChangeEmitter.fire(uri);

src/editors/playgroundController.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ export default class PlaygroundController {
7070
if (
7171
editor &&
7272
editor.document &&
73-
!editor.document.uri.path.includes('extension-output')
73+
editor.document.languageId === 'mongodb'
7474
) {
7575
this._activeTextEditor = editor;
76-
log.info('Active editor uri', editor.document.uri.path);
76+
log.info('Active editor path', editor.document.uri?.path);
7777
}
7878
});
7979
}
@@ -172,8 +172,12 @@ export default class PlaygroundController {
172172
return resolve(null);
173173
});
174174

175-
const codeToEvaluate =
176-
this._activeTextEditor?.document.getText() || '';
175+
let codeToEvaluate = '';
176+
177+
if (this._activeTextEditor && this._activeTextEditor.document) {
178+
codeToEvaluate = this._activeTextEditor.document.getText() || '';
179+
}
180+
177181
// Run all playground scripts.
178182
const result = await this.evaluate(codeToEvaluate);
179183

src/test/suite/connectionController.test.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ suite('Connection Controller Test Suite', function () {
4242
beforeEach(() => {
4343
// Here we stub the showInformationMessage process because it is too much
4444
// for the render process and leads to crashes while testing.
45-
sinon.replace(vscode.window, 'showInformationMessage', sinon.stub());
45+
sinon.replace(
46+
vscode.window,
47+
'showInformationMessage',
48+
sinon.fake.resolves(true)
49+
);
4650
});
4751

4852
afterEach(async () => {
@@ -155,8 +159,8 @@ suite('Connection Controller Test Suite', function () {
155159
await testConnectionController.disconnect();
156160

157161
assert(
158-
fakeVscodeErrorMessage.firstArg === expectedMessage,
159-
`Expected error message "${expectedMessage}" when disconnecting with no active connection, recieved "${fakeVscodeErrorMessage.firstArg}"`
162+
fakeVscodeErrorMessage.firstCall.args[0] === expectedMessage,
163+
`Expected error message "${expectedMessage}" when disconnecting with no active connection, recieved "${fakeVscodeErrorMessage.firstCall.args[0]}"`
160164
);
161165
} catch (error) {
162166
assert(!!error, 'Expected an error disconnect response.');
@@ -245,8 +249,8 @@ suite('Connection Controller Test Suite', function () {
245249
await testConnectionController.disconnect();
246250

247251
assert(
248-
fakeVscodeErrorMessage.firstArg === expectedMessage,
249-
`Expected "${expectedMessage}" when disconnecting while connecting, recieved "${fakeVscodeErrorMessage.firstArg}"`
252+
fakeVscodeErrorMessage.firstCall.args[0] === expectedMessage,
253+
`Expected "${expectedMessage}" when disconnecting while connecting, recieved "${fakeVscodeErrorMessage.firstCall.args[0]}"`
250254
);
251255
} catch (error) {
252256
assert(!!error, 'Expected an error disconnect response.');
@@ -265,8 +269,8 @@ suite('Connection Controller Test Suite', function () {
265269
await testConnectionController.disconnect();
266270

267271
assert(
268-
fakeVscodeErrorMessage.firstArg === expectedMessage,
269-
`Expected "${expectedMessage}" when disconnecting while already disconnecting, recieved "${fakeVscodeErrorMessage.firstArg}"`
272+
fakeVscodeErrorMessage.firstCall.args[0] === expectedMessage,
273+
`Expected "${expectedMessage}" when disconnecting while already disconnecting, recieved "${fakeVscodeErrorMessage.firstCall.args[0]}"`
270274
);
271275
} catch (error) {
272276
assert(!!error, 'Expected an error disconnect response.');
@@ -486,9 +490,9 @@ suite('Connection Controller Test Suite', function () {
486490
});
487491

488492
test('a connection can be connected to by id', async () => {
489-
const getConnection = (TEST_DATABASE_URI): Promise<any> =>
493+
const getConnection = (dbUri): Promise<any> =>
490494
new Promise((resolve, reject) => {
491-
Connection.from(TEST_DATABASE_URI, (err, connectionModel) => {
495+
Connection.from(dbUri, (err, connectionModel) => {
492496
if (err) {
493497
return reject(err);
494498
}

src/test/suite/editors/collectionDocumentsProvider.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ suite('Collection Documents Provider Test Suite', () => {
240240
): void => {
241241
assert(mockShowMessage.called);
242242
assert(!mockHideMessage.called);
243-
assert(mockShowMessage.firstArg === 'Fetching documents...');
243+
assert(mockShowMessage.firstCall.args[0] === 'Fetching documents...');
244244

245245
return callback(null, ['aaaaaaaaaaaaaaaaa']);
246246
};

src/test/suite/editors/documentProvider.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ suite('Document Provider Test Suite', () => {
191191
): void => {
192192
assert(mockShowMessage.called);
193193
assert(!mockHideMessage.called);
194-
assert(mockShowMessage.firstArg === 'Fetching document...');
194+
assert(mockShowMessage.firstCall.args[0] === 'Fetching document...');
195195

196196
return callback(null, [{ b: 'aaaaaaaaaaaaaaaaa' }]);
197197
};

src/test/suite/explorer/explorerController.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ suite('Explorer Controller Test Suite', function () {
346346

347347
testExplorerController.activateTreeView();
348348

349-
const treeControllerStub = sinon.stub().returns();
349+
const treeControllerStub = sinon.stub().returns(null);
350350

351351
sinon.replace(
352352
testExplorerController.getTreeController(),

src/test/suite/explorer/schemaTreeItem.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ suite('SchemaTreeItem Test Suite', () => {
156156
const expectedMessage =
157157
'Unable to parse schema: Unknown input type for `docs`. Must be an array, stream or MongoDB Cursor.';
158158
assert(
159-
fakeVscodeErrorMessage.firstArg === expectedMessage,
160-
`Expected error message to be "${expectedMessage}" found "${fakeVscodeErrorMessage.firstArg}"`
159+
fakeVscodeErrorMessage.firstCall.args[0] === expectedMessage,
160+
`Expected error message to be "${expectedMessage}" found "${fakeVscodeErrorMessage.firstCall.args[0]}"`
161161
);
162162
})
163163
.then(done, done);

0 commit comments

Comments
 (0)