Skip to content

Commit 90c6d4d

Browse files
committed
Cleanup activation to remove dead code and improve readability
1 parent 772e41b commit 90c6d4d

File tree

8 files changed

+396
-351
lines changed

8 files changed

+396
-351
lines changed

l10n/bundle.l10n.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2+
"How to setup Remote Debugging": "How to setup Remote Debugging",
3+
"The C# extension for Visual Studio Code is incompatible on {0} {1} with the VS Code Remote Extensions. To see avaliable workarounds, click on '{2}'.": "The C# extension for Visual Studio Code is incompatible on {0} {1} with the VS Code Remote Extensions. To see avaliable workarounds, click on '{2}'.",
4+
"The C# extension for Visual Studio Code is incompatible on {0} {1}.": "The C# extension for Visual Studio Code is incompatible on {0} {1}.",
25
"Update and reload": "Update and reload",
36
"The {0} extension requires at least {1} of the .NET Install Tool ({2}) extension. Please update to continue": "The {0} extension requires at least {1} of the .NET Install Tool ({2}) extension. Please update to continue",
47
"Version {0} of the .NET Install Tool ({1}) was not found, {2} will not activate.": "Version {0} of the .NET Install Tool ({1}) was not found, {2} will not activate.",
58
".NET Test Log": ".NET Test Log",
69
".NET NuGet Restore": ".NET NuGet Restore",
7-
"How to setup Remote Debugging": "How to setup Remote Debugging",
8-
"The C# extension for Visual Studio Code is incompatible on {0} {1} with the VS Code Remote Extensions. To see avaliable workarounds, click on '{2}'.": "The C# extension for Visual Studio Code is incompatible on {0} {1} with the VS Code Remote Extensions. To see avaliable workarounds, click on '{2}'.",
9-
"The C# extension for Visual Studio Code is incompatible on {0} {1}.": "The C# extension for Visual Studio Code is incompatible on {0} {1}.",
1010
"Cannot create .NET debug configurations. No workspace folder was selected.": "Cannot create .NET debug configurations. No workspace folder was selected.",
1111
"Cannot create .NET debug configurations. The server is still initializing or has exited unexpectedly.": "Cannot create .NET debug configurations. The server is still initializing or has exited unexpectedly.",
1212
"Cannot create .NET debug configurations. The active C# project is not within folder '{0}'.": "Cannot create .NET debug configurations. The active C# project is not within folder '{0}'.",

src/activateOmniSharp.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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 vscode from 'vscode';
7+
import { OmnisharpExtensionExports } from './csharpExtensionExports';
8+
import { PlatformInformation } from './shared/platform';
9+
import { Observable } from 'rxjs';
10+
import { NetworkSettingsProvider } from './networkSettings';
11+
import TelemetryReporter from '@vscode/extension-telemetry';
12+
import { activateOmniSharpLanguageServer } from './omnisharp/omnisharpLanguageServer';
13+
import { EventStream } from './eventStream';
14+
import { razorOptions } from './shared/options';
15+
import { activateRazorExtension } from './razor/razor';
16+
17+
export function activateOmniSharp(
18+
context: vscode.ExtensionContext,
19+
platformInfo: PlatformInformation,
20+
optionStream: Observable<void>,
21+
networkSettingsProvider: NetworkSettingsProvider,
22+
eventStream: EventStream,
23+
csharpChannel: vscode.OutputChannel,
24+
reporter: TelemetryReporter,
25+
getCoreClrDebugPromise: (languageServerStarted: Promise<any>) => Promise<void>
26+
): OmnisharpExtensionExports {
27+
// activate language services
28+
const dotnetTestChannel = vscode.window.createOutputChannel(vscode.l10n.t('.NET Test Log'));
29+
const dotnetChannel = vscode.window.createOutputChannel(vscode.l10n.t('.NET NuGet Restore'));
30+
const omnisharpLangServicePromise = activateOmniSharpLanguageServer(
31+
context,
32+
platformInfo,
33+
optionStream,
34+
networkSettingsProvider,
35+
eventStream,
36+
csharpChannel,
37+
dotnetTestChannel,
38+
dotnetChannel,
39+
reporter
40+
);
41+
42+
let omnisharpRazorPromise: Promise<void> | undefined = undefined;
43+
if (!razorOptions.razorDevMode) {
44+
omnisharpRazorPromise = activateRazorExtension(
45+
context,
46+
context.extension.extensionPath,
47+
eventStream,
48+
reporter,
49+
undefined,
50+
platformInfo,
51+
/* useOmnisharpServer */ true
52+
);
53+
}
54+
55+
const coreClrDebugPromise = getCoreClrDebugPromise(omnisharpLangServicePromise);
56+
57+
const exports: OmnisharpExtensionExports = {
58+
initializationFinished: async () => {
59+
const langService = await omnisharpLangServicePromise;
60+
await langService!.server.waitForInitialize();
61+
await coreClrDebugPromise;
62+
63+
if (omnisharpRazorPromise) {
64+
await omnisharpRazorPromise;
65+
}
66+
},
67+
getAdvisor: async () => {
68+
const langService = await omnisharpLangServicePromise;
69+
return langService!.advisor;
70+
},
71+
getTestManager: async () => {
72+
const langService = await omnisharpLangServicePromise;
73+
return langService!.testManager;
74+
},
75+
eventStream,
76+
logDirectory: context.logUri.fsPath,
77+
};
78+
79+
return exports;
80+
}

src/activateRoslyn.ts

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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 vscode from 'vscode';
7+
import { CSharpExtensionExports } from './csharpExtensionExports';
8+
import { activateRazorExtension } from './razor/razor';
9+
import { PlatformInformation } from './shared/platform';
10+
import { Observable } from 'rxjs';
11+
import { EventStream } from './eventStream';
12+
import TelemetryReporter from '@vscode/extension-telemetry';
13+
import { RoslynLanguageServer } from './lsptoolshost/server/roslynLanguageServer';
14+
import { CSharpDevKitExports } from './csharpDevKitExports';
15+
import { RoslynLanguageServerEvents, ServerState } from './lsptoolshost/server/languageServerEvents';
16+
import { activateRoslynLanguageServer } from './lsptoolshost/activate';
17+
import Descriptors from './lsptoolshost/solutionSnapshot/descriptors';
18+
import { getBrokeredServiceContainer } from './lsptoolshost/serviceBroker/brokeredServicesHosting';
19+
import { debugSessionTracker } from './coreclrDebug/provisionalDebugSessionTracker';
20+
import { RoslynLanguageServerExport } from './lsptoolshost/extensions/roslynLanguageServerExportChannel';
21+
import { BlazorDebugConfigurationProvider } from './razor/src/blazorDebug/blazorDebugConfigurationProvider';
22+
import { languageServerOptions } from './shared/options';
23+
import { csharpDevkitExtensionId } from './utils/getCSharpDevKit';
24+
import { GlobalBrokeredServiceContainer } from '@microsoft/servicehub-framework';
25+
import { SolutionSnapshotProvider } from './lsptoolshost/solutionSnapshot/solutionSnapshotProvider';
26+
import { BuildResultDiagnostics } from './lsptoolshost/diagnostics/buildResultReporterService';
27+
import { getComponentFolder } from './lsptoolshost/extensions/builtInComponents';
28+
29+
export function activateRoslyn(
30+
context: vscode.ExtensionContext,
31+
platformInfo: PlatformInformation,
32+
optionStream: Observable<void>,
33+
eventStream: EventStream,
34+
csharpChannel: vscode.LogOutputChannel,
35+
reporter: TelemetryReporter,
36+
csharpDevkitExtension: vscode.Extension<CSharpDevKitExports> | undefined,
37+
getCoreClrDebugPromise: (languageServerStarted: Promise<any>) => Promise<void>
38+
): CSharpExtensionExports {
39+
const roslynLanguageServerEvents = new RoslynLanguageServerEvents();
40+
context.subscriptions.push(roslynLanguageServerEvents);
41+
42+
// Activate Razor. Needs to be activated before Roslyn so commands are registered in the correct order.
43+
// Otherwise, if Roslyn starts up first, they could execute commands that don't yet exist on Razor's end.
44+
//
45+
// Flow:
46+
// Razor starts up and registers dynamic file info commands ->
47+
// Roslyn starts up and registers Razor-specific didOpen/didClose/didChange commands and sends request to Razor
48+
// for dynamic file info once project system is ready ->
49+
// Razor sends didOpen commands to Roslyn for generated docs and responds to request with dynamic file info
50+
const razorLanguageServerStartedPromise = activateRazorExtension(
51+
context,
52+
context.extension.extensionPath,
53+
eventStream,
54+
reporter,
55+
csharpDevkitExtension,
56+
platformInfo,
57+
/* useOmnisharpServer */ false
58+
);
59+
60+
// Setup a listener for project initialization complete before we start the server.
61+
const projectInitializationCompletePromise = new Promise<void>((resolve, _) => {
62+
roslynLanguageServerEvents.onServerStateChange(async (e) => {
63+
if (e.state === ServerState.ProjectInitializationComplete) {
64+
resolve();
65+
}
66+
});
67+
});
68+
69+
// Start the server, but do not await the completion to avoid blocking activation.
70+
const roslynLanguageServerStartedPromise = activateRoslynLanguageServer(
71+
context,
72+
platformInfo,
73+
optionStream,
74+
csharpChannel,
75+
reporter,
76+
roslynLanguageServerEvents
77+
);
78+
79+
debugSessionTracker.initializeDebugSessionHandlers(context);
80+
tryGetCSharpDevKitExtensionExports(csharpDevkitExtension, csharpChannel);
81+
const coreClrDebugPromise = getCoreClrDebugPromise(roslynLanguageServerStartedPromise);
82+
83+
const languageServerExport = new RoslynLanguageServerExport(roslynLanguageServerStartedPromise);
84+
const exports: CSharpExtensionExports = {
85+
initializationFinished: async () => {
86+
await coreClrDebugPromise;
87+
await razorLanguageServerStartedPromise;
88+
await roslynLanguageServerStartedPromise;
89+
await projectInitializationCompletePromise;
90+
},
91+
profferBrokeredServices: (container) =>
92+
profferBrokeredServices(context, container, roslynLanguageServerStartedPromise!),
93+
logDirectory: context.logUri.fsPath,
94+
determineBrowserType: BlazorDebugConfigurationProvider.determineBrowserType,
95+
experimental: {
96+
sendServerRequest: async (t, p, ct) => await languageServerExport.sendRequest(t, p, ct),
97+
languageServerEvents: roslynLanguageServerEvents,
98+
},
99+
getComponentFolder: (componentName) => {
100+
return getComponentFolder(componentName, languageServerOptions);
101+
},
102+
};
103+
104+
return exports;
105+
}
106+
107+
/**
108+
* This method will try to get the CSharpDevKitExports through a thenable promise,
109+
* awaiting `activate` will cause this extension's activation to hang.
110+
*/
111+
function tryGetCSharpDevKitExtensionExports(
112+
csharpDevKit: vscode.Extension<CSharpDevKitExports> | undefined,
113+
csharpChannel: vscode.LogOutputChannel
114+
): void {
115+
csharpDevKit?.activate().then(
116+
async (exports: CSharpDevKitExports) => {
117+
if (exports && exports.serviceBroker) {
118+
// When proffering this IServiceBroker into our own container,
119+
// we list the monikers of the brokered services we expect to find there.
120+
// This list must be a subset of the monikers previously registered with our own container
121+
// as defined in the getBrokeredServiceContainer function.
122+
getBrokeredServiceContainer().profferServiceBroker(exports.serviceBroker, [
123+
Descriptors.dotnetDebugConfigurationService.moniker,
124+
]);
125+
126+
// Notify the vsdbg configuration provider that C# dev kit has been loaded.
127+
exports.serverProcessLoaded(async () => {
128+
await debugSessionTracker.onCsDevKitInitialized(await exports.getBrokeredServiceServerPipeName());
129+
});
130+
131+
await vscode.commands.executeCommand('setContext', 'dotnet.debug.serviceBrokerAvailable', true);
132+
} else {
133+
csharpChannel.error(`'${csharpDevkitExtensionId}' activated but did not return expected Exports.`);
134+
}
135+
},
136+
() => {
137+
csharpChannel.error(`Failed to activate '${csharpDevkitExtensionId}'`);
138+
}
139+
);
140+
}
141+
142+
function profferBrokeredServices(
143+
context: vscode.ExtensionContext,
144+
serviceContainer: GlobalBrokeredServiceContainer,
145+
languageServerPromise: Promise<RoslynLanguageServer>
146+
) {
147+
context.subscriptions.push(
148+
serviceContainer.profferServiceFactory(
149+
Descriptors.solutionSnapshotProviderRegistration,
150+
(_mk, _op, _sb) => new SolutionSnapshotProvider(languageServerPromise)
151+
),
152+
serviceContainer.profferServiceFactory(
153+
Descriptors.csharpExtensionBuildResultService,
154+
(_mk, _op, _sb) => new BuildResultDiagnostics(languageServerPromise)
155+
)
156+
);
157+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 vscode from 'vscode';
7+
import { lt } from 'semver';
8+
9+
export const DotNetRuntimeExtensionId = 'ms-dotnettools.vscode-dotnet-runtime';
10+
const requiredDotNetRuntimeExtensionVersion = '2.2.3';
11+
12+
export async function checkDotNetRuntimeExtensionVersion(context: vscode.ExtensionContext): Promise<void> {
13+
const dotnetRuntimeExtension = vscode.extensions.getExtension(DotNetRuntimeExtensionId);
14+
const dotnetRuntimeExtensionVersion = dotnetRuntimeExtension?.packageJSON.version;
15+
if (lt(dotnetRuntimeExtensionVersion, requiredDotNetRuntimeExtensionVersion)) {
16+
const button = vscode.l10n.t('Update and reload');
17+
const prompt = vscode.l10n.t(
18+
'The {0} extension requires at least {1} of the .NET Install Tool ({2}) extension. Please update to continue',
19+
context.extension.packageJSON.displayName,
20+
requiredDotNetRuntimeExtensionVersion,
21+
DotNetRuntimeExtensionId
22+
);
23+
const selection = await vscode.window.showErrorMessage(prompt, button);
24+
if (selection === button) {
25+
await vscode.commands.executeCommand('workbench.extensions.installExtension', DotNetRuntimeExtensionId);
26+
await vscode.commands.executeCommand('workbench.action.reloadWindow');
27+
} else {
28+
throw new Error(
29+
vscode.l10n.t(
30+
'Version {0} of the .NET Install Tool ({1}) was not found, {2} will not activate.',
31+
requiredDotNetRuntimeExtensionVersion,
32+
DotNetRuntimeExtensionId,
33+
context.extension.packageJSON.displayName
34+
)
35+
);
36+
}
37+
}
38+
}

src/checkSupportedPlatform.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 vscode from 'vscode';
7+
import { PlatformInformation } from './shared/platform';
8+
import { ActionOption, showErrorMessage } from './shared/observers/utils/showMessage';
9+
10+
export function checkIsSupportedPlatform(context: vscode.ExtensionContext, platformInfo: PlatformInformation): boolean {
11+
if (!isSupportedPlatform(platformInfo)) {
12+
// Check to see if VS Code is running remotely
13+
if (context.extension.extensionKind === vscode.ExtensionKind.Workspace) {
14+
const setupButton: ActionOption = {
15+
title: vscode.l10n.t('How to setup Remote Debugging'),
16+
action: async () => {
17+
const remoteDebugInfoURL =
18+
'https://github.com/dotnet/vscode-csharp/wiki/Remote-Debugging-On-Linux-Arm';
19+
await vscode.env.openExternal(vscode.Uri.parse(remoteDebugInfoURL));
20+
},
21+
};
22+
const errorMessage = vscode.l10n.t(
23+
`The C# extension for Visual Studio Code is incompatible on {0} {1} with the VS Code Remote Extensions. To see avaliable workarounds, click on '{2}'.`,
24+
platformInfo.platform,
25+
platformInfo.architecture,
26+
setupButton.title
27+
);
28+
showErrorMessage(vscode, errorMessage, setupButton);
29+
} else {
30+
const errorMessage = vscode.l10n.t(
31+
'The C# extension for Visual Studio Code is incompatible on {0} {1}.',
32+
platformInfo.platform,
33+
platformInfo.architecture
34+
);
35+
showErrorMessage(vscode, errorMessage);
36+
}
37+
38+
// Unsupported platform
39+
return false;
40+
}
41+
42+
return true;
43+
}
44+
45+
function isSupportedPlatform(platform: PlatformInformation): boolean {
46+
if (platform.isWindows()) {
47+
return platform.architecture === 'x86_64' || platform.architecture === 'arm64';
48+
}
49+
50+
if (platform.isMacOS()) {
51+
return true;
52+
}
53+
54+
if (platform.isLinux()) {
55+
return (
56+
platform.architecture === 'x86_64' ||
57+
platform.architecture === 'x86' ||
58+
platform.architecture === 'i686' ||
59+
platform.architecture === 'arm64'
60+
);
61+
}
62+
63+
return false;
64+
}

src/dotnetPack.ts

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

0 commit comments

Comments
 (0)