-
Notifications
You must be signed in to change notification settings - Fork 676
/
main.ts
243 lines (203 loc) · 12.1 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as OmniSharp from './omnisharp/extension';
import * as coreclrdebug from './coreclr-debug/activate';
import * as util from './common';
import * as vscode from 'vscode';
import { ActivationFailure, ActiveTextEditorChanged } from './omnisharp/loggingEvents';
import { WarningMessageObserver } from './observers/WarningMessageObserver';
import { CsharpChannelObserver } from './observers/CsharpChannelObserver';
import { CsharpLoggerObserver } from './observers/CsharpLoggerObserver';
import { DotNetChannelObserver } from './observers/DotnetChannelObserver';
import { DotnetLoggerObserver } from './observers/DotnetLoggerObserver';
import { EventStream } from './EventStream';
import { InformationMessageObserver } from './observers/InformationMessageObserver';
import { OmnisharpChannelObserver } from './observers/OmnisharpChannelObserver';
import { OmnisharpDebugModeLoggerObserver } from './observers/OmnisharpDebugModeLoggerObserver';
import { OmnisharpLoggerObserver } from './observers/OmnisharpLoggerObserver';
import { OmnisharpStatusBarObserver } from './observers/OmnisharpStatusBarObserver';
import { PlatformInformation } from './platform';
import { StatusBarItemAdapter } from './statusBarItemAdapter';
import { TelemetryObserver } from './observers/TelemetryObserver';
import TelemetryReporter from 'vscode-extension-telemetry';
import { addJSONProviders } from './features/json/jsonContributions';
import { ProjectStatusBarObserver } from './observers/ProjectStatusBarObserver';
import CSharpExtensionExports from './CSharpExtensionExports';
import { vscodeNetworkSettingsProvider } from './NetworkSettings';
import { ErrorMessageObserver } from './observers/ErrorMessageObserver';
import OptionProvider from './observers/OptionProvider';
import DotNetTestChannelObserver from './observers/DotnetTestChannelObserver';
import DotNetTestLoggerObserver from './observers/DotnetTestLoggerObserver';
import { ShowOmniSharpConfigChangePrompt } from './observers/OptionChangeObserver';
import createOptionStream from './observables/CreateOptionStream';
import { CSharpExtensionId } from './constants/CSharpExtensionId';
import { OpenURLObserver } from './observers/OpenURLObserver';
import { activateRazorExtension } from './razor/razor';
import { RazorLoggerObserver } from './observers/RazorLoggerObserver';
import { AbsolutePathPackage } from './packageManager/AbsolutePathPackage';
import { downloadAndInstallPackages } from './packageManager/downloadAndInstallPackages';
import IInstallDependencies from './packageManager/IInstallDependencies';
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> {
const extensionId = CSharpExtensionId;
const extension = vscode.extensions.getExtension<CSharpExtensionExports>(extensionId);
const extensionVersion = extension.packageJSON.version;
const aiKey = extension.packageJSON.contributes.debuggers[0].aiKey;
const reporter = new TelemetryReporter(extensionId, extensionVersion, aiKey);
util.setExtensionPath(extension.extensionPath);
const eventStream = new EventStream();
const optionStream = createOptionStream(vscode);
let optionProvider = new OptionProvider(optionStream);
let dotnetChannel = vscode.window.createOutputChannel('.NET');
let dotnetChannelObserver = new DotNetChannelObserver(dotnetChannel);
let dotnetLoggerObserver = new DotnetLoggerObserver(dotnetChannel);
eventStream.subscribe(dotnetChannelObserver.post);
eventStream.subscribe(dotnetLoggerObserver.post);
let dotnetTestChannel = vscode.window.createOutputChannel(".NET Test Log");
let dotnetTestChannelObserver = new DotNetTestChannelObserver(dotnetTestChannel);
let dotnetTestLoggerObserver = new DotNetTestLoggerObserver(dotnetTestChannel);
eventStream.subscribe(dotnetTestChannelObserver.post);
eventStream.subscribe(dotnetTestLoggerObserver.post);
let csharpChannel = vscode.window.createOutputChannel('C#');
let csharpchannelObserver = new CsharpChannelObserver(csharpChannel);
let csharpLogObserver = new CsharpLoggerObserver(csharpChannel);
eventStream.subscribe(csharpchannelObserver.post);
eventStream.subscribe(csharpLogObserver.post);
let omnisharpChannel = vscode.window.createOutputChannel('OmniSharp Log');
let omnisharpLogObserver = new OmnisharpLoggerObserver(omnisharpChannel);
let omnisharpChannelObserver = new OmnisharpChannelObserver(omnisharpChannel, vscode);
eventStream.subscribe(omnisharpLogObserver.post);
eventStream.subscribe(omnisharpChannelObserver.post);
let warningMessageObserver = new WarningMessageObserver(vscode, () => optionProvider.GetLatestOptions().disableMSBuildDiagnosticWarning || false);
eventStream.subscribe(warningMessageObserver.post);
let informationMessageObserver = new InformationMessageObserver(vscode);
eventStream.subscribe(informationMessageObserver.post);
let errorMessageObserver = new ErrorMessageObserver(vscode);
eventStream.subscribe(errorMessageObserver.post);
let omnisharpStatusBar = new StatusBarItemAdapter(vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, Number.MIN_VALUE + 2));
omnisharpStatusBar.name = "C# Language Service Status";
let omnisharpStatusBarObserver = new OmnisharpStatusBarObserver(omnisharpStatusBar);
eventStream.subscribe(omnisharpStatusBarObserver.post);
let projectStatusBar = new StatusBarItemAdapter(vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, Number.MIN_VALUE + 1));
projectStatusBar.name = "C# Project Selector";
let projectStatusBarObserver = new ProjectStatusBarObserver(projectStatusBar);
eventStream.subscribe(projectStatusBarObserver.post);
let backgroundWorkStatusBar = new StatusBarItemAdapter(vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, Number.MIN_VALUE));
backgroundWorkStatusBar.name = "C# Code Analysis";
let backgroundWorkStatusBarObserver = new BackgroundWorkStatusBarObserver(backgroundWorkStatusBar);
eventStream.subscribe(backgroundWorkStatusBarObserver.post);
let openURLObserver = new OpenURLObserver(vscode);
eventStream.subscribe(openURLObserver.post);
const debugMode = false;
if (debugMode) {
let omnisharpDebugModeLoggerObserver = new OmnisharpDebugModeLoggerObserver(omnisharpChannel);
eventStream.subscribe(omnisharpDebugModeLoggerObserver.post);
}
let platformInfo: PlatformInformation;
try {
platformInfo = await PlatformInformation.GetCurrent();
}
catch (error) {
eventStream.post(new ActivationFailure());
}
if (!isSupportedPlatform(platformInfo)) {
const platform: string = platformInfo.platform ? platformInfo.platform : "this platform";
const architecture: string = platformInfo.architecture ? platformInfo.architecture : " and <unknown processor architecture>";
let errorMessage: string = `The C# extension for Visual Studio Code (powered by OmniSharp) is incompatible on ${platform} ${architecture}`;
const messageOptions: vscode.MessageOptions = {
};
// Check to see if VS Code is running remotely
if (extension.extensionKind === vscode.ExtensionKind.Workspace) {
const setupButton: string = "How to setup Remote Debugging";
errorMessage += ` with the VS Code Remote Extensions. To see avaliable workarounds, click on '${setupButton}'.`;
await vscode.window.showErrorMessage(errorMessage, messageOptions, setupButton).then((selectedItem: string) => {
if (selectedItem === setupButton) {
let remoteDebugInfoURL = 'https://github.com/OmniSharp/omnisharp-vscode/wiki/Remote-Debugging-On-Linux-Arm';
vscode.env.openExternal(vscode.Uri.parse(remoteDebugInfoURL));
}
});
} else {
await vscode.window.showErrorMessage(errorMessage, messageOptions);
}
// Unsupported platform
return null;
}
// 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);
let networkSettingsProvider = vscodeNetworkSettingsProvider(vscode);
let installDependencies: IInstallDependencies = async (dependencies: AbsolutePathPackage[]) => downloadAndInstallPackages(dependencies, networkSettingsProvider, eventStream, isValidDownload);
let runtimeDependenciesExist = await ensureRuntimeDependencies(extension, eventStream, platformInfo, installDependencies);
// Prompt to authorize decompilation in this workspace
await getDecompilationAuthorization(context, optionProvider);
// activate language services
let langServicePromise = OmniSharp.activate(context, extension.packageJSON, platformInfo, networkSettingsProvider, eventStream, optionProvider, extension.extensionPath);
// register JSON completion & hover providers for project.json
context.subscriptions.push(addJSONProviders());
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(() => {
eventStream.post(new ActiveTextEditorChanged());
}));
context.subscriptions.push(optionProvider);
context.subscriptions.push(ShowOmniSharpConfigChangePrompt(optionStream, vscode));
let coreClrDebugPromise = Promise.resolve();
if (runtimeDependenciesExist) {
// activate coreclr-debug
coreClrDebugPromise = coreclrdebug.activate(extension, context, platformInfo, eventStream);
}
let razorPromise = Promise.resolve();
if (!optionProvider.GetLatestOptions().razorDisabled) {
const razorObserver = new RazorLoggerObserver(omnisharpChannel);
eventStream.subscribe(razorObserver.post);
if (!optionProvider.GetLatestOptions().razorDevMode) {
razorPromise = activateRazorExtension(context, extension.extensionPath, eventStream);
}
}
return {
initializationFinished: async () => {
let langService = await langServicePromise;
await langService.server.waitForEmptyEventQueue();
await coreClrDebugPromise;
await razorPromise;
},
getAdvisor: async () => {
let langService = await langServicePromise;
return langService.advisor;
},
getTestManager: async () => {
let langService = await langServicePromise;
return langService.testManager;
},
eventStream
};
}
function isSupportedPlatform(platform: PlatformInformation): boolean {
if (platform.isWindows()) {
return platform.architecture === "x86" || platform.architecture === "x86_64" || platform.architecture === "arm64";
}
if (platform.isMacOS()) {
return true;
}
if (platform.isLinux()) {
return platform.architecture === "x86_64" ||
platform.architecture === "x86" ||
platform.architecture === "i686";
}
return false;
}
async function ensureRuntimeDependencies(extension: vscode.Extension<CSharpExtensionExports>, eventStream: EventStream, platformInfo: PlatformInformation, installDependencies: IInstallDependencies): Promise<boolean> {
return installRuntimeDependencies(extension.packageJSON, extension.extensionPath, installDependencies, eventStream, platformInfo);
}
async function initializeDotnetPath() {
const dotnetPackApi = await getDotnetPackApi();
if (!dotnetPackApi) {
return null;
}
return await dotnetPackApi.getDotnetPath();
}