Skip to content

Commit

Permalink
VSCODE-231: Catch completion error when not connected (#251)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alenakhineika authored Feb 5, 2021
1 parent 86b7335 commit 34eca98
Show file tree
Hide file tree
Showing 36 changed files with 1,455 additions and 1,078 deletions.
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ steps:
displayName: 'Set extension_version variable from package.json version'
- bash: |
vsixFilename=./mongodb-vscode-$(extension_version).vsix
maxsize=5000000 # 5MB
maxsize=6000000 # 6MB
filesize=$(stat -c%s "$vsixFilename")
echo "Size of $vsixFilename = $filesize bytes."
if (( filesize > maxsize )); then
echo "File is over 5MB."
echo "File is over 6MB."
exit 1
fi
displayName: 'Check .vsix filesize'
Expand Down
1,299 changes: 808 additions & 491 deletions package-lock.json

Large diffs are not rendered by default.

53 changes: 27 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -850,27 +850,27 @@
}
},
"dependencies": {
"@babel/parser": "^7.9.6",
"@babel/traverse": "^7.9.6",
"@fortawesome/fontawesome-svg-core": "^1.2.28",
"@fortawesome/free-solid-svg-icons": "^5.13.0",
"@fortawesome/react-fontawesome": "^0.1.9",
"@iconify-icons/codicon": "^1.0.6",
"@babel/parser": "^7.12.11",
"@babel/traverse": "^7.12.12",
"@fortawesome/fontawesome-svg-core": "^1.2.34",
"@fortawesome/free-solid-svg-icons": "^5.15.2",
"@fortawesome/react-fontawesome": "^0.1.14",
"@iconify-icons/codicon": "^1.1.5",
"@iconify/react": "^1.1.3",
"@leafygreen-ui/toggle": "3.0.1",
"@mongosh/browser-runtime-electron": "^0.5.2",
"@mongosh/service-provider-server": "^0.5.2",
"@mongosh/shell-api": "^0.5.2",
"analytics-node": "^3.4.0-beta.1",
"@mongosh/browser-runtime-electron": "^0.6.1",
"@mongosh/service-provider-server": "^0.6.1",
"@mongosh/shell-api": "^0.6.1",
"analytics-node": "^3.5.0",
"bson": "^4.2.0",
"classnames": "^2.2.6",
"debug": "^4.1.1",
"dotenv": "^8.2.0",
"micromatch": "^4.0.2",
"mongodb": "^3.6.3",
"mongodb-cloud-info": "^1.1.2",
"mongodb-connection-model": "^18.1.0",
"mongodb-data-service": "^18.1.0",
"mongodb-connection-model": "^19.0.2",
"mongodb-data-service": "^19.0.0",
"mongodb-ns": "^2.2.0",
"mongodb-schema": "^8.2.5",
"numeral": "^2.0.6",
Expand All @@ -879,11 +879,11 @@
"react-redux": "^7.2.0",
"redux": "^4.0.5",
"ts-log": "^2.1.4",
"uuid": "^8.0.2",
"vscode-languageclient": "^6.1.3",
"uuid": "^8.3.2",
"vscode-languageclient": "^6.1.4",
"vscode-languageserver": "^6.1.1",
"vscode-languageserver-textdocument": "^1.0.1",
"ws": "^7.2.3"
"ws": "^7.4.2"
},
"devDependencies": {
"@types/analytics-node": "^3.1.4",
Expand All @@ -896,14 +896,15 @@
"@types/glob": "^7.1.3",
"@types/jest": "^26.0.20",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.20",
"@types/node": "^14.14.22",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/sinon": "^9.0.10",
"@types/uuid": "^8.3.0",
"@types/vscode": "^1.49.0",
"@types/ws": "^7.4.0",
"@typescript-eslint/eslint-plugin": "^4.13.0",
"@typescript-eslint/parser": "^4.13.0",
"@typescript-eslint/eslint-plugin": "^4.14.2",
"@typescript-eslint/parser": "^4.14.2",
"autoprefixer": "^9.7.5",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
Expand All @@ -914,38 +915,38 @@
"depcheck": "^1.3.1",
"download": "^8.0.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.5",
"enzyme-adapter-react-16": "^1.15.6",
"eslint": "^6.8.0",
"eslint-config-mongodb-js": "^5.0.3",
"eslint-plugin-mocha": "^8.0.0",
"glob": "^7.1.6",
"jest": "^26.5.2",
"jest-junit": "^12.0.0",
"jest-transform-stub": "^2.0.0",
"less": "^3.11.1",
"less": "^3.13.1",
"less-loader": "^5.0.0",
"meow": "^6.0.1",
"mkdirp": "^1.0.4",
"mocha": "^8.2.1",
"mocha-junit-reporter": "^2.0.0",
"mocha-multi": "^1.1.3",
"mongodb-ace-autocompleter": "^0.4.14",
"mongodb-runner": "^4.8.0",
"mongodb-runner": "^4.8.1",
"node-loader": "^0.6.0",
"npm-run-all": "^4.1.5",
"ora": "^4.0.3",
"postcss-loader": "^3.0.0",
"pre-commit": "^1.2.2",
"sinon": "^9.2.3",
"sinon": "^9.2.4",
"sinon-chai": "^3.5.0",
"style-loader": "^1.1.3",
"ts-jest": "^26.4.4",
"ts-jest": "^26.5.0",
"ts-loader": "^8.0.14",
"ts-node": "^9.1.1",
"typescript": "^4.1.3",
"vsce": "^1.83.0",
"vscode-test": "^1.4.1",
"webpack": "^4.42.0",
"vsce": "^1.85.0",
"vscode-test": "^1.5.0",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.11",
"xvfb-maybe": "^0.2.1"
},
Expand Down
38 changes: 19 additions & 19 deletions src/connectionController.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { v4 as uuidv4 } from 'uuid';
import * as vscode from 'vscode';
import { v4 as uuidv4 } from 'uuid';
import Connection from 'mongodb-connection-model/lib/model';
import DataService from 'mongodb-data-service';
import { EventEmitter } from 'events';

import { ConnectionModelType } from './connectionModelType';
import { DataServiceType } from './dataServiceType';
import { CONNECTION_STATUS } from './views/webview-app/extension-app-message-constants';
import { ConnectionModel } from './types/connectionModelType';
import { createLogger } from './logging';
import { DataServiceType } from './types/dataServiceType';
import { ext } from './extensionConstants';
import { SavedConnection, StorageScope } from './storage/storageController';
import SSH_TUNNEL_TYPES from './views/webview-app/connection-model/constants/ssh-tunnel-types';
import { StatusView } from './views';
import { EventEmitter } from 'events';
import { StorageController, StorageVariables } from './storage';
import { SavedConnection, StorageScope } from './storage/storageController';
import TelemetryService from './telemetry/telemetryService';
import { ext } from './extensionConstants';
import { CONNECTION_STATUS } from './views/webview-app/extension-app-message-constants';
import SSH_TUNNEL_TYPES from './views/webview-app/connection-model/constants/ssh-tunnel-types';

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

export type SavedConnectionInformation = {
connectionModel: ConnectionModelType;
connectionModel: ConnectionModel;
};

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

private readonly _serviceName = 'mdb.vscode.savedConnections';
_activeDataService: null | DataServiceType = null;
_activeConnectionModel: null | ConnectionModelType = null;
_activeConnectionModel: null | ConnectionModel = null;
private _currentConnectionId: null | string = null;

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

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

return connectionModel;
};

public getConnectionNameFromConnectionModel = (
connectionModel: ConnectionModelType
connectionModel: ConnectionModel
): string => {
const { sshTunnelOptions } = connectionModel.getAttributes({
derived: true
Expand Down Expand Up @@ -300,7 +300,7 @@ export default class ConnectionController {
};

public saveNewConnectionAndConnect = async (
connectionModel: ConnectionModelType,
connectionModel: ConnectionModel,
connectionType: ConnectionTypes
): Promise<ConnectionAttemptResult> => {
const connectionId = uuidv4();
Expand Down Expand Up @@ -340,7 +340,7 @@ export default class ConnectionController {

public connect = async (
connectionId: string,
connectionModel: ConnectionModelType,
connectionModel: ConnectionModel,
connectionType: ConnectionTypes
): Promise<ConnectionAttemptResult> => {
log.info(
Expand Down Expand Up @@ -424,7 +424,7 @@ export default class ConnectionController {

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

try {
const savedConnectionModel = this._connections[connectionId]
Expand Down Expand Up @@ -731,7 +731,7 @@ export default class ConnectionController {
return this._activeDataService;
}

public getActiveConnectionModel(): null | ConnectionModelType {
public getActiveConnectionModel(): null | ConnectionModel {
return this._activeConnectionModel;
}

Expand Down
26 changes: 0 additions & 26 deletions src/connectionModelType.ts

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion src/editors/collectionDocumentsOperationsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class CollectionDocumentsOperationsStore {
operations: { [key: string]: CollectionDocumentsOperation } = {};

createNewOperation(): string {
const operationId = uuidv4() as string;
const operationId = uuidv4();

const initialDocumentsLimit = vscode.workspace
.getConfiguration('mdb')
Expand Down
29 changes: 15 additions & 14 deletions src/editors/editDocumentCodeLensProvider.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import * as vscode from 'vscode';
import EXTENSION_COMMANDS from '../commands';
import type { OutputItem, ResultCodeLensInfo } from '../utils/types';
import ConnectionController from '../connectionController';
import { DocumentSource } from '../utils/documentSource';
import { EJSON } from 'bson';

import ConnectionController from '../connectionController';
import { DocumentSource } from '../documentSource';
import type { EditDocumentInfo } from '../types/editDocumentInfoType';
import EXTENSION_COMMANDS from '../commands';
import { PLAYGROUND_RESULT_URI } from './playgroundResultProvider';
import type { PlaygroundResult } from '../types/playgroundType';

export default class EditDocumentCodeLensProvider
implements vscode.CodeLensProvider {
_onDidChangeCodeLenses: vscode.EventEmitter<void> = new vscode.EventEmitter<void>();
_codeLenses: vscode.CodeLens[] = [];
_codeLensesInfo: { [name: string]: ResultCodeLensInfo[] } | {};
_codeLensesInfo: { [name: string]: EditDocumentInfo[] } | {} = {};
_connectionController: ConnectionController;

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

constructor(connectionController: ConnectionController) {
this._connectionController = connectionController;
this._codeLensesInfo = {};

vscode.workspace.onDidChangeConfiguration(() => {
this._onDidChangeCodeLenses.fire();
Expand All @@ -30,7 +31,7 @@ implements vscode.CodeLensProvider {
namespace: string | null,
uri: vscode.Uri
}) {
let resultCodeLensesInfo: ResultCodeLensInfo[] = [];
let resultCodeLensesInfo: EditDocumentInfo[] = [];

resultCodeLensesInfo = this._updateCodeLensesForCursor({
...data,
Expand All @@ -40,9 +41,9 @@ implements vscode.CodeLensProvider {
this._codeLensesInfo[data.uri.toString()] = resultCodeLensesInfo;
}

updateCodeLensesForPlayground(playgroundResult: OutputItem) {
updateCodeLensesForPlayground(playgroundResult: PlaygroundResult) {
const source = DocumentSource.DOCUMENT_SOURCE_PLAYGROUND;
let resultCodeLensesInfo: ResultCodeLensInfo[] = [];
let resultCodeLensesInfo: EditDocumentInfo[] = [];

if (!playgroundResult || !playgroundResult.content) {
this._codeLensesInfo[PLAYGROUND_RESULT_URI.toString()] = [];
Expand All @@ -68,8 +69,8 @@ implements vscode.CodeLensProvider {
content: any,
namespace: string | null,
source: DocumentSource
}): ResultCodeLensInfo[] {
const resultCodeLensesInfo: ResultCodeLensInfo[] = [];
}): EditDocumentInfo[] {
const resultCodeLensesInfo: EditDocumentInfo[] = [];

if (Array.isArray(data.content)) {
const connectionId = this._connectionController.getActiveConnectionId();
Expand Down Expand Up @@ -106,9 +107,9 @@ implements vscode.CodeLensProvider {
content: any,
namespace: string | null,
source: DocumentSource
}): ResultCodeLensInfo[] {
}): EditDocumentInfo[] {
const { content, namespace, source } = data;
const resultCodeLensesInfo: ResultCodeLensInfo[] = [];
const resultCodeLensesInfo: EditDocumentInfo[] = [];

if (content._id && namespace) {
const connectionId = this._connectionController.getActiveConnectionId();
Expand Down Expand Up @@ -139,7 +140,7 @@ implements vscode.CodeLensProvider {
const command: {
title: string;
command: EXTENSION_COMMANDS;
arguments: ResultCodeLensInfo[];
arguments: EditDocumentInfo[];
} = {
title: 'Edit Document',
command: EXTENSION_COMMANDS.MDB_OPEN_MONGODB_DOCUMENT_FROM_CODE_LENS,
Expand Down
Loading

0 comments on commit 34eca98

Please sign in to comment.