forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproductPath.ts
More file actions
120 lines (108 loc) · 5.17 KB
/
productPath.ts
File metadata and controls
120 lines (108 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable } from 'inversify';
import * as path from 'path';
import { Uri } from 'vscode';
import { IFormatterHelper } from '../../formatters/types';
import { IServiceContainer } from '../../ioc/types';
import { ILinterManager } from '../../linters/types';
import { ITestingService } from '../../testing/types';
import { IConfigurationService, IInstaller, ModuleNamePurpose, Product } from '../types';
import { IProductPathService } from './types';
@injectable()
export abstract class BaseProductPathsService implements IProductPathService {
protected readonly configService: IConfigurationService;
protected readonly productInstaller: IInstaller;
constructor(@inject(IServiceContainer) protected serviceContainer: IServiceContainer) {
this.configService = serviceContainer.get<IConfigurationService>(IConfigurationService);
this.productInstaller = serviceContainer.get<IInstaller>(IInstaller);
}
public abstract getExecutableNameFromSettings(product: Product, resource?: Uri): string;
public isExecutableAModule(product: Product, resource?: Uri): boolean {
let moduleName: string | undefined;
try {
moduleName = this.productInstaller.translateProductToModuleName(product, ModuleNamePurpose.run);
} catch {}
// User may have customized the module name or provided the fully qualifieid path.
const executableName = this.getExecutableNameFromSettings(product, resource);
return (
typeof moduleName === 'string' && moduleName.length > 0 && path.basename(executableName) === executableName
);
}
}
@injectable()
export class CTagsProductPathService extends BaseProductPathsService {
constructor(@inject(IServiceContainer) serviceContainer: IServiceContainer) {
super(serviceContainer);
}
public getExecutableNameFromSettings(_: Product, resource?: Uri): string {
const settings = this.configService.getSettings(resource);
return settings.workspaceSymbols.ctagsPath;
}
}
@injectable()
export class FormatterProductPathService extends BaseProductPathsService {
constructor(@inject(IServiceContainer) serviceContainer: IServiceContainer) {
super(serviceContainer);
}
public getExecutableNameFromSettings(product: Product, resource?: Uri): string {
const settings = this.configService.getSettings(resource);
const formatHelper = this.serviceContainer.get<IFormatterHelper>(IFormatterHelper);
const settingsPropNames = formatHelper.getSettingsPropertyNames(product);
return settings.formatting[settingsPropNames.pathName] as string;
}
}
@injectable()
export class LinterProductPathService extends BaseProductPathsService {
constructor(@inject(IServiceContainer) serviceContainer: IServiceContainer) {
super(serviceContainer);
}
public getExecutableNameFromSettings(product: Product, resource?: Uri): string {
const linterManager = this.serviceContainer.get<ILinterManager>(ILinterManager);
return linterManager.getLinterInfo(product).pathName(resource);
}
}
@injectable()
export class TestFrameworkProductPathService extends BaseProductPathsService {
constructor(@inject(IServiceContainer) serviceContainer: IServiceContainer) {
super(serviceContainer);
}
public getExecutableNameFromSettings(product: Product, resource?: Uri): string {
const testHelper = this.serviceContainer.get<ITestingService>(ITestingService);
const settingsPropNames = testHelper.getSettingsPropertyNames(product);
if (!settingsPropNames.pathName) {
// E.g. in the case of UnitTests we don't allow customizing the paths.
return this.productInstaller.translateProductToModuleName(product, ModuleNamePurpose.run);
}
const settings = this.configService.getSettings(resource);
return settings.testing[settingsPropNames.pathName] as string;
}
}
@injectable()
export class RefactoringLibraryProductPathService extends BaseProductPathsService {
constructor(@inject(IServiceContainer) serviceContainer: IServiceContainer) {
super(serviceContainer);
}
public getExecutableNameFromSettings(product: Product, _?: Uri): string {
return this.productInstaller.translateProductToModuleName(product, ModuleNamePurpose.run);
}
}
@injectable()
export class DataScienceProductPathService extends BaseProductPathsService {
constructor(@inject(IServiceContainer) serviceContainer: IServiceContainer) {
super(serviceContainer);
}
public getExecutableNameFromSettings(product: Product, _?: Uri): string {
return this.productInstaller.translateProductToModuleName(product, ModuleNamePurpose.run);
}
}
@injectable()
export class TensorBoardProductPathService extends BaseProductPathsService {
constructor(@inject(IServiceContainer) serviceContainer: IServiceContainer) {
super(serviceContainer);
}
public getExecutableNameFromSettings(product: Product, _?: Uri): string {
return this.productInstaller.translateProductToModuleName(product, ModuleNamePurpose.run);
}
}