|
| 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 | + |
0 commit comments