Skip to content

Commit 34eca98

Browse files
VSCODE-231: Catch completion error when not connected (#251)
* fix: catch completion error when user is not connected (VSCODE-231) * refactor: clean up types and returning values * test: use a new connection instance for each suite * build: increase allowed vsix size to 6mb * chore: bump mongosh to 0.6.1 * refactor: clean up type names and move all types to their separate folder * build: use lowercase file name for the connection model type
1 parent 86b7335 commit 34eca98

36 files changed

+1455
-1078
lines changed

azure-pipelines.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ steps:
7373
displayName: 'Set extension_version variable from package.json version'
7474
- bash: |
7575
vsixFilename=./mongodb-vscode-$(extension_version).vsix
76-
maxsize=5000000 # 5MB
76+
maxsize=6000000 # 6MB
7777
filesize=$(stat -c%s "$vsixFilename")
7878
7979
echo "Size of $vsixFilename = $filesize bytes."
8080
8181
if (( filesize > maxsize )); then
82-
echo "File is over 5MB."
82+
echo "File is over 6MB."
8383
exit 1
8484
fi
8585
displayName: 'Check .vsix filesize'

package-lock.json

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

package.json

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -850,27 +850,27 @@
850850
}
851851
},
852852
"dependencies": {
853-
"@babel/parser": "^7.9.6",
854-
"@babel/traverse": "^7.9.6",
855-
"@fortawesome/fontawesome-svg-core": "^1.2.28",
856-
"@fortawesome/free-solid-svg-icons": "^5.13.0",
857-
"@fortawesome/react-fontawesome": "^0.1.9",
858-
"@iconify-icons/codicon": "^1.0.6",
853+
"@babel/parser": "^7.12.11",
854+
"@babel/traverse": "^7.12.12",
855+
"@fortawesome/fontawesome-svg-core": "^1.2.34",
856+
"@fortawesome/free-solid-svg-icons": "^5.15.2",
857+
"@fortawesome/react-fontawesome": "^0.1.14",
858+
"@iconify-icons/codicon": "^1.1.5",
859859
"@iconify/react": "^1.1.3",
860860
"@leafygreen-ui/toggle": "3.0.1",
861-
"@mongosh/browser-runtime-electron": "^0.5.2",
862-
"@mongosh/service-provider-server": "^0.5.2",
863-
"@mongosh/shell-api": "^0.5.2",
864-
"analytics-node": "^3.4.0-beta.1",
861+
"@mongosh/browser-runtime-electron": "^0.6.1",
862+
"@mongosh/service-provider-server": "^0.6.1",
863+
"@mongosh/shell-api": "^0.6.1",
864+
"analytics-node": "^3.5.0",
865865
"bson": "^4.2.0",
866866
"classnames": "^2.2.6",
867867
"debug": "^4.1.1",
868868
"dotenv": "^8.2.0",
869869
"micromatch": "^4.0.2",
870870
"mongodb": "^3.6.3",
871871
"mongodb-cloud-info": "^1.1.2",
872-
"mongodb-connection-model": "^18.1.0",
873-
"mongodb-data-service": "^18.1.0",
872+
"mongodb-connection-model": "^19.0.2",
873+
"mongodb-data-service": "^19.0.0",
874874
"mongodb-ns": "^2.2.0",
875875
"mongodb-schema": "^8.2.5",
876876
"numeral": "^2.0.6",
@@ -879,11 +879,11 @@
879879
"react-redux": "^7.2.0",
880880
"redux": "^4.0.5",
881881
"ts-log": "^2.1.4",
882-
"uuid": "^8.0.2",
883-
"vscode-languageclient": "^6.1.3",
882+
"uuid": "^8.3.2",
883+
"vscode-languageclient": "^6.1.4",
884884
"vscode-languageserver": "^6.1.1",
885885
"vscode-languageserver-textdocument": "^1.0.1",
886-
"ws": "^7.2.3"
886+
"ws": "^7.4.2"
887887
},
888888
"devDependencies": {
889889
"@types/analytics-node": "^3.1.4",
@@ -896,14 +896,15 @@
896896
"@types/glob": "^7.1.3",
897897
"@types/jest": "^26.0.20",
898898
"@types/mocha": "^8.2.0",
899-
"@types/node": "^14.14.20",
899+
"@types/node": "^14.14.22",
900900
"@types/react": "^17.0.0",
901901
"@types/react-dom": "^17.0.0",
902902
"@types/sinon": "^9.0.10",
903+
"@types/uuid": "^8.3.0",
903904
"@types/vscode": "^1.49.0",
904905
"@types/ws": "^7.4.0",
905-
"@typescript-eslint/eslint-plugin": "^4.13.0",
906-
"@typescript-eslint/parser": "^4.13.0",
906+
"@typescript-eslint/eslint-plugin": "^4.14.2",
907+
"@typescript-eslint/parser": "^4.14.2",
907908
"autoprefixer": "^9.7.5",
908909
"chai": "^4.2.0",
909910
"chai-as-promised": "^7.1.1",
@@ -914,38 +915,38 @@
914915
"depcheck": "^1.3.1",
915916
"download": "^8.0.0",
916917
"enzyme": "^3.11.0",
917-
"enzyme-adapter-react-16": "^1.15.5",
918+
"enzyme-adapter-react-16": "^1.15.6",
918919
"eslint": "^6.8.0",
919920
"eslint-config-mongodb-js": "^5.0.3",
920921
"eslint-plugin-mocha": "^8.0.0",
921922
"glob": "^7.1.6",
922923
"jest": "^26.5.2",
923924
"jest-junit": "^12.0.0",
924925
"jest-transform-stub": "^2.0.0",
925-
"less": "^3.11.1",
926+
"less": "^3.13.1",
926927
"less-loader": "^5.0.0",
927928
"meow": "^6.0.1",
928929
"mkdirp": "^1.0.4",
929930
"mocha": "^8.2.1",
930931
"mocha-junit-reporter": "^2.0.0",
931932
"mocha-multi": "^1.1.3",
932933
"mongodb-ace-autocompleter": "^0.4.14",
933-
"mongodb-runner": "^4.8.0",
934+
"mongodb-runner": "^4.8.1",
934935
"node-loader": "^0.6.0",
935936
"npm-run-all": "^4.1.5",
936937
"ora": "^4.0.3",
937938
"postcss-loader": "^3.0.0",
938939
"pre-commit": "^1.2.2",
939-
"sinon": "^9.2.3",
940+
"sinon": "^9.2.4",
940941
"sinon-chai": "^3.5.0",
941942
"style-loader": "^1.1.3",
942-
"ts-jest": "^26.4.4",
943+
"ts-jest": "^26.5.0",
943944
"ts-loader": "^8.0.14",
944945
"ts-node": "^9.1.1",
945946
"typescript": "^4.1.3",
946-
"vsce": "^1.83.0",
947-
"vscode-test": "^1.4.1",
948-
"webpack": "^4.42.0",
947+
"vsce": "^1.85.0",
948+
"vscode-test": "^1.5.0",
949+
"webpack": "^4.46.0",
949950
"webpack-cli": "^3.3.11",
950951
"xvfb-maybe": "^0.2.1"
951952
},

src/connectionController.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { v4 as uuidv4 } from 'uuid';
21
import * as vscode from 'vscode';
2+
import { v4 as uuidv4 } from 'uuid';
33
import Connection from 'mongodb-connection-model/lib/model';
44
import DataService from 'mongodb-data-service';
5+
import { EventEmitter } from 'events';
56

6-
import { ConnectionModelType } from './connectionModelType';
7-
import { DataServiceType } from './dataServiceType';
7+
import { CONNECTION_STATUS } from './views/webview-app/extension-app-message-constants';
8+
import { ConnectionModel } from './types/connectionModelType';
89
import { createLogger } from './logging';
10+
import { DataServiceType } from './types/dataServiceType';
11+
import { ext } from './extensionConstants';
12+
import { SavedConnection, StorageScope } from './storage/storageController';
13+
import SSH_TUNNEL_TYPES from './views/webview-app/connection-model/constants/ssh-tunnel-types';
914
import { StatusView } from './views';
10-
import { EventEmitter } from 'events';
1115
import { StorageController, StorageVariables } from './storage';
12-
import { SavedConnection, StorageScope } from './storage/storageController';
1316
import TelemetryService from './telemetry/telemetryService';
14-
import { ext } from './extensionConstants';
15-
import { CONNECTION_STATUS } from './views/webview-app/extension-app-message-constants';
16-
import SSH_TUNNEL_TYPES from './views/webview-app/connection-model/constants/ssh-tunnel-types';
1717

1818
const { name, version } = require('../package.json');
1919
const log = createLogger('connection controller');
@@ -31,7 +31,7 @@ export enum ConnectionTypes {
3131
}
3232

3333
export type SavedConnectionInformation = {
34-
connectionModel: ConnectionModelType;
34+
connectionModel: ConnectionModel;
3535
};
3636

3737
// A loaded connection contains connection information.
@@ -57,7 +57,7 @@ export default class ConnectionController {
5757

5858
private readonly _serviceName = 'mdb.vscode.savedConnections';
5959
_activeDataService: null | DataServiceType = null;
60-
_activeConnectionModel: null | ConnectionModelType = null;
60+
_activeConnectionModel: null | ConnectionModel = null;
6161
private _currentConnectionId: null | string = null;
6262

6363
// When we are connecting to a server we save a connection version to
@@ -229,7 +229,7 @@ export default class ConnectionController {
229229
return new Promise((resolve, reject) => {
230230
Connection.from(
231231
connectionString,
232-
(error: Error | undefined, newConnectionModel: ConnectionModelType) => {
232+
(error: Error | undefined, newConnectionModel: ConnectionModel) => {
233233
if (error) {
234234
return reject(new Error(`Unable to create connection: ${error}`));
235235
}
@@ -257,19 +257,19 @@ export default class ConnectionController {
257257
}
258258

259259
public parseNewConnection = (
260-
newConnectionModel: ConnectionModelType
261-
): ConnectionModelType => {
260+
newConnectionModel: ConnectionModel
261+
): ConnectionModel => {
262262
// Here we re-parse the connection, as it can be loaded from storage or
263263
// passed by the connection model without the class methods.
264-
const connectionModel: ConnectionModelType = new Connection(
264+
const connectionModel: ConnectionModel = new Connection(
265265
newConnectionModel
266266
);
267267

268268
return connectionModel;
269269
};
270270

271271
public getConnectionNameFromConnectionModel = (
272-
connectionModel: ConnectionModelType
272+
connectionModel: ConnectionModel
273273
): string => {
274274
const { sshTunnelOptions } = connectionModel.getAttributes({
275275
derived: true
@@ -300,7 +300,7 @@ export default class ConnectionController {
300300
};
301301

302302
public saveNewConnectionAndConnect = async (
303-
connectionModel: ConnectionModelType,
303+
connectionModel: ConnectionModel,
304304
connectionType: ConnectionTypes
305305
): Promise<ConnectionAttemptResult> => {
306306
const connectionId = uuidv4();
@@ -340,7 +340,7 @@ export default class ConnectionController {
340340

341341
public connect = async (
342342
connectionId: string,
343-
connectionModel: ConnectionModelType,
343+
connectionModel: ConnectionModel,
344344
connectionType: ConnectionTypes
345345
): Promise<ConnectionAttemptResult> => {
346346
log.info(
@@ -424,7 +424,7 @@ export default class ConnectionController {
424424

425425
public connectWithConnectionId = (connectionId: string): Promise<boolean> => {
426426
if (this._connections[connectionId]) {
427-
let connectionModel: ConnectionModelType;
427+
let connectionModel: ConnectionModel;
428428

429429
try {
430430
const savedConnectionModel = this._connections[connectionId]
@@ -731,7 +731,7 @@ export default class ConnectionController {
731731
return this._activeDataService;
732732
}
733733

734-
public getActiveConnectionModel(): null | ConnectionModelType {
734+
public getActiveConnectionModel(): null | ConnectionModel {
735735
return this._activeConnectionModel;
736736
}
737737

src/connectionModelType.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/editors/collectionDocumentsOperationsStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default class CollectionDocumentsOperationsStore {
2020
operations: { [key: string]: CollectionDocumentsOperation } = {};
2121

2222
createNewOperation(): string {
23-
const operationId = uuidv4() as string;
23+
const operationId = uuidv4();
2424

2525
const initialDocumentsLimit = vscode.workspace
2626
.getConfiguration('mdb')

src/editors/editDocumentCodeLensProvider.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
import * as vscode from 'vscode';
2-
import EXTENSION_COMMANDS from '../commands';
3-
import type { OutputItem, ResultCodeLensInfo } from '../utils/types';
4-
import ConnectionController from '../connectionController';
5-
import { DocumentSource } from '../utils/documentSource';
62
import { EJSON } from 'bson';
3+
4+
import ConnectionController from '../connectionController';
5+
import { DocumentSource } from '../documentSource';
6+
import type { EditDocumentInfo } from '../types/editDocumentInfoType';
7+
import EXTENSION_COMMANDS from '../commands';
78
import { PLAYGROUND_RESULT_URI } from './playgroundResultProvider';
9+
import type { PlaygroundResult } from '../types/playgroundType';
810

911
export default class EditDocumentCodeLensProvider
1012
implements vscode.CodeLensProvider {
1113
_onDidChangeCodeLenses: vscode.EventEmitter<void> = new vscode.EventEmitter<void>();
1214
_codeLenses: vscode.CodeLens[] = [];
13-
_codeLensesInfo: { [name: string]: ResultCodeLensInfo[] } | {};
15+
_codeLensesInfo: { [name: string]: EditDocumentInfo[] } | {} = {};
1416
_connectionController: ConnectionController;
1517

1618
readonly onDidChangeCodeLenses: vscode.Event<void> = this
1719
._onDidChangeCodeLenses.event;
1820

1921
constructor(connectionController: ConnectionController) {
2022
this._connectionController = connectionController;
21-
this._codeLensesInfo = {};
2223

2324
vscode.workspace.onDidChangeConfiguration(() => {
2425
this._onDidChangeCodeLenses.fire();
@@ -30,7 +31,7 @@ implements vscode.CodeLensProvider {
3031
namespace: string | null,
3132
uri: vscode.Uri
3233
}) {
33-
let resultCodeLensesInfo: ResultCodeLensInfo[] = [];
34+
let resultCodeLensesInfo: EditDocumentInfo[] = [];
3435

3536
resultCodeLensesInfo = this._updateCodeLensesForCursor({
3637
...data,
@@ -40,9 +41,9 @@ implements vscode.CodeLensProvider {
4041
this._codeLensesInfo[data.uri.toString()] = resultCodeLensesInfo;
4142
}
4243

43-
updateCodeLensesForPlayground(playgroundResult: OutputItem) {
44+
updateCodeLensesForPlayground(playgroundResult: PlaygroundResult) {
4445
const source = DocumentSource.DOCUMENT_SOURCE_PLAYGROUND;
45-
let resultCodeLensesInfo: ResultCodeLensInfo[] = [];
46+
let resultCodeLensesInfo: EditDocumentInfo[] = [];
4647

4748
if (!playgroundResult || !playgroundResult.content) {
4849
this._codeLensesInfo[PLAYGROUND_RESULT_URI.toString()] = [];
@@ -68,8 +69,8 @@ implements vscode.CodeLensProvider {
6869
content: any,
6970
namespace: string | null,
7071
source: DocumentSource
71-
}): ResultCodeLensInfo[] {
72-
const resultCodeLensesInfo: ResultCodeLensInfo[] = [];
72+
}): EditDocumentInfo[] {
73+
const resultCodeLensesInfo: EditDocumentInfo[] = [];
7374

7475
if (Array.isArray(data.content)) {
7576
const connectionId = this._connectionController.getActiveConnectionId();
@@ -106,9 +107,9 @@ implements vscode.CodeLensProvider {
106107
content: any,
107108
namespace: string | null,
108109
source: DocumentSource
109-
}): ResultCodeLensInfo[] {
110+
}): EditDocumentInfo[] {
110111
const { content, namespace, source } = data;
111-
const resultCodeLensesInfo: ResultCodeLensInfo[] = [];
112+
const resultCodeLensesInfo: EditDocumentInfo[] = [];
112113

113114
if (content._id && namespace) {
114115
const connectionId = this._connectionController.getActiveConnectionId();
@@ -139,7 +140,7 @@ implements vscode.CodeLensProvider {
139140
const command: {
140141
title: string;
141142
command: EXTENSION_COMMANDS;
142-
arguments: ResultCodeLensInfo[];
143+
arguments: EditDocumentInfo[];
143144
} = {
144145
title: 'Edit Document',
145146
command: EXTENSION_COMMANDS.MDB_OPEN_MONGODB_DOCUMENT_FROM_CODE_LENS,

0 commit comments

Comments
 (0)