Skip to content

Commit 17f4934

Browse files
committed
Merge remote-tracking branch 'upstream/main' into eslint
2 parents 93d9d8d + 32917c2 commit 17f4934

25 files changed

+369
-354
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"displayName": "C#",
77
"author": "Microsoft Corporation",
88
"license": "SEE LICENSE IN RuntimeLicenses/license.txt",
9+
"qna": "https://github.com/dotnet/vscode-csharp/issues",
910
"icon": "images/csharpIcon.png",
1011
"preview": false,
1112
"bugs": {
@@ -35,7 +36,7 @@
3536
}
3637
},
3738
"defaults": {
38-
"roslyn": "4.7.0-3.23316.4",
39+
"roslyn": "4.7.0-3.23326.2",
3940
"omniSharp": "1.39.6",
4041
"razor": "7.0.0-preview.23275.2"
4142
},
@@ -150,6 +151,7 @@
150151
"typescript": "^5.1.3",
151152
"unzipper": "0.10.11",
152153
"vsce": "2.9.2",
154+
"vscode-uri": "^3.0.7",
153155
"webpack": "5.76.0",
154156
"webpack-cli": "4.6.0"
155157
},
@@ -1686,8 +1688,7 @@
16861688
{
16871689
"command": "csharp.reportIssue",
16881690
"title": "Report an issue",
1689-
"category": "CSharp",
1690-
"enablement": "config.dotnet.server.useOmnisharp"
1691+
"category": "CSharp"
16911692
},
16921693
{
16931694
"command": "csharp.showDecompilationTerms",

src/constants/IGetDotnetInfo.ts

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

src/coreclrDebug/activate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from '../omnisharp/loggingEvents';
1616
import { EventStream } from '../eventStream';
1717
import { getRuntimeDependencyPackageWithId } from '../tools/runtimeDependencyPackageUtils';
18-
import { getDotnetInfo } from '../utils/getDotnetInfo';
18+
import { getDotnetInfo } from '../shared/utils/getDotnetInfo';
1919
import { Options } from '../shared/options';
2020
import { RemoteAttachPicker } from '../features/processPicker';
2121
import CompositeDisposable from '../compositeDisposable';

src/coreclrDebug/util.ts

Lines changed: 7 additions & 1 deletion
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 = '1.0.0';
1414

@@ -133,6 +133,12 @@ export function getTargetArchitecture(
133133
}
134134

135135
// Otherwise, look at the runtime ID.
136+
if (!dotnetInfo.RuntimeId) {
137+
throw new Error(
138+
`Unable to determine RuntimeId. Please set 'targetArchitecture' in your launch.json configuration.`
139+
);
140+
}
141+
136142
if (dotnetInfo.RuntimeId.includes('arm64')) {
137143
return 'arm64';
138144
} else if (dotnetInfo.RuntimeId.includes('x64')) {

src/features/commands.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import { EventStream } from '../eventStream';
2424
import { PlatformInformation } from '../shared/platform';
2525
import CompositeDisposable from '../compositeDisposable';
2626
import OptionProvider from '../shared/observers/optionProvider';
27-
import reportIssue from './reportIssue';
27+
import reportIssue from '../shared/reportIssue';
2828
import { IHostExecutableResolver } from '../shared/constants/IHostExecutableResolver';
29-
import { getDotnetInfo } from '../utils/getDotnetInfo';
29+
import { getDotnetInfo } from '../shared/utils/getDotnetInfo';
3030
import { getDecompilationAuthorization, resetDecompilationAuthorization } from '../omnisharp/decompilationPrompt';
3131
import { IWorkspaceDebugInformationProvider } from '../shared/IWorkspaceDebugInformationProvider';
3232

@@ -79,7 +79,6 @@ export default function registerCommands(
7979
reportIssue(
8080
vscode,
8181
context.extension.packageJSON.version,
82-
eventStream,
8382
getDotnetInfo,
8483
platformInfo.isValidPlatformForMono(),
8584
optionProvider.GetLatestOptions(),

src/features/reportIssue.ts

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

src/lsptoolshost/commands.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@ 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(
17+
context: vscode.ExtensionContext,
18+
languageServer: RoslynLanguageServer,
19+
optionProvider: OptionProvider,
20+
hostExecutableResolver: IHostExecutableResolver
21+
) {
1322
// It is very important to be careful about the types used as parameters for these command callbacks.
1423
// If the arguments are coming from the server as json, it is NOT appropriate to use type definitions
1524
// from the normal vscode API (e.g. vscode.Location) as input parameters.
@@ -29,6 +38,18 @@ export function registerCommands(context: vscode.ExtensionContext, languageServe
2938
context.subscriptions.push(
3039
vscode.commands.registerCommand('dotnet.openSolution', async () => openSolution(languageServer))
3140
);
41+
context.subscriptions.push(
42+
vscode.commands.registerCommand('csharp.reportIssue', async () =>
43+
reportIssue(
44+
vscode,
45+
context.extension.packageJSON.version,
46+
getDotnetInfo,
47+
/*shouldIncludeMonoInfo:*/ false,
48+
optionProvider.GetLatestOptions(),
49+
hostExecutableResolver
50+
)
51+
)
52+
);
3253
}
3354

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

0 commit comments

Comments
 (0)