-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathextension.ts
More file actions
141 lines (125 loc) · 5.96 KB
/
extension.ts
File metadata and controls
141 lines (125 loc) · 5.96 KB
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import * as fs from "fs";
import * as path from "path";
import * as vscode from "vscode";
import { dispose as disposeTelemetryWrapper, initialize, instrumentOperation, sendInfo } from "vscode-extension-telemetry-wrapper";
import { BeginnerTipsViewSerializer } from "./beginner-tips";
import { ClassPathConfigurationViewSerializer } from "./classpath/classpathConfigurationView";
import { initialize as initCommands } from "./commands";
import { initDaemon } from "./daemon";
import { initialize as initExp } from "./exp";
import { JavaExtGuideViewSerializer } from "./ext-guide";
import { initFormatterSettingsEditorProvider } from "./formatter-settings";
import { initRemoteProfileProvider } from "./formatter-settings/RemoteProfileProvider";
import { InstallJdkViewSerializer } from "./install-jdk";
import { JavaRuntimeViewSerializer, validateJavaRuntime } from "./java-runtime";
import { HelpViewType, showReleaseNotesOnStart } from "./misc";
import { OverviewViewSerializer } from "./overview";
import { CodeActionProvider } from "./providers/CodeActionProvider";
import { initialize as initRecommendations } from "./recommendation";
import { initialize as initUtils } from "./utils";
import { KEY_SHOW_WHEN_USING_JAVA } from "./utils/globalState";
import { scheduleAction } from "./utils/scheduler";
import { showWelcomeWebview, WelcomeViewSerializer } from "./welcome";
import { promisify } from "util";
let cleanJavaWorkspaceIndicator: string;
export let activatingTimestamp: number;
export async function activate(context: vscode.ExtensionContext) {
activatingTimestamp = performance.now();
// monitor the startup time at very beginning in case we miss the activation of java extension.
recordStartupTime();
syncState(context);
initializeTelemetry(context);
// initialize exp service ahead of activation operation to make sure exp context properties are set.
await initExp(context);
await instrumentOperation("activation", initializeExtension)(context);
}
async function initializeExtension(_operationId: string, context: vscode.ExtensionContext) {
initFormatterSettingsEditorProvider(context);
initRemoteProfileProvider(context);
initUtils(context);
initCommands(context);
initRecommendations(context);
initDaemon(context);
if(context.storageUri) {
const javaWorkspaceStoragePath = path.join(context.storageUri.fsPath, "..", "redhat.java");
cleanJavaWorkspaceIndicator = path.join(javaWorkspaceStoragePath, "jdt_ws", ".cleanWorkspace");
}
context.subscriptions.push(vscode.languages.registerCodeActionsProvider({ scheme: "file", language: "java", pattern: "**/*.java" }, new CodeActionProvider()));
// webview serializers to restore pages
context.subscriptions.push(vscode.window.registerWebviewPanelSerializer("java.extGuide", new JavaExtGuideViewSerializer()));
context.subscriptions.push(vscode.window.registerWebviewPanelSerializer("java.overview", new OverviewViewSerializer()));
context.subscriptions.push(vscode.window.registerWebviewPanelSerializer("java.runtime", new JavaRuntimeViewSerializer()));
context.subscriptions.push(vscode.window.registerWebviewPanelSerializer("java.gettingStarted", new BeginnerTipsViewSerializer(context)));
context.subscriptions.push(vscode.window.registerWebviewPanelSerializer("java.welcome", new WelcomeViewSerializer()));
context.subscriptions.push(vscode.window.registerWebviewPanelSerializer("java.classpathConfiguration", new ClassPathConfigurationViewSerializer()));
context.subscriptions.push(vscode.window.registerWebviewPanelSerializer("java.installJdk", new InstallJdkViewSerializer(context)));
const config = vscode.workspace.getConfiguration("java.help");
if (config.get("firstView") !== HelpViewType.None && context.globalState.get(KEY_SHOW_WHEN_USING_JAVA)) {
scheduleAction("showFirstView", true).then(() => {
presentFirstView(context);
});
}
if (config.get("showReleaseNotes")) {
scheduleAction("showReleaseNotes").then(() => {
showReleaseNotesOnStart(context);
});
}
if (!await validateJavaRuntime()) {
scheduleAction("showJdkState", true, true).then(() => {
vscode.commands.executeCommand("java.runtime");
});
}
}
async function presentFirstView(context: vscode.ExtensionContext) {
await showWelcomeWebview(context);
}
function syncState(_context: vscode.ExtensionContext): void {
_context.globalState.setKeysForSync([KEY_SHOW_WHEN_USING_JAVA]);
}
function initializeTelemetry(_context: vscode.ExtensionContext) {
const ext = vscode.extensions.getExtension("vscjava.vscode-java-pack");
const packageInfo = ext ? ext.packageJSON : undefined;
if (packageInfo) {
if (packageInfo.aiKey) {
initialize(packageInfo.id, packageInfo.version, packageInfo.aiKey, { firstParty: true });
}
}
}
export async function deactivate() {
const now = performance.now();
const data = {
name: "sessionStatus",
time: Math.round(now - activatingTimestamp)
}
if (cleanJavaWorkspaceIndicator && fs.existsSync(cleanJavaWorkspaceIndicator)) {
data.name = "cleanJavaLSWorkspace";
}
sendInfo("", data);
await disposeTelemetryWrapper();
}
async function recordStartupTime() {
const javaExt = vscode.extensions.getExtension("redhat.java");
// only count the e2e time when java extension is not activated at the moment.
// if it's already activated, we are not clear if it is activated with pack at
// the same moment.
if (javaExt && !javaExt.isActive) {
const delay = promisify(setTimeout);
const timeout = 1 * 60 * 1000; // wait 1 min at most
let count = 0;
while(!javaExt.isActive && count < timeout) {
await delay(1000);
count += 1000;
}
if (javaExt.isActive && javaExt.exports?.serverReady) {
javaExt.exports.serverReady().then(() => {
const message = Math.round(performance.now() - activatingTimestamp).toString();
sendInfo("", {
name: "e2e-startup-time",
message,
});
});
}
}
}