From 94835a5c52bb4eac3f774af654b8c76fa63a4fa9 Mon Sep 17 00:00:00 2001 From: Mark SchillI Date: Thu, 6 Jul 2017 15:03:04 -0400 Subject: [PATCH 1/3] Adds the ability to create a bug report from within the extension --- README.md | 2 + package.json | 10 +++ src/features/GenerateBugReport.ts | 135 ++++++++++++++++++++++++++++++ src/main.ts | 2 + src/session.ts | 2 +- src/settings.ts | 12 ++- 6 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 src/features/GenerateBugReport.ts diff --git a/README.md b/README.md index 9cbe243907..aa9bb5137e 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,8 @@ to file an issue on our GitHub repository: Make sure to fill in the information that is requested in the issue template as it will help us investigate the problem more quickly. +> 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. + ### 2. Capture verbose logs and send them to us If you're having an issue with crashing or other erratic behavior, add the following diff --git a/package.json b/package.json index 8e5be1d9e8..88389be05d 100644 --- a/package.json +++ b/package.json @@ -105,6 +105,11 @@ "title": "Open PowerShell Extension Logs Folder", "category": "PowerShell" }, + { + "command": "PowerShell.GenerateBugReport", + "title": "Upload Bug Report to Github", + "category": "PowerShell" + }, { "command": "PowerShell.OpenInISE", "title": "Open Current File in PowerShell ISE", @@ -399,6 +404,11 @@ "default": true, "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." }, + "powershell.bugReporting.project": { + "type": "string", + "default": "https://github.com/PowerShell/vscode-powershell", + "description": "Specifies the url of the GitHub project in which to generate bug reports." + }, "powershell.scriptAnalysis.enable": { "type": "boolean", "default": true, diff --git a/src/features/GenerateBugReport.ts b/src/features/GenerateBugReport.ts new file mode 100644 index 0000000000..e42f83eee6 --- /dev/null +++ b/src/features/GenerateBugReport.ts @@ -0,0 +1,135 @@ +import vscode = require('vscode'); +import { SessionManager } from '../session'; +import cp = require('child_process'); +import Settings = require('../settings'); + +import window = vscode.window; +const os = require("os"); + +import { IFeature, LanguageClient } from '../feature'; +// import { IExtensionManagementService, LocalExtensionType, ILocalExtension } from 'vs/platform/extensionManagement/common/extensionManagement'; + +const extensionId: string = 'ms-vscode.PowerShell'; +const extensionVersion: string = vscode.extensions.getExtension(extensionId).packageJSON.version; + +const queryStringPrefix: string = '?' + +var settings = Settings.load(); +let project = settings.bugReporting.project; + +const issuesUrl: string = `${project}/issues/new` + +var extensions = vscode.extensions.all.filter(element => element.packageJSON.isBuiltin == false).sort((leftside, rightside): number => { + if (leftside.packageJSON.name.toLowerCase() < rightside.packageJSON.name.toLowerCase()) return -1; + if (leftside.packageJSON.name.toLowerCase() > rightside.packageJSON.name.toLowerCase()) return 1; + return 0; +}) + +export class GenerateBugReportFeature implements IFeature { + + private command: vscode.Disposable; + private powerShellProcess: cp.ChildProcess; + + constructor(private sessionManager: SessionManager) { + this.command = vscode.commands.registerCommand('PowerShell.GenerateBugReport', () => { + + + var OutputChannel = window.createOutputChannel('Debug'); + OutputChannel.show(); + + OutputChannel.appendLine('Starting Bug Report'); + + var body = encodeURIComponent(`## Issue Description ## + +I am experiencing a problem with... + +## Attached Logs ## + +Follow the instructions in the [README](https://github.com/PowerShell/vscode-powershell#reporting-problems) about capturing and sending logs. + +## Environment Information ## + +### Visual Studio Code ### + +| Name | Version | +| --- | --- | +| Operating System | ${os.type() + ' ' + os.arch() + ' ' + os.release()} | +| VSCode | ${vscode.version}| +| PowerShell Extension Version | ${extensionVersion} | +| PSES | | + +### PowerShell Information ### + +${this.getRuntimeInfo()} + +### Visual Studio Code Extensions ### + +
Visual Studio Code Extensions(Click to Expand) + +${this.generateExtensionTable(extensions)} +
+ +`); + + var encodedBody = encodeURIComponent(body); + var fullUrl = `${issuesUrl}${queryStringPrefix}body=${encodedBody}`; + vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(fullUrl)); + + }); + + } + + + public setLanguageClient(LanguageClient: LanguageClient) { + // Not needed for this feature. + } + + public dispose() { + this.command.dispose(); + } + + + private generateExtensionTable(extensions): string { + if (!extensions.length) { + return 'none'; + } + + let tableHeader = `|Extension|Author|Version|\n|---|---|---|`; + const table = extensions.map(e => { + + if (e.packageJSON.isBuiltin == false) { + return `|${e.packageJSON.name}|${e.packageJSON.publisher}|${e.packageJSON.version}|`; + } + }).join('\n'); + + const extensionTable = ` +${tableHeader}\n${table}; +`; + // 2000 chars is browsers de-facto limit for URLs, 400 chars are allowed for other string parts of the issue URL + // http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers + // if (encodeURIComponent(extensionTable).length > 1600) { + // return 'the listing length exceeds browsers\' URL characters limit'; + // } + + return extensionTable; + } + + private getRuntimeInfo() { + + var psOutput; + var powerShellExePath = this.sessionManager.getPowerShellExePath(); + var powerShellArgs = [ + "-NoProfile", + + "-Command", + '$PSVersionString = "|Name|Value|\n"; $PSVersionString += "|---|---|\n"; $PSVersionTable.keys | ForEach-Object { $PSVersionString += "|$_|$($PSVersionTable.Item($_))|\n" }; $PSVersionString' + ] + + var spawn = require('child_process').spawnSync; + var child = spawn(powerShellExePath, powerShellArgs); + return child.stdout.toString().replace(';', ','); + + } + +} + diff --git a/src/main.ts b/src/main.ts index 8ccb72bcb4..3df9942bb0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -15,6 +15,7 @@ import { PowerShellLanguageId } from './utils'; import { ConsoleFeature } from './features/Console'; import { ExamplesFeature } from './features/Examples'; import { OpenInISEFeature } from './features/OpenInISE'; +import { GenerateBugReportFeature } from './features/GenerateBugReport'; import { CustomViewsFeature } from './features/CustomViews'; import { ExpandAliasFeature } from './features/ExpandAlias'; import { ShowHelpFeature } from './features/ShowOnlineHelp'; @@ -109,6 +110,7 @@ export function activate(context: vscode.ExtensionContext): void { new ConsoleFeature(), new ExamplesFeature(), new OpenInISEFeature(), + new GenerateBugReportFeature(sessionManager), new ExpandAliasFeature(), new ShowHelpFeature(), new FindModuleFeature(), diff --git a/src/session.ts b/src/session.ts index f6fde9de1f..2cb073d19c 100644 --- a/src/session.ts +++ b/src/session.ts @@ -500,7 +500,7 @@ export class SessionManager implements Middleware { SessionStatus.Failed); } - private getPowerShellExePath(): string { + public getPowerShellExePath(): string { if (!this.sessionSettings.powerShellExePath && this.sessionSettings.developer.powerShellExePath) diff --git a/src/settings.ts b/src/settings.ts index 7934789098..4f9e3a6ad9 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -14,6 +14,10 @@ enum CodeFormattingPreset { Stroustrup } +export interface IBugReportingSettings { + project: string; +} + export interface ICodeFormattingSettings { preset: CodeFormattingPreset; openBraceOnSameLine: boolean; @@ -55,6 +59,7 @@ export interface ISettings { developer?: IDeveloperSettings; codeFormatting?: ICodeFormattingSettings; integratedConsole?: IIntegratedConsoleSettings; + bugReporting?: IBugReportingSettings } export interface IIntegratedConsoleSettings { @@ -67,6 +72,10 @@ export function load(): ISettings { vscode.workspace.getConfiguration( utils.PowerShellLanguageId); + let defaultBugReportingSettings: IBugReportingSettings = { + project: "https://github.com/PowerShell/vscode-powershell" + }; + let defaultScriptAnalysisSettings: IScriptAnalysisSettings = { enable: true, settingsPath: "" @@ -112,7 +121,8 @@ export function load(): ISettings { debugging: configuration.get("debugging", defaultDebuggingSettings), developer: configuration.get("developer", defaultDeveloperSettings), codeFormatting: configuration.get("codeFormatting", defaultCodeFormattingSettings), - integratedConsole: configuration.get("integratedConsole", defaultIntegratedConsoleSettings) + integratedConsole: configuration.get("integratedConsole", defaultIntegratedConsoleSettings), + bugReporting: configuration.get("bugReporting", defaultBugReportingSettings) }; } From f16040dc0bfe1354532ed40a70a815c3694fbe95 Mon Sep 17 00:00:00 2001 From: Mark SchillI Date: Tue, 18 Jul 2017 08:07:18 -0400 Subject: [PATCH 2/3] Removes PSES line from output --- src/features/GenerateBugReport.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/features/GenerateBugReport.ts b/src/features/GenerateBugReport.ts index e42f83eee6..a7c9c87e67 100644 --- a/src/features/GenerateBugReport.ts +++ b/src/features/GenerateBugReport.ts @@ -56,7 +56,6 @@ Follow the instructions in the [README](https://github.com/PowerShell/vscode-pow | Operating System | ${os.type() + ' ' + os.arch() + ' ' + os.release()} | | VSCode | ${vscode.version}| | PowerShell Extension Version | ${extensionVersion} | -| PSES | | ### PowerShell Information ### @@ -120,7 +119,6 @@ ${tableHeader}\n${table}; var powerShellExePath = this.sessionManager.getPowerShellExePath(); var powerShellArgs = [ "-NoProfile", - "-Command", '$PSVersionString = "|Name|Value|\n"; $PSVersionString += "|---|---|\n"; $PSVersionTable.keys | ForEach-Object { $PSVersionString += "|$_|$($PSVersionTable.Item($_))|\n" }; $PSVersionString' ] From 99711560b4e8d8eb632ccf6e90fb0805c1f795f6 Mon Sep 17 00:00:00 2001 From: Mark SchillI Date: Thu, 27 Jul 2017 08:27:29 -0400 Subject: [PATCH 3/3] Removes unused output code used for debugging --- src/features/GenerateBugReport.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/features/GenerateBugReport.ts b/src/features/GenerateBugReport.ts index a7c9c87e67..33aeb96f69 100644 --- a/src/features/GenerateBugReport.ts +++ b/src/features/GenerateBugReport.ts @@ -3,7 +3,6 @@ import { SessionManager } from '../session'; import cp = require('child_process'); import Settings = require('../settings'); -import window = vscode.window; const os = require("os"); import { IFeature, LanguageClient } from '../feature'; @@ -33,12 +32,6 @@ export class GenerateBugReportFeature implements IFeature { constructor(private sessionManager: SessionManager) { this.command = vscode.commands.registerCommand('PowerShell.GenerateBugReport', () => { - - var OutputChannel = window.createOutputChannel('Debug'); - OutputChannel.show(); - - OutputChannel.appendLine('Starting Bug Report'); - var body = encodeURIComponent(`## Issue Description ## I am experiencing a problem with...