From dc4f4d0527f2419bbb8d199859607911f8614c35 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Tue, 15 Sep 2020 12:32:22 -0700 Subject: [PATCH] Fix linter issues (#39) --- src/client/activation/jedi.ts | 1 - .../migrateDataScienceSettingsService.ts | 31 +-- src/client/activation/serviceRegistry.ts | 7 +- .../common/installer/productInstaller.ts | 9 +- .../jupyter/kernels/kernelService.ts | 5 +- src/client/extensionActivation.ts | 4 - src/client/providers/importSortProvider.ts | 2 - src/client/providers/types.ts | 1 - .../pythonExecutionFactory.unit.test.ts | 2 + .../datascience/errorHandler.unit.test.ts | 194 +++++++++--------- 10 files changed, 127 insertions(+), 129 deletions(-) diff --git a/src/client/activation/jedi.ts b/src/client/activation/jedi.ts index c8db33c1322..717a525a06a 100644 --- a/src/client/activation/jedi.ts +++ b/src/client/activation/jedi.ts @@ -80,7 +80,6 @@ export class JediExtensionActivator implements ILanguageServerActivator { this.objectDefinitionProvider = new PythonObjectDefinitionProvider(jediFactory); this.symbolProvider = new JediSymbolProvider(serviceContainer, jediFactory); this.signatureProvider = new PythonSignatureProvider(jediFactory); - } public deactivate() { diff --git a/src/client/activation/migrateDataScienceSettingsService.ts b/src/client/activation/migrateDataScienceSettingsService.ts index 0db3dd87ba7..00079331c55 100644 --- a/src/client/activation/migrateDataScienceSettingsService.ts +++ b/src/client/activation/migrateDataScienceSettingsService.ts @@ -3,15 +3,15 @@ 'use strict'; -import * as path from 'path'; import { inject, injectable } from 'inversify'; +import * as path from 'path'; import { IApplicationEnvironment, IWorkspaceService } from '../common/application/types'; import { traceError } from '../common/logger'; import { Resource } from '../common/types'; import { swallowExceptions } from '../common/utils/decorators'; +import { IDataScienceFileSystem } from '../datascience/types'; import { traceDecorators } from '../logging'; import { IExtensionActivationService } from './types'; -import { IDataScienceFileSystem } from '../datascience/types'; @injectable() export class MigrateDataScienceSettingsService implements IExtensionActivationService { @@ -19,15 +19,29 @@ export class MigrateDataScienceSettingsService implements IExtensionActivationSe @inject(IDataScienceFileSystem) private readonly fs: IDataScienceFileSystem, @inject(IApplicationEnvironment) private readonly application: IApplicationEnvironment, @inject(IWorkspaceService) private readonly workspace: IWorkspaceService - ) { } + ) {} + public async activate(resource: Resource): Promise { this.updateSettings(resource).ignoreErrors(); } + + @swallowExceptions('Failed to update settings.json') + public async fixSettingInFile(filePath: string): Promise { + let fileContents = await this.fs.readLocalFile(filePath); + fileContents = fileContents.replace( + /"python\.dataScience\.(.*?)":/g, + (_match, capture) => `"jupyter.${capture}":` + ); + await this.fs.writeLocalFile(filePath, fileContents); + return fileContents; + } + @traceDecorators.error('Failed to update test settings') private async updateSettings(resource: Resource): Promise { const filesToBeFixed = await this.getFilesToBeFixed(resource); await Promise.all(filesToBeFixed.map((file) => this.fixSettingInFile(file))); } + private getSettingsFiles(resource: Resource): string[] { const settingsFiles: string[] = []; if (this.application.userSettingsFile) { @@ -39,6 +53,7 @@ export class MigrateDataScienceSettingsService implements IExtensionActivationSe } return settingsFiles; } + private async getFilesToBeFixed(resource: Resource): Promise { const files = this.getSettingsFiles(resource); const result = await Promise.all( @@ -49,16 +64,6 @@ export class MigrateDataScienceSettingsService implements IExtensionActivationSe ); return result.filter((item) => item.needsFixing).map((item) => item.file); } - @swallowExceptions('Failed to update settings.json') - public async fixSettingInFile(filePath: string): Promise { - let fileContents = await this.fs.readLocalFile(filePath); - fileContents = fileContents.replace( - /"python\.dataScience\.(.*?)":/g, - (_match, capture) => `"jupyter.${capture}":` - ); - await this.fs.writeLocalFile(filePath, fileContents); - return fileContents; - } private async doesFileNeedToBeFixed(filePath: string): Promise { try { diff --git a/src/client/activation/serviceRegistry.ts b/src/client/activation/serviceRegistry.ts index 07e77bbb836..93889852aeb 100644 --- a/src/client/activation/serviceRegistry.ts +++ b/src/client/activation/serviceRegistry.ts @@ -41,6 +41,7 @@ import { DotNetLanguageServerProxy } from './languageServer/languageServerProxy' import { DotNetLanguageServerManager } from './languageServer/manager'; import { LanguageServerOutputChannel } from './languageServer/outputChannel'; import { PlatformData } from './languageServer/platformData'; +import { MigrateDataScienceSettingsService } from './migrateDataScienceSettingsService'; import { NodeLanguageServerActivator } from './node/activator'; import { NodeLanguageServerAnalysisOptions } from './node/analysisOptions'; import { NodeLanguageClientFactory } from './node/languageClientFactory'; @@ -74,7 +75,6 @@ import { IPlatformData, LanguageServerType } from './types'; -import { MigrateDataScienceSettingsService } from './migrateDataScienceSettingsService'; // tslint:disable-next-line: max-func-body-length export function registerTypes(serviceManager: IServiceManager, languageServerType: LanguageServerType) { @@ -82,7 +82,10 @@ export function registerTypes(serviceManager: IServiceManager, languageServerTyp serviceManager.addBinding(ILanguageServerCache, IExtensionActivationService); serviceManager.addSingleton(ILanguageServerExtension, LanguageServerExtension); serviceManager.add(IExtensionActivationManager, ExtensionActivationManager); - serviceManager.addSingleton(IExtensionActivationService, MigrateDataScienceSettingsService); + serviceManager.addSingleton( + IExtensionActivationService, + MigrateDataScienceSettingsService + ); serviceManager.addSingleton( IPythonExtensionBanner, diff --git a/src/client/common/installer/productInstaller.ts b/src/client/common/installer/productInstaller.ts index 286271f5803..8919ed27379 100644 --- a/src/client/common/installer/productInstaller.ts +++ b/src/client/common/installer/productInstaller.ts @@ -69,12 +69,11 @@ export abstract class BaseInstaller { } public async install( - _product: Product, - _resource?: InterpreterUri, - _cancel?: CancellationToken + product: Product, + resource?: InterpreterUri, + cancel?: CancellationToken ): Promise { - // TODO: - return InstallerResponse.Ignore; + return this.serviceContainer.get(IPythonInstaller).install(product, resource, cancel); } public async isInstalled(product: Product, resource?: InterpreterUri): Promise { diff --git a/src/client/datascience/jupyter/kernels/kernelService.ts b/src/client/datascience/jupyter/kernels/kernelService.ts index b55c853184a..f3a8255c509 100644 --- a/src/client/datascience/jupyter/kernels/kernelService.ts +++ b/src/client/datascience/jupyter/kernels/kernelService.ts @@ -51,10 +51,7 @@ const NamedRegexp = require('named-js-regexp') as typeof import('named-js-regexp */ function isInterpreter(item: nbformat.IKernelspecMetadata | PythonEnvironment): item is PythonEnvironment { // Interpreters will not have a `display_name` property, but have `path` and `type` properties. - return ( - !!(item as PythonEnvironment).path && - !(item as nbformat.IKernelspecMetadata).display_name - ); + return !!(item as PythonEnvironment).path && !(item as nbformat.IKernelspecMetadata).display_name; } /** diff --git a/src/client/extensionActivation.ts b/src/client/extensionActivation.ts index b5c81b1a2f0..68b93a46782 100644 --- a/src/client/extensionActivation.ts +++ b/src/client/extensionActivation.ts @@ -48,7 +48,6 @@ import { PythonCodeActionProvider } from './providers/codeActionProvider/pythonC import { PythonFormattingEditProvider } from './providers/formatProvider'; import { registerTypes as providersRegisterTypes } from './providers/serviceRegistry'; import { activateSimplePythonRefactorProvider } from './providers/simpleRefactorProvider'; -import { ISortImportsEditingProvider } from './providers/types'; import { setExtensionInstallTelemetryProperties } from './telemetry/extensionInstallTelemetry'; import { registerTypes as commonRegisterTerminalTypes } from './terminals/serviceRegistry'; @@ -147,9 +146,6 @@ async function activateLegacy( activateSimplePythonRefactorProvider(serviceContainer); - const sortImports = serviceContainer.get(ISortImportsEditingProvider); - sortImports.registerCommands(); - // Activate data science features const dataScience = serviceManager.get(IDataScience); dataScience.activate().ignoreErrors(); diff --git a/src/client/providers/importSortProvider.ts b/src/client/providers/importSortProvider.ts index 0fc61ba7ffc..70001bcdf6e 100644 --- a/src/client/providers/importSortProvider.ts +++ b/src/client/providers/importSortProvider.ts @@ -84,8 +84,6 @@ export class SortImportsEditingProvider implements ISortImportsEditingProvider { : undefined; } - public registerCommands() {} - public async sortImports(uri?: Uri): Promise { if (!uri) { const activeEditor = this.documentManager.activeTextEditor; diff --git a/src/client/providers/types.ts b/src/client/providers/types.ts index f2d1bc6eea3..f47f90598ee 100644 --- a/src/client/providers/types.ts +++ b/src/client/providers/types.ts @@ -9,5 +9,4 @@ export const ISortImportsEditingProvider = Symbol('ISortImportsEditingProvider') export interface ISortImportsEditingProvider { provideDocumentSortImportsEdits(uri: Uri, token?: CancellationToken): Promise; sortImports(uri?: Uri): Promise; - registerCommands(): void; } diff --git a/src/test/common/process/pythonExecutionFactory.unit.test.ts b/src/test/common/process/pythonExecutionFactory.unit.test.ts index fa9fed47a80..0c388df61a4 100644 --- a/src/test/common/process/pythonExecutionFactory.unit.test.ts +++ b/src/test/common/process/pythonExecutionFactory.unit.test.ts @@ -84,6 +84,8 @@ suite('Process - PythonExecutionFactory', () => { setup(() => { bufferDecoder = mock(BufferDecoder); processFactory = mock(ProcessServiceFactory); + activationHelper = mock(); + windowsStoreInterpreter = mock(); configService = mock(ConfigurationService); processLogger = mock(ProcessLogger); platformService = mock(); diff --git a/src/test/datascience/errorHandler.unit.test.ts b/src/test/datascience/errorHandler.unit.test.ts index 68ec15f59bf..2666dfd63f8 100644 --- a/src/test/datascience/errorHandler.unit.test.ts +++ b/src/test/datascience/errorHandler.unit.test.ts @@ -1,111 +1,111 @@ -// // Copyright (c) Microsoft Corporation. All rights reserved. -// // Licensed under the MIT License. -// 'use strict'; -// import { anything, instance, mock, verify, when } from 'ts-mockito'; -// import * as typemoq from 'typemoq'; -// import { IApplicationShell } from '../../client/common/application/types'; -// import * as localize from '../../client/common/utils/localize'; -// import { DataScienceErrorHandler } from '../../client/datascience/errorHandler/errorHandler'; -// import { JupyterInstallError } from '../../client/datascience/jupyter/jupyterInstallError'; -// import { JupyterSelfCertsError } from '../../client/datascience/jupyter/jupyterSelfCertsError'; -// import { JupyterZMQBinariesNotFoundError } from '../../client/datascience/jupyter/jupyterZMQBinariesNotFoundError'; -// import { JupyterServerSelector } from '../../client/datascience/jupyter/serverSelector'; -// import { IJupyterInterpreterDependencyManager } from '../../client/datascience/types'; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +'use strict'; +import { anything, instance, mock, verify, when } from 'ts-mockito'; +import * as typemoq from 'typemoq'; +import { IApplicationShell } from '../../client/common/application/types'; +import * as localize from '../../client/common/utils/localize'; +import { DataScienceErrorHandler } from '../../client/datascience/errorHandler/errorHandler'; +import { JupyterInstallError } from '../../client/datascience/jupyter/jupyterInstallError'; +import { JupyterSelfCertsError } from '../../client/datascience/jupyter/jupyterSelfCertsError'; +import { JupyterZMQBinariesNotFoundError } from '../../client/datascience/jupyter/jupyterZMQBinariesNotFoundError'; +import { JupyterServerSelector } from '../../client/datascience/jupyter/serverSelector'; +import { IJupyterInterpreterDependencyManager } from '../../client/datascience/types'; -// suite('DataScience Error Handler Unit Tests', () => { -// let applicationShell: typemoq.IMock; -// let dataScienceErrorHandler: DataScienceErrorHandler; -// let dependencyManager: IJupyterInterpreterDependencyManager; -// const serverSelector = mock(JupyterServerSelector); +suite('DataScience Error Handler Unit Tests', () => { + let applicationShell: typemoq.IMock; + let dataScienceErrorHandler: DataScienceErrorHandler; + let dependencyManager: IJupyterInterpreterDependencyManager; + const serverSelector = mock(JupyterServerSelector); -// setup(() => { -// applicationShell = typemoq.Mock.ofType(); -// dependencyManager = mock(); -// when(dependencyManager.installMissingDependencies(anything())).thenResolve(); -// dataScienceErrorHandler = new DataScienceErrorHandler( -// applicationShell.object, -// instance(dependencyManager), -// instance(serverSelector) -// ); -// }); -// const message = 'Test error message.'; + setup(() => { + applicationShell = typemoq.Mock.ofType(); + dependencyManager = mock(); + when(dependencyManager.installMissingDependencies(anything())).thenResolve(); + dataScienceErrorHandler = new DataScienceErrorHandler( + applicationShell.object, + instance(dependencyManager), + instance(serverSelector) + ); + }); + const message = 'Test error message.'; -// test('Default error', async () => { -// applicationShell -// .setup((app) => app.showErrorMessage(typemoq.It.isAny())) -// .returns(() => Promise.resolve(message)) -// .verifiable(typemoq.Times.once()); + test('Default error', async () => { + applicationShell + .setup((app) => app.showErrorMessage(typemoq.It.isAny())) + .returns(() => Promise.resolve(message)) + .verifiable(typemoq.Times.once()); -// const err = new Error(message); -// await dataScienceErrorHandler.handleError(err); + const err = new Error(message); + await dataScienceErrorHandler.handleError(err); -// applicationShell.verifyAll(); -// }); + applicationShell.verifyAll(); + }); -// test('Jupyter Self Certificates Error', async () => { -// applicationShell -// .setup((app) => app.showErrorMessage(typemoq.It.isAny())) -// .returns(() => Promise.resolve(message)) -// .verifiable(typemoq.Times.never()); + test('Jupyter Self Certificates Error', async () => { + applicationShell + .setup((app) => app.showErrorMessage(typemoq.It.isAny())) + .returns(() => Promise.resolve(message)) + .verifiable(typemoq.Times.never()); -// const err = new JupyterSelfCertsError(message); -// await dataScienceErrorHandler.handleError(err); + const err = new JupyterSelfCertsError(message); + await dataScienceErrorHandler.handleError(err); -// applicationShell.verifyAll(); -// }); + applicationShell.verifyAll(); + }); -// test('Jupyter Install Error', async () => { -// applicationShell -// .setup((app) => -// app.showInformationMessage( -// typemoq.It.isAny(), -// typemoq.It.isValue(localize.DataScience.jupyterInstall()), -// typemoq.It.isValue(localize.DataScience.notebookCheckForImportNo()), -// typemoq.It.isAny() -// ) -// ) -// .returns(() => Promise.resolve(localize.DataScience.jupyterInstall())) -// .verifiable(typemoq.Times.once()); + test('Jupyter Install Error', async () => { + applicationShell + .setup((app) => + app.showInformationMessage( + typemoq.It.isAny(), + typemoq.It.isValue(localize.DataScience.jupyterInstall()), + typemoq.It.isValue(localize.DataScience.notebookCheckForImportNo()), + typemoq.It.isAny() + ) + ) + .returns(() => Promise.resolve(localize.DataScience.jupyterInstall())) + .verifiable(typemoq.Times.once()); -// const installers: IModuleInstaller[] = [ -// { -// name: 'Pip', -// displayName: 'Pip', -// priority: 0, -// isSupported: () => Promise.resolve(true), -// installModule: () => Promise.resolve() -// }, -// { -// name: 'Conda', -// displayName: 'Conda', -// priority: 0, -// isSupported: () => Promise.resolve(true), -// installModule: () => Promise.resolve() -// } -// ]; + // const installers: IModuleInstaller[] = [ + // { + // name: 'Pip', + // displayName: 'Pip', + // priority: 0, + // isSupported: () => Promise.resolve(true), + // installModule: () => Promise.resolve() + // }, + // { + // name: 'Conda', + // displayName: 'Conda', + // priority: 0, + // isSupported: () => Promise.resolve(true), + // installModule: () => Promise.resolve() + // } + // ]; -// channels -// .setup((ch) => ch.getInstallationChannels()) -// .returns(() => Promise.resolve(installers)) -// .verifiable(typemoq.Times.once()); + // channels + // .setup((ch) => ch.getInstallationChannels()) + // .returns(() => Promise.resolve(installers)) + // .verifiable(typemoq.Times.once()); -// const err = new JupyterInstallError(message, 'test.com'); -// await dataScienceErrorHandler.handleError(err); + const err = new JupyterInstallError(message, 'test.com'); + await dataScienceErrorHandler.handleError(err); -// verify(dependencyManager.installMissingDependencies(err)).once(); -// }); + verify(dependencyManager.installMissingDependencies(err)).once(); + }); -// test('ZMQ Install Error', async () => { -// applicationShell -// .setup((app) => -// app.showErrorMessage(typemoq.It.isAny(), typemoq.It.isValue(localize.DataScience.selectNewServer())) -// ) -// .returns(() => Promise.resolve(localize.DataScience.selectNewServer())) -// .verifiable(typemoq.Times.once()); -// when(serverSelector.selectJupyterURI(anything())).thenCall(() => Promise.resolve()); -// const err = new JupyterZMQBinariesNotFoundError('Not found'); -// await dataScienceErrorHandler.handleError(err); -// verify(serverSelector.selectJupyterURI(anything())).once(); -// applicationShell.verifyAll(); -// }); -// }); + test('ZMQ Install Error', async () => { + applicationShell + .setup((app) => + app.showErrorMessage(typemoq.It.isAny(), typemoq.It.isValue(localize.DataScience.selectNewServer())) + ) + .returns(() => Promise.resolve(localize.DataScience.selectNewServer())) + .verifiable(typemoq.Times.once()); + when(serverSelector.selectJupyterURI(anything())).thenCall(() => Promise.resolve()); + const err = new JupyterZMQBinariesNotFoundError('Not found'); + await dataScienceErrorHandler.handleError(err); + verify(serverSelector.selectJupyterURI(anything())).once(); + applicationShell.verifyAll(); + }); +});