-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2503 from akshita31/bug_generator
Add command to create an issue from within the extension
- Loading branch information
Showing
26 changed files
with
731 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
export const CSharpExtensionId = 'ms-vscode.csharp'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
export interface IGetDotnetInfo { | ||
(): Promise<string>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
export interface IGetMonoVersion { | ||
(environment: NodeJS.ProcessEnv): Promise<string>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { Options } from "../omnisharp/options"; | ||
import { MonoInformation } from "./MonoInformation"; | ||
|
||
export interface IMonoResolver { | ||
getGlobalMonoInfo(options: Options): Promise<MonoInformation>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
export interface MonoInformation { | ||
version: string; | ||
path: string; | ||
env: NodeJS.ProcessEnv; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { vscode } from "../vscodeAdapter"; | ||
import { Extension } from "../vscodeAdapter"; | ||
import { CSharpExtensionId } from "../constants/CSharpExtensionId"; | ||
import { EventStream } from "../EventStream"; | ||
import { OpenURL } from "../omnisharp/loggingEvents"; | ||
import { Options } from "../omnisharp/options"; | ||
import { IMonoResolver } from "../constants/IMonoResolver"; | ||
import { IGetDotnetInfo } from "../constants/IGetDotnetInfo"; | ||
|
||
const issuesUrl = "https://github.com/OmniSharp/omnisharp-vscode/issues/new"; | ||
|
||
export default async function reportIssue(vscode: vscode, eventStream: EventStream, getDotnetInfo: IGetDotnetInfo, isValidPlatformForMono: boolean, options: Options, monoResolver: IMonoResolver) { | ||
const dotnetInfo = await getDotnetInfo(); | ||
const monoInfo = await getMonoIfPlatformValid(isValidPlatformForMono, options, monoResolver); | ||
let extensions = getInstalledExtensions(vscode); | ||
let csharpExtVersion = getCsharpExtensionVersion(vscode); | ||
|
||
const body = encodeURIComponent(`## Issue Description ## | ||
## Steps to Reproduce ## | ||
## Expected Behavior ## | ||
## Actual Behavior ## | ||
## Logs ## | ||
### OmniSharp log ### | ||
<details>Post the output from Output-->OmniSharp log here</details> | ||
### C# log ### | ||
<details>Post the output from Output-->C# here</details> | ||
## Environment information ## | ||
**VSCode version**: ${vscode.version} | ||
**C# Extension**: ${csharpExtVersion} | ||
${monoInfo} | ||
<details><summary>Dotnet Information</summary> | ||
${dotnetInfo}</details> | ||
<details><summary>Visual Studio Code Extensions</summary> | ||
${generateExtensionTable(extensions)} | ||
</details> | ||
`); | ||
|
||
const encodedBody = encodeURIComponent(body); | ||
const queryStringPrefix: string = "?"; | ||
const fullUrl = `${issuesUrl}${queryStringPrefix}body=${encodedBody}`; | ||
eventStream.post(new OpenURL(fullUrl)); | ||
} | ||
|
||
function sortExtensions(a: Extension<any>, b: Extension<any>): number { | ||
|
||
if (a.packageJSON.name.toLowerCase() < b.packageJSON.name.toLowerCase()) { | ||
return -1; | ||
} | ||
if (a.packageJSON.name.toLowerCase() > b.packageJSON.name.toLowerCase()) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
function generateExtensionTable(extensions: Extension<any>[]) { | ||
if (extensions.length <= 0) { | ||
return "none"; | ||
} | ||
|
||
const tableHeader = `|Extension|Author|Version|\n|---|---|---|`; | ||
const table = extensions.map((e) => `|${e.packageJSON.name}|${e.packageJSON.publisher}|${e.packageJSON.version}|`).join("\n"); | ||
|
||
const extensionTable = ` | ||
${tableHeader}\n${table}; | ||
`; | ||
|
||
return extensionTable; | ||
} | ||
|
||
async function getMonoIfPlatformValid(isValidPlatformForMono: boolean, options: Options, monoResolver: IMonoResolver): Promise<string> { | ||
if (isValidPlatformForMono) { | ||
let monoVersion: string; | ||
try { | ||
let globalMonoInfo = await monoResolver.getGlobalMonoInfo(options); | ||
if (globalMonoInfo) { | ||
monoVersion = `OmniSharp using global mono :${globalMonoInfo.version}`; | ||
} | ||
else { | ||
monoVersion = `OmniSharp using built-in mono`; | ||
} | ||
} | ||
catch (error) { | ||
monoVersion = `There is a problem with running OmniSharp on mono: ${error}`; | ||
} | ||
|
||
return `<details><summary>Mono Information</summary> | ||
${monoVersion}</details>`; | ||
} | ||
|
||
return ""; | ||
} | ||
|
||
|
||
|
||
function getInstalledExtensions(vscode: vscode) { | ||
let extensions = vscode.extensions.all | ||
.filter(extension => extension.packageJSON.isBuiltin === false); | ||
|
||
return extensions.sort(sortExtensions); | ||
} | ||
|
||
function getCsharpExtensionVersion(vscode: vscode): string { | ||
const extension = vscode.extensions.getExtension(CSharpExtensionId); | ||
return extension.packageJSON.version; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { vscode } from "../vscodeAdapter"; | ||
import { BaseEvent, OpenURL } from "../omnisharp/loggingEvents"; | ||
|
||
export class OpenURLObserver { | ||
|
||
constructor(private vscode: vscode) { | ||
} | ||
|
||
public post = (event: BaseEvent) => { | ||
switch (event.constructor.name) { | ||
case OpenURL.name: | ||
let url = (<OpenURL>event).url; | ||
this.vscode.commands.executeCommand("vscode.open", this.vscode.Uri.parse(url)); | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { satisfies } from 'semver'; | ||
import * as path from 'path'; | ||
import { Options } from './options'; | ||
import { IMonoResolver } from '../constants/IMonoResolver'; | ||
import { MonoInformation } from '../constants/MonoInformation'; | ||
import { IGetMonoVersion } from '../constants/IGetMonoVersion'; | ||
|
||
export class OmniSharpMonoResolver implements IMonoResolver { | ||
private minimumMonoVersion = "5.8.1"; | ||
constructor(private getMonoVersion: IGetMonoVersion) { | ||
} | ||
|
||
private async configureEnvironmentAndGetInfo(options: Options): Promise<MonoInformation> { | ||
let env = { ...process.env }; | ||
let monoPath: string; | ||
if (options.useGlobalMono !== "never" && options.monoPath !== undefined) { | ||
env['PATH'] = path.join(options.monoPath, 'bin') + path.delimiter + env['PATH']; | ||
env['MONO_GAC_PREFIX'] = options.monoPath; | ||
monoPath = options.monoPath; | ||
} | ||
|
||
let version = await this.getMonoVersion(env); | ||
|
||
return { | ||
version, | ||
path: monoPath, | ||
env | ||
}; | ||
} | ||
|
||
public async getGlobalMonoInfo(options: Options): Promise<MonoInformation> { | ||
let monoInfo = await this.configureEnvironmentAndGetInfo(options); | ||
let isValid = monoInfo.version && satisfies(monoInfo.version, `>=${this.minimumMonoVersion}`); | ||
|
||
if (options.useGlobalMono === "always") { | ||
if (!isValid) { | ||
throw new Error(`Cannot start OmniSharp because Mono version >=${this.minimumMonoVersion} is required.`); | ||
} | ||
|
||
return monoInfo; | ||
} | ||
else if (options.useGlobalMono === "auto" && isValid) { | ||
return monoInfo; | ||
} | ||
|
||
return undefined; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.