From 3ac9796a8cfcea7d3a95b078c196bbcbd00853e2 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Thu, 7 Jun 2018 09:32:38 -0700 Subject: [PATCH 1/2] Ensure resource is passed into isInstalled method --- .../common/installer/productInstaller.ts | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/client/common/installer/productInstaller.ts b/src/client/common/installer/productInstaller.ts index 8e3bde192995..fa8c72aae939 100644 --- a/src/client/common/installer/productInstaller.ts +++ b/src/client/common/installer/productInstaller.ts @@ -1,7 +1,7 @@ import { inject, injectable, named } from 'inversify'; import * as os from 'os'; import * as path from 'path'; -import * as vscode from 'vscode'; +import { OutputChannel, Uri } from 'vscode'; import '../../common/extensions'; import { IFormatterHelper } from '../../formatters/types'; import { IServiceContainer } from '../../ioc/types'; @@ -35,13 +35,13 @@ export abstract class BaseInstaller { protected configService: IConfigurationService; private readonly workspaceService: IWorkspaceService; - constructor(protected serviceContainer: IServiceContainer, protected outputChannel: vscode.OutputChannel) { + constructor(protected serviceContainer: IServiceContainer, protected outputChannel: OutputChannel) { this.appShell = serviceContainer.get(IApplicationShell); this.configService = serviceContainer.get(IConfigurationService); this.workspaceService = serviceContainer.get(IWorkspaceService); } - public promptToInstall(product: Product, resource?: vscode.Uri): Promise { + public promptToInstall(product: Product, resource?: Uri): Promise { // If this method gets called twice, while previous promise has not been resolved, then return that same promise. // E.g. previous promise is not resolved as a message has been displayed to the user, so no point displaying // another message. @@ -58,7 +58,7 @@ export abstract class BaseInstaller { return promise; } - public async install(product: Product, resource?: vscode.Uri): Promise { + public async install(product: Product, resource?: Uri): Promise { if (product === Product.unittest) { return InstallerResponse.Installed; } @@ -74,11 +74,11 @@ export abstract class BaseInstaller { await installer.installModule(moduleName, resource) .catch(logger.logError.bind(logger, `Error in installing the module '${moduleName}'`)); - return this.isInstalled(product) + return this.isInstalled(product, resource) .then(isInstalled => isInstalled ? InstallerResponse.Installed : InstallerResponse.Ignore); } - public async isInstalled(product: Product, resource?: vscode.Uri): Promise { + public async isInstalled(product: Product, resource?: Uri): Promise { if (product === Product.unittest) { return true; } @@ -102,18 +102,18 @@ export abstract class BaseInstaller { .catch(() => false); } } - protected abstract promptToInstallImplementation(product: Product, resource?: vscode.Uri): Promise; - protected getExecutableNameFromSettings(product: Product, resource?: vscode.Uri): string { + protected abstract promptToInstallImplementation(product: Product, resource?: Uri): Promise; + protected getExecutableNameFromSettings(product: Product, resource?: Uri): string { throw new Error('getExecutableNameFromSettings is not supported on this object'); } } export class CTagsInstaller extends BaseInstaller { - constructor(serviceContainer: IServiceContainer, outputChannel: vscode.OutputChannel) { + constructor(serviceContainer: IServiceContainer, outputChannel: OutputChannel) { super(serviceContainer, outputChannel); } - public async install(product: Product, resource?: vscode.Uri): Promise { + public async install(product: Product, resource?: Uri): Promise { if (this.serviceContainer.get(IPlatformService).isWindows) { this.outputChannel.appendLine('Install Universal Ctags Win32 to enable support for Workspace Symbols'); this.outputChannel.appendLine('Download the CTags binary from the Universal CTags site.'); @@ -129,19 +129,19 @@ export class CTagsInstaller extends BaseInstaller { } return InstallerResponse.Ignore; } - protected async promptToInstallImplementation(product: Product, resource?: vscode.Uri): Promise { + protected async promptToInstallImplementation(product: Product, resource?: Uri): Promise { const item = await this.appShell.showErrorMessage('Install CTags to enable Python workspace symbols?', 'Yes', 'No'); return item === 'Yes' ? this.install(product, resource) : InstallerResponse.Ignore; } - protected getExecutableNameFromSettings(product: Product, resource?: vscode.Uri): string { + protected getExecutableNameFromSettings(product: Product, resource?: Uri): string { const settings = this.configService.getSettings(resource); return settings.workspaceSymbols.ctagsPath; } } export class FormatterInstaller extends BaseInstaller { - protected async promptToInstallImplementation(product: Product, resource?: vscode.Uri): Promise { + protected async promptToInstallImplementation(product: Product, resource?: Uri): Promise { // Hard-coded on purpose because the UI won't necessarily work having // another formatter. const formatters = [Product.autopep8, Product.black, Product.yapf]; @@ -168,7 +168,7 @@ export class FormatterInstaller extends BaseInstaller { return InstallerResponse.Ignore; } - protected getExecutableNameFromSettings(product: Product, resource?: vscode.Uri): string { + protected getExecutableNameFromSettings(product: Product, resource?: Uri): string { const settings = this.configService.getSettings(resource); const formatHelper = this.serviceContainer.get(IFormatterHelper); const settingsPropNames = formatHelper.getSettingsPropertyNames(product); @@ -178,7 +178,7 @@ export class FormatterInstaller extends BaseInstaller { // tslint:disable-next-line:max-classes-per-file export class LinterInstaller extends BaseInstaller { - protected async promptToInstallImplementation(product: Product, resource?: vscode.Uri): Promise { + protected async promptToInstallImplementation(product: Product, resource?: Uri): Promise { const productName = ProductNames.get(product)!; const install = 'Install'; const disableAllLinting = 'Disable linting'; @@ -199,7 +199,7 @@ export class LinterInstaller extends BaseInstaller { } return InstallerResponse.Ignore; } - protected getExecutableNameFromSettings(product: Product, resource?: vscode.Uri): string { + protected getExecutableNameFromSettings(product: Product, resource?: Uri): string { const linterManager = this.serviceContainer.get(ILinterManager); return linterManager.getLinterInfo(product).pathName(resource); } @@ -207,13 +207,13 @@ export class LinterInstaller extends BaseInstaller { // tslint:disable-next-line:max-classes-per-file export class TestFrameworkInstaller extends BaseInstaller { - protected async promptToInstallImplementation(product: Product, resource?: vscode.Uri): Promise { + protected async promptToInstallImplementation(product: Product, resource?: Uri): Promise { const productName = ProductNames.get(product)!; const item = await this.appShell.showErrorMessage(`Test framework ${productName} is not installed. Install?`, 'Yes', 'No'); return item === 'Yes' ? this.install(product, resource) : InstallerResponse.Ignore; } - protected getExecutableNameFromSettings(product: Product, resource?: vscode.Uri): string { + protected getExecutableNameFromSettings(product: Product, resource?: Uri): string { const testHelper = this.serviceContainer.get(ITestsHelper); const settingsPropNames = testHelper.getSettingsPropertyNames(product); if (!settingsPropNames.pathName) { @@ -227,12 +227,12 @@ export class TestFrameworkInstaller extends BaseInstaller { // tslint:disable-next-line:max-classes-per-file export class RefactoringLibraryInstaller extends BaseInstaller { - protected async promptToInstallImplementation(product: Product, resource?: vscode.Uri): Promise { + protected async promptToInstallImplementation(product: Product, resource?: Uri): Promise { const productName = ProductNames.get(product)!; const item = await this.appShell.showErrorMessage(`Refactoring library ${productName} is not installed. Install?`, 'Yes', 'No'); return item === 'Yes' ? this.install(product, resource) : InstallerResponse.Ignore; } - protected getExecutableNameFromSettings(product: Product, resource?: vscode.Uri): string { + protected getExecutableNameFromSettings(product: Product, resource?: Uri): string { return translateProductToModule(product, ModuleNamePurpose.run); } } @@ -243,7 +243,7 @@ export class ProductInstaller implements IInstaller { private ProductTypes = new Map(); constructor(@inject(IServiceContainer) private serviceContainer: IServiceContainer, - @inject(IOutputChannel) @named(STANDARD_OUTPUT_CHANNEL) private outputChannel: vscode.OutputChannel) { + @inject(IOutputChannel) @named(STANDARD_OUTPUT_CHANNEL) private outputChannel: OutputChannel) { this.ProductTypes.set(Product.flake8, ProductType.Linter); this.ProductTypes.set(Product.mypy, ProductType.Linter); this.ProductTypes.set(Product.pep8, ProductType.Linter); @@ -263,13 +263,13 @@ export class ProductInstaller implements IInstaller { // tslint:disable-next-line:no-empty public dispose() { } - public async promptToInstall(product: Product, resource?: vscode.Uri): Promise { + public async promptToInstall(product: Product, resource?: Uri): Promise { return this.createInstaller(product).promptToInstall(product, resource); } - public async install(product: Product, resource?: vscode.Uri): Promise { + public async install(product: Product, resource?: Uri): Promise { return this.createInstaller(product).install(product, resource); } - public async isInstalled(product: Product, resource?: vscode.Uri): Promise { + public async isInstalled(product: Product, resource?: Uri): Promise { return this.createInstaller(product).isInstalled(product, resource); } public translateProductToModuleName(product: Product, purpose: ModuleNamePurpose): string { From 79d3da863df105f66b5abfed3f7c09df756c2215 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Thu, 7 Jun 2018 09:34:22 -0700 Subject: [PATCH 2/2] :memo: add news entry --- news/3 Code Health/1893.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/3 Code Health/1893.md diff --git a/news/3 Code Health/1893.md b/news/3 Code Health/1893.md new file mode 100644 index 000000000000..88cf91a7e1b0 --- /dev/null +++ b/news/3 Code Health/1893.md @@ -0,0 +1 @@ +Ensure workspace information is passed into installer when determining whether a product/tool is installed.