Skip to content

Commit

Permalink
Use the dotnet bundle api to get dotnet path
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeRobich committed Apr 6, 2021
1 parent b1c5e2c commit dffd50b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
24 changes: 24 additions & 0 deletions src/DotnetPack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from "vscode";

const dotnetPackExtensionId = "ms-dotnettools.vscode-dotnet-pack";

export interface DotnetPackExtensionExports {
getDotnetPath(version?: string): Promise<string | undefined>;
}

export async function getDotnetPackApi(): Promise<DotnetPackExtensionExports> {
const dotnetExtension = vscode.extensions.getExtension<DotnetPackExtensionExports>(dotnetPackExtensionId);
if (!dotnetExtension) {
return null;
}

if (!dotnetExtension.isActive) {
await dotnetExtension.activate();
}

return dotnetExtension.exports;
}
2 changes: 1 addition & 1 deletion src/features/codeActionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default class CodeActionProvider extends AbstractProvider implements vsco

private async _runCodeAction(req: protocol.V2.RunCodeActionRequest, token: vscode.CancellationToken): Promise<boolean | string | {}> {

return serverUtils.runCodeAction(this._server, req).then(response => {
return serverUtils.runCodeAction(this._server, req).then(async response => {
if (response) {
return buildEditForResponse(response.Changes, this._languageMiddlewareFeature, token);
}
Expand Down
28 changes: 8 additions & 20 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { installRuntimeDependencies } from './InstallRuntimeDependencies';
import { isValidDownload } from './packageManager/isValidDownload';
import { BackgroundWorkStatusBarObserver } from './observers/BackgroundWorkStatusBarObserver';
import { getDecompilationAuthorization } from './omnisharp/decompilationPrompt';
import { getDotnetPackApi } from './DotNetPack';

export async function activate(context: vscode.ExtensionContext): Promise<CSharpExtensionExports> {

Expand Down Expand Up @@ -148,7 +149,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
return null;
}

await tryAddDotNetToPath();
// If the dotnet bundle is installed, this will ensure the dotnet CLI is on the path.
await initializeDotnetPath();

let telemetryObserver = new TelemetryObserver(platformInfo, () => reporter);
eventStream.subscribe(telemetryObserver.post);
Expand Down Expand Up @@ -229,24 +231,10 @@ async function ensureRuntimeDependencies(extension: vscode.Extension<CSharpExten
return installRuntimeDependencies(extension.packageJSON, extension.extensionPath, installDependencies, eventStream, platformInfo);
}

async function tryAddDotNetToPath() {
const sdkExtension = vscode.extensions.getExtension("ms-dotnettools.vscode-dotnet-pack");
if (sdkExtension) {
try {
if (!sdkExtension.isActive) {
await sdkExtension.activate();
}

// Invoking acquireStatus updates the process.env.PATH with the folder that contains the dotnet cli.
// This will allow child processes such as OmniSharp to use the dotnet cli.
const request = { version: '5.0', requestingExtensionId: 'ms-dotnettools.csharp' };
const statusResult = await vscode.commands.executeCommand<{ dotnetPath: string }>('dotnet-sdk.acquireStatus', request);

return statusResult.dotnetPath?.length > 0;
}
catch {
}
async function initializeDotnetPath() {
const dotnetPackApi = await getDotnetPackApi();
if (!dotnetPackApi) {
return null;
}

return false;
return await dotnetPackApi.getDotnetPath();
}

0 comments on commit dffd50b

Please sign in to comment.