From dffd50b0f5a51e501123286b6917e753d11e5b42 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Tue, 6 Apr 2021 13:44:14 -0700 Subject: [PATCH] Use the dotnet bundle api to get dotnet path --- src/DotnetPack.ts | 24 ++++++++++++++++++++++++ src/features/codeActionProvider.ts | 2 +- src/main.ts | 28 ++++++++-------------------- 3 files changed, 33 insertions(+), 21 deletions(-) create mode 100644 src/DotnetPack.ts diff --git a/src/DotnetPack.ts b/src/DotnetPack.ts new file mode 100644 index 0000000000..a462d6cd42 --- /dev/null +++ b/src/DotnetPack.ts @@ -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; +} + +export async function getDotnetPackApi(): Promise { + const dotnetExtension = vscode.extensions.getExtension(dotnetPackExtensionId); + if (!dotnetExtension) { + return null; + } + + if (!dotnetExtension.isActive) { + await dotnetExtension.activate(); + } + + return dotnetExtension.exports; +} \ No newline at end of file diff --git a/src/features/codeActionProvider.ts b/src/features/codeActionProvider.ts index 1b9059fbd8..85fb53a8d3 100644 --- a/src/features/codeActionProvider.ts +++ b/src/features/codeActionProvider.ts @@ -100,7 +100,7 @@ export default class CodeActionProvider extends AbstractProvider implements vsco private async _runCodeAction(req: protocol.V2.RunCodeActionRequest, token: vscode.CancellationToken): Promise { - 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); } diff --git a/src/main.ts b/src/main.ts index bebcbab41b..e50e005262 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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 { @@ -148,7 +149,8 @@ export async function activate(context: vscode.ExtensionContext): Promise reporter); eventStream.subscribe(telemetryObserver.post); @@ -229,24 +231,10 @@ async function ensureRuntimeDependencies(extension: vscode.Extension('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(); } \ No newline at end of file