Skip to content

Commit 40c292a

Browse files
committed
Implement report issue command for prerelease extension
1 parent 8e4471d commit 40c292a

24 files changed

+349
-325
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,8 +1677,7 @@
16771677
{
16781678
"command": "csharp.reportIssue",
16791679
"title": "Report an issue",
1680-
"category": "CSharp",
1681-
"enablement": "config.dotnet.server.useOmnisharp"
1680+
"category": "CSharp"
16821681
},
16831682
{
16841683
"command": "csharp.showDecompilationTerms",

src/constants/IGetDotnetInfo.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/coreclr-debug/activate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { PlatformInformation } from '../shared/platform';
1111
import { DebuggerPrerequisiteWarning, DebuggerPrerequisiteFailure, DebuggerNotInstalledFailure } from '../omnisharp/loggingEvents';
1212
import { EventStream } from '../EventStream';
1313
import { getRuntimeDependencyPackageWithId } from '../tools/RuntimeDependencyPackageUtils';
14-
import { getDotnetInfo } from '../utils/getDotnetInfo';
14+
import { getDotnetInfo } from '../shared/utils/getDotnetInfo';
1515
import { Options } from '../shared/options';
1616
import { RemoteAttachPicker } from '../features/processPicker';
1717
import CompositeDisposable from '../CompositeDisposable';

src/coreclr-debug/util.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as fs from 'fs';
88
import * as semver from 'semver';
99
import * as os from 'os';
1010
import { PlatformInformation } from '../shared/platform';
11-
import { getDotnetInfo, DotnetInfo } from '../utils/getDotnetInfo';
11+
import { getDotnetInfo, DotnetInfo } from '../shared/utils/getDotnetInfo';
1212

1313
const MINIMUM_SUPPORTED_DOTNET_CLI: string = '1.0.0';
1414

@@ -127,11 +127,11 @@ export function getTargetArchitecture(platformInfo: PlatformInformation, launchJ
127127
}
128128

129129
// Otherwise, look at the runtime ID.
130-
if (dotnetInfo.RuntimeId.includes('arm64'))
130+
if (dotnetInfo.RuntimeId?.includes('arm64'))
131131
{
132132
return 'arm64';
133133
}
134-
else if (dotnetInfo.RuntimeId.includes('x64'))
134+
else if (dotnetInfo.RuntimeId?.includes('x64'))
135135
{
136136
return 'x86_64';
137137
}

src/features/commands.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import { EventStream } from '../EventStream';
1818
import { PlatformInformation } from '../shared/platform';
1919
import CompositeDisposable from '../CompositeDisposable';
2020
import OptionProvider from '../shared/observers/OptionProvider';
21-
import reportIssue from './reportIssue';
21+
import reportIssue from '../shared/reportIssue';
2222
import { IHostExecutableResolver } from '../shared/constants/IHostExecutableResolver';
23-
import { getDotnetInfo } from '../utils/getDotnetInfo';
23+
import { getDotnetInfo } from '../shared/utils/getDotnetInfo';
2424
import { getDecompilationAuthorization, resetDecompilationAuthorization } from '../omnisharp/decompilationPrompt';
2525
import { IWorkspaceDebugInformationProvider } from '../shared/IWorkspaceDebugInformationProvider';
2626

@@ -47,7 +47,7 @@ export default function registerCommands(
4747
// Register command for generating tasks.json and launch.json assets.
4848
disposable.add(vscode.commands.registerCommand('dotnet.generateAssets', async (selectedIndex) => generateAssets(workspaceInformationProvider, selectedIndex)));
4949

50-
disposable.add(vscode.commands.registerCommand('csharp.reportIssue', async () => reportIssue(vscode, context.extension.packageJSON.version, eventStream, getDotnetInfo, platformInfo.isValidPlatformForMono(), optionProvider.GetLatestOptions(), dotnetResolver, monoResolver)));
50+
disposable.add(vscode.commands.registerCommand('csharp.reportIssue', async () => reportIssue(vscode, context.extension.packageJSON.version, getDotnetInfo, platformInfo.isValidPlatformForMono(), optionProvider.GetLatestOptions(), dotnetResolver, monoResolver)));
5151

5252
disposable.add(vscode.commands.registerCommand('csharp.showDecompilationTerms', async () => showDecompilationTerms(context, server, optionProvider)));
5353

src/features/reportIssue.ts

Lines changed: 0 additions & 116 deletions
This file was deleted.

src/lsptoolshost/commands.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ import { UriConverter } from './uriConverter';
88
import * as languageClient from 'vscode-languageclient/node';
99
import { RoslynLanguageServer } from './roslynLanguageServer';
1010
import { createLaunchTargetForSolution } from '../shared/LaunchTarget';
11+
import reportIssue from '../shared/reportIssue';
12+
import { getDotnetInfo } from '../shared/utils/getDotnetInfo';
13+
import OptionProvider from '../shared/observers/OptionProvider';
14+
import { IHostExecutableResolver } from '../shared/constants/IHostExecutableResolver';
1115

12-
export function registerCommands(context: vscode.ExtensionContext, languageServer: RoslynLanguageServer) {
16+
export function registerCommands(context: vscode.ExtensionContext, languageServer: RoslynLanguageServer, optionProvider: OptionProvider, hostExecutableResolver: IHostExecutableResolver) {
1317
// It is very important to be careful about the types used as parameters for these command callbacks.
1418
// If the arguments are coming from the server as json, it is NOT appropriate to use type definitions
1519
// from the normal vscode API (e.g. vscode.Location) as input parameters.
@@ -23,6 +27,7 @@ export function registerCommands(context: vscode.ExtensionContext, languageServe
2327
context.subscriptions.push(vscode.commands.registerCommand('roslyn.client.completionComplexEdit', completionComplexEdit));
2428
context.subscriptions.push(vscode.commands.registerCommand('dotnet.restartServer', async () => restartServer(languageServer)));
2529
context.subscriptions.push(vscode.commands.registerCommand('dotnet.openSolution', async () => openSolution(languageServer)));
30+
context.subscriptions.push(vscode.commands.registerCommand('csharp.reportIssue', async () => reportIssue(vscode, context.extension.packageJSON.version, getDotnetInfo, /*shouldIncludeMonoInfo:*/ false, optionProvider.GetLatestOptions(), hostExecutableResolver)));
2631
}
2732

2833
/**
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as path from 'path';
7+
import * as vscode from 'vscode';
8+
import { HostExecutableInformation } from "../shared/constants/HostExecutableInformation";
9+
import { IHostExecutableResolver } from "../shared/constants/IHostExecutableResolver";
10+
import { getServerPath } from "../lsptoolshost/roslynLanguageServer";
11+
import { PlatformInformation } from "../shared/platform";
12+
import { Options } from "../shared/options";
13+
import { existsSync } from 'fs';
14+
import { CSharpExtensionId } from '../constants/CSharpExtensionId';
15+
16+
export const DotNetRuntimeVersion = '7.0';
17+
18+
interface IDotnetAcquireResult {
19+
dotnetPath: string;
20+
}
21+
22+
/**
23+
* Resolves the dotnet runtime from given options and the dotnet runtime VSCode extension.
24+
*/
25+
export class DotnetRuntimeExtensionResolver implements IHostExecutableResolver {
26+
constructor(private platformInfo: PlatformInformation) { }
27+
28+
private hostInfo: HostExecutableInformation | undefined;
29+
30+
async getHostExecutableInfo(options: Options): Promise<HostExecutableInformation> {
31+
let dotnetRuntimePath = options.commonOptions.dotnetPath;
32+
const serverPath = getServerPath(options, this.platformInfo);
33+
if (!dotnetRuntimePath)
34+
{
35+
let dotnetInfo = await this.acquireDotNetProcessDependencies(serverPath);
36+
dotnetRuntimePath = path.dirname(dotnetInfo.path);
37+
}
38+
39+
// TODO need exe?
40+
const dotnetExecutableName = this.platformInfo.isWindows() ? 'dotnet.exe' : 'dotnet';
41+
const dotnetExecutablePath = path.join(dotnetRuntimePath, dotnetExecutableName);
42+
if (!existsSync(dotnetExecutablePath)) {
43+
throw new Error(`Cannot find dotnet path '${dotnetExecutablePath}'`);
44+
}
45+
46+
return {
47+
version: "", /* We don't need to know the version - we've already downloaded the correct one */
48+
path: dotnetExecutablePath,
49+
env: process.env,
50+
};
51+
}
52+
53+
/**
54+
* Acquires the .NET runtime if it is not already present.
55+
* @returns The path to the .NET runtime
56+
*/
57+
private async acquireRuntime(): Promise<HostExecutableInformation> {
58+
if (this.hostInfo) {
59+
return this.hostInfo;
60+
}
61+
62+
let status = await vscode.commands.executeCommand<IDotnetAcquireResult>('dotnet.acquireStatus', {
63+
version: DotNetRuntimeVersion,
64+
requestingExtensionId: CSharpExtensionId,
65+
});
66+
if (status === undefined) {
67+
await vscode.commands.executeCommand('dotnet.showAcquisitionLog');
68+
69+
status = await vscode.commands.executeCommand<IDotnetAcquireResult>('dotnet.acquire', {
70+
version: DotNetRuntimeVersion,
71+
requestingExtensionId: CSharpExtensionId,
72+
});
73+
if (!status?.dotnetPath) {
74+
throw new Error('Could not resolve the dotnet path!');
75+
}
76+
}
77+
78+
return (this.hostInfo = {
79+
version: DotNetRuntimeVersion,
80+
path: status.dotnetPath,
81+
env: process.env
82+
});
83+
}
84+
85+
/**
86+
* Acquires the .NET runtime and any other dependencies required to spawn a particular .NET executable.
87+
* @param path The path to the entrypoint assembly. Typically a .dll.
88+
* @returns The path to the `dotnet` command to use to spawn the process.
89+
*/
90+
private async acquireDotNetProcessDependencies(path: string) {
91+
const dotnetPath = await this.acquireRuntime();
92+
93+
const args = [path];
94+
// This will install any missing Linux dependencies.
95+
await vscode.commands.executeCommand('dotnet.ensureDotnetDependencies', { command: dotnetPath, arguments: args });
96+
97+
return dotnetPath;
98+
}
99+
}
100+
101+
102+

0 commit comments

Comments
 (0)