Skip to content

Commit f03a750

Browse files
PowerSchilldaviwil
authored andcommitted
Adds the ability to create a bug report from within the extension
1 parent d57ab29 commit f03a750

File tree

6 files changed

+161
-2
lines changed

6 files changed

+161
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ to file an issue on our GitHub repository:
9999
Make sure to fill in the information that is requested in the issue template as it
100100
will help us investigate the problem more quickly.
101101

102+
> Note To automatically create a bug report from within the extension run the *"Report a problem on GitHub"* command. Some basic information about your instance and powershell versions will be collected and inserted into a new GitHub issue.
103+
102104
### 2. Capture verbose logs and send them to us
103105

104106
If you're having an issue with crashing or other erratic behavior, add the following

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@
110110
"title": "Open PowerShell Extension Logs Folder",
111111
"category": "PowerShell"
112112
},
113+
{
114+
"command": "PowerShell.GenerateBugReport",
115+
"title": "Upload Bug Report to Github",
116+
"category": "PowerShell"
117+
},
113118
{
114119
"command": "PowerShell.OpenInISE",
115120
"title": "Open Current File in PowerShell ISE",
@@ -404,6 +409,11 @@
404409
"default": true,
405410
"description": "Loads user and system-wide PowerShell profiles (profile.ps1 and Microsoft.VSCode_profile.ps1) into the PowerShell session. This affects IntelliSense and interactive script execution, but it does not affect the debugger."
406411
},
412+
"powershell.bugReporting.project": {
413+
"type": "string",
414+
"default": "https://github.com/PowerShell/vscode-powershell",
415+
"description": "Specifies the url of the GitHub project in which to generate bug reports."
416+
},
407417
"powershell.scriptAnalysis.enable": {
408418
"type": "boolean",
409419
"default": true,

src/features/GenerateBugReport.ts

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import vscode = require('vscode');
2+
import { SessionManager } from '../session';
3+
import cp = require('child_process');
4+
import Settings = require('../settings');
5+
6+
import window = vscode.window;
7+
const os = require("os");
8+
9+
import { IFeature, LanguageClient } from '../feature';
10+
// import { IExtensionManagementService, LocalExtensionType, ILocalExtension } from 'vs/platform/extensionManagement/common/extensionManagement';
11+
12+
const extensionId: string = 'ms-vscode.PowerShell';
13+
const extensionVersion: string = vscode.extensions.getExtension(extensionId).packageJSON.version;
14+
15+
const queryStringPrefix: string = '?'
16+
17+
var settings = Settings.load();
18+
let project = settings.bugReporting.project;
19+
20+
const issuesUrl: string = `${project}/issues/new`
21+
22+
var extensions = vscode.extensions.all.filter(element => element.packageJSON.isBuiltin == false).sort((leftside, rightside): number => {
23+
if (leftside.packageJSON.name.toLowerCase() < rightside.packageJSON.name.toLowerCase()) return -1;
24+
if (leftside.packageJSON.name.toLowerCase() > rightside.packageJSON.name.toLowerCase()) return 1;
25+
return 0;
26+
})
27+
28+
export class GenerateBugReportFeature implements IFeature {
29+
30+
private command: vscode.Disposable;
31+
private powerShellProcess: cp.ChildProcess;
32+
33+
constructor(private sessionManager: SessionManager) {
34+
this.command = vscode.commands.registerCommand('PowerShell.GenerateBugReport', () => {
35+
36+
37+
var OutputChannel = window.createOutputChannel('Debug');
38+
OutputChannel.show();
39+
40+
OutputChannel.appendLine('Starting Bug Report');
41+
42+
var body = encodeURIComponent(`## Issue Description ##
43+
44+
I am experiencing a problem with...
45+
46+
## Attached Logs ##
47+
48+
Follow the instructions in the [README](https://github.com/PowerShell/vscode-powershell#reporting-problems) about capturing and sending logs.
49+
50+
## Environment Information ##
51+
52+
### Visual Studio Code ###
53+
54+
| Name | Version |
55+
| --- | --- |
56+
| Operating System | ${os.type() + ' ' + os.arch() + ' ' + os.release()} |
57+
| VSCode | ${vscode.version}|
58+
| PowerShell Extension Version | ${extensionVersion} |
59+
| PSES | |
60+
61+
### PowerShell Information ###
62+
63+
${this.getRuntimeInfo()}
64+
65+
### Visual Studio Code Extensions ###
66+
67+
<details><summary>Visual Studio Code Extensions(Click to Expand)</summary>
68+
69+
${this.generateExtensionTable(extensions)}
70+
</details>
71+
72+
`);
73+
74+
var encodedBody = encodeURIComponent(body);
75+
var fullUrl = `${issuesUrl}${queryStringPrefix}body=${encodedBody}`;
76+
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(fullUrl));
77+
78+
});
79+
80+
}
81+
82+
83+
public setLanguageClient(LanguageClient: LanguageClient) {
84+
// Not needed for this feature.
85+
}
86+
87+
public dispose() {
88+
this.command.dispose();
89+
}
90+
91+
92+
private generateExtensionTable(extensions): string {
93+
if (!extensions.length) {
94+
return 'none';
95+
}
96+
97+
let tableHeader = `|Extension|Author|Version|\n|---|---|---|`;
98+
const table = extensions.map(e => {
99+
100+
if (e.packageJSON.isBuiltin == false) {
101+
return `|${e.packageJSON.name}|${e.packageJSON.publisher}|${e.packageJSON.version}|`;
102+
}
103+
}).join('\n');
104+
105+
const extensionTable = `
106+
${tableHeader}\n${table};
107+
`;
108+
// 2000 chars is browsers de-facto limit for URLs, 400 chars are allowed for other string parts of the issue URL
109+
// http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
110+
// if (encodeURIComponent(extensionTable).length > 1600) {
111+
// return 'the listing length exceeds browsers\' URL characters limit';
112+
// }
113+
114+
return extensionTable;
115+
}
116+
117+
private getRuntimeInfo() {
118+
119+
var psOutput;
120+
var powerShellExePath = this.sessionManager.getPowerShellExePath();
121+
var powerShellArgs = [
122+
"-NoProfile",
123+
124+
"-Command",
125+
'$PSVersionString = "|Name|Value|\n"; $PSVersionString += "|---|---|\n"; $PSVersionTable.keys | ForEach-Object { $PSVersionString += "|$_|$($PSVersionTable.Item($_))|\n" }; $PSVersionString'
126+
]
127+
128+
var spawn = require('child_process').spawnSync;
129+
var child = spawn(powerShellExePath, powerShellArgs);
130+
return child.stdout.toString().replace(';', ',');
131+
132+
}
133+
134+
}
135+

src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { PowerShellLanguageId } from './utils';
1515
import { ConsoleFeature } from './features/Console';
1616
import { ExamplesFeature } from './features/Examples';
1717
import { OpenInISEFeature } from './features/OpenInISE';
18+
import { GenerateBugReportFeature } from './features/GenerateBugReport';
1819
import { CustomViewsFeature } from './features/CustomViews';
1920
import { ExpandAliasFeature } from './features/ExpandAlias';
2021
import { ShowHelpFeature } from './features/ShowOnlineHelp';
@@ -109,6 +110,7 @@ export function activate(context: vscode.ExtensionContext): void {
109110
new ConsoleFeature(),
110111
new ExamplesFeature(),
111112
new OpenInISEFeature(),
113+
new GenerateBugReportFeature(sessionManager),
112114
new ExpandAliasFeature(),
113115
new ShowHelpFeature(),
114116
new FindModuleFeature(),

src/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ export class SessionManager implements Middleware {
519519
SessionStatus.Failed);
520520
}
521521

522-
private getPowerShellExePath(): string {
522+
public getPowerShellExePath(): string {
523523

524524
if (!this.sessionSettings.powerShellExePath &&
525525
this.sessionSettings.developer.powerShellExePath)

src/settings.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ enum CodeFormattingPreset {
1414
Stroustrup
1515
}
1616

17+
export interface IBugReportingSettings {
18+
project: string;
19+
}
20+
1721
export interface ICodeFormattingSettings {
1822
preset: CodeFormattingPreset;
1923
openBraceOnSameLine: boolean;
@@ -55,6 +59,7 @@ export interface ISettings {
5559
developer?: IDeveloperSettings;
5660
codeFormatting?: ICodeFormattingSettings;
5761
integratedConsole?: IIntegratedConsoleSettings;
62+
bugReporting?: IBugReportingSettings
5863
}
5964

6065
export interface IIntegratedConsoleSettings {
@@ -67,6 +72,10 @@ export function load(): ISettings {
6772
vscode.workspace.getConfiguration(
6873
utils.PowerShellLanguageId);
6974

75+
let defaultBugReportingSettings: IBugReportingSettings = {
76+
project: "https://github.com/PowerShell/vscode-powershell"
77+
};
78+
7079
let defaultScriptAnalysisSettings: IScriptAnalysisSettings = {
7180
enable: true,
7281
settingsPath: ""
@@ -112,7 +121,8 @@ export function load(): ISettings {
112121
debugging: configuration.get<IDebuggingSettings>("debugging", defaultDebuggingSettings),
113122
developer: configuration.get<IDeveloperSettings>("developer", defaultDeveloperSettings),
114123
codeFormatting: configuration.get<ICodeFormattingSettings>("codeFormatting", defaultCodeFormattingSettings),
115-
integratedConsole: configuration.get<IIntegratedConsoleSettings>("integratedConsole", defaultIntegratedConsoleSettings)
124+
integratedConsole: configuration.get<IIntegratedConsoleSettings>("integratedConsole", defaultIntegratedConsoleSettings),
125+
bugReporting: configuration.get<IBugReportingSettings>("bugReporting", defaultBugReportingSettings)
116126
};
117127
}
118128

0 commit comments

Comments
 (0)