forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pylintPrompt.ts
86 lines (73 loc) · 3.45 KB
/
pylintPrompt.ts
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { IApplicationEnvironment } from '../../common/application/types';
import { Common, ToolsExtensions } from '../../common/utils/localize';
import { executeCommand } from '../../common/vscodeApis/commandApis';
import { showInformationMessage } from '../../common/vscodeApis/windowApis';
import { IServiceContainer } from '../../ioc/types';
import { sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';
import { doNotShowPromptState, inToolsExtensionsExperiment, isExtensionDisabled, isExtensionEnabled } from './common';
import { IToolsExtensionPrompt } from './types';
export const PYLINT_EXTENSION = 'ms-python.pylint';
const PYLINT_PROMPT_DONOTSHOW_KEY = 'showPylintExtensionPrompt';
export class PylintExtensionPrompt implements IToolsExtensionPrompt {
private shownThisSession = false;
public constructor(private readonly serviceContainer: IServiceContainer) {}
public async showPrompt(): Promise<boolean> {
const isEnabled = isExtensionEnabled(this.serviceContainer, PYLINT_EXTENSION);
if (isEnabled || isExtensionDisabled(this.serviceContainer, PYLINT_EXTENSION)) {
sendTelemetryEvent(EventName.TOOLS_EXTENSIONS_ALREADY_INSTALLED, undefined, {
extensionId: PYLINT_EXTENSION,
isEnabled,
});
return true;
}
const doNotShow = doNotShowPromptState(this.serviceContainer, PYLINT_PROMPT_DONOTSHOW_KEY);
if (this.shownThisSession || doNotShow.value) {
return false;
}
if (!(await inToolsExtensionsExperiment(this.serviceContainer))) {
return false;
}
sendTelemetryEvent(EventName.TOOLS_EXTENSIONS_PROMPT_SHOWN, undefined, { extensionId: PYLINT_EXTENSION });
this.shownThisSession = true;
const response = await showInformationMessage(
ToolsExtensions.pylintPromptMessage,
ToolsExtensions.installPylintExtension,
Common.doNotShowAgain,
);
if (response === Common.doNotShowAgain) {
await doNotShow.updateValue(true);
sendTelemetryEvent(EventName.TOOLS_EXTENSIONS_PROMPT_DISMISSED, undefined, {
extensionId: PYLINT_EXTENSION,
dismissType: 'doNotShow',
});
return false;
}
if (response === ToolsExtensions.installPylintExtension) {
sendTelemetryEvent(EventName.TOOLS_EXTENSIONS_INSTALL_SELECTED, undefined, {
extensionId: PYLINT_EXTENSION,
});
const appEnv: IApplicationEnvironment = this.serviceContainer.get<IApplicationEnvironment>(
IApplicationEnvironment,
);
await executeCommand('workbench.extensions.installExtension', PYLINT_EXTENSION, {
installPreReleaseVersion: appEnv.extensionChannel === 'insiders',
});
return true;
}
sendTelemetryEvent(EventName.TOOLS_EXTENSIONS_PROMPT_DISMISSED, undefined, {
extensionId: PYLINT_EXTENSION,
dismissType: 'close',
});
return false;
}
}
let _prompt: IToolsExtensionPrompt | undefined;
export function getOrCreatePylintPrompt(serviceContainer: IServiceContainer): IToolsExtensionPrompt {
if (!_prompt) {
_prompt = new PylintExtensionPrompt(serviceContainer);
}
return _prompt;
}