forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreportIssueCommand.ts
More file actions
49 lines (42 loc) · 2.38 KB
/
reportIssueCommand.ts
File metadata and controls
49 lines (42 loc) · 2.38 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import * as fs from 'fs-extra';
import * as path from 'path';
import { inject, injectable } from 'inversify';
import { IExtensionSingleActivationService } from '../../../activation/types';
import { ICommandManager, IWorkspaceService } from '../types';
import { EXTENSION_ROOT_DIR } from '../../../constants';
import { IInterpreterService, IInterpreterVersionService } from '../../../interpreter/contracts';
import { identifyEnvironment } from '../../../pythonEnvironments/common/environmentIdentifier';
import { getPythonOutputChannelContent } from '../../../logging';
import { Commands } from '../../constants';
/**
* Allows the user to report an issue related to the Python extension using our template.
*/
@injectable()
export class ReportIssueCommandHandler implements IExtensionSingleActivationService {
constructor(
@inject(ICommandManager) private readonly commandManager: ICommandManager,
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService,
@inject(IInterpreterService) private readonly interpreterService: IInterpreterService,
@inject(IInterpreterVersionService) private readonly interpreterVersionService: IInterpreterVersionService,
) {}
public async activate(): Promise<void> {
this.commandManager.registerCommand(Commands.ReportIssue, this.openReportIssue, this);
}
private templatePath = path.join(EXTENSION_ROOT_DIR, 'resources', 'report_issue_template.md');
public async openReportIssue(): Promise<void> {
const pythonLogs = await getPythonOutputChannelContent();
const template = await fs.readFile(this.templatePath, 'utf8');
const interpreterPath = (await this.interpreterService.getActiveInterpreter())?.path || 'not-selected';
const pythonVersion = await this.interpreterVersionService.getVersion(interpreterPath, '');
const languageServer =
this.workspaceService.getConfiguration('python').get<string>('languageServer') || 'Not Found';
const virtualEnv = await identifyEnvironment(interpreterPath);
this.commandManager.executeCommand('workbench.action.openIssueReporter', {
extensionId: 'ms-python.python',
issueBody: template.format(pythonVersion, virtualEnv, languageServer, pythonLogs),
});
}
}