Skip to content

Commit 482f109

Browse files
authored
Show Extension Guide in Experiment Group (#462)
* Show Extension Guide in Experiment Group Signed-off-by: Rome Li <[email protected]> * Add license info Signed-off-by: Rome Li <[email protected]>
1 parent 3cc6597 commit 482f109

File tree

6 files changed

+121
-0
lines changed

6 files changed

+121
-0
lines changed

package-lock.json

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
"ts-loader": "^4.3.0",
136136
"tslint": "^5.20.1",
137137
"typescript": "^3.7.5",
138+
"vscode-tas-client": "^0.1.4",
138139
"webpack": "^4.43.0",
139140
"webpack-cli": "^3.3.11"
140141
},

src/exp/index.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
import * as vscode from "vscode";
5+
import { IExperimentationService, IExperimentationTelemetry, getExperimentationService, TargetPopulation } from "vscode-tas-client";
6+
import { addContextProperty, sendInfo } from "vscode-extension-telemetry-wrapper";
7+
import { getExtensionName, getExtensionVersion } from "../utils";
8+
9+
class ExperimentationTelemetry implements IExperimentationTelemetry {
10+
11+
public setSharedProperty(name: string, value: string): void {
12+
addContextProperty(name, value);
13+
}
14+
15+
public postEvent(eventName: string, props: Map<string, string>): void {
16+
const payload: any = { __event_name__: eventName };
17+
for (const [key, value] of props) {
18+
payload[key] = value;
19+
}
20+
21+
sendInfo("", payload);
22+
}
23+
24+
}
25+
26+
let expService: IExperimentationService;
27+
28+
export function getExpService() {
29+
return expService;
30+
}
31+
32+
export function initialize(context: vscode.ExtensionContext) {
33+
expService = getExperimentationService(
34+
getExtensionName(),
35+
getExtensionVersion(),
36+
TargetPopulation.Public,
37+
new ExperimentationTelemetry(),
38+
context.globalState
39+
);
40+
}

src/extension.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { initialize as initUtils } from "./utils";
88
import { initialize as initCommands } from "./commands";
99
import { initialize as initRecommendations } from "./recommendation";
1010
import { initialize as initMisc, showReleaseNotesOnStart, HelpViewType } from "./misc";
11+
import { initialize as initExp, getExpService } from "./exp";
1112
import { showOverviewPageOnActivation } from "./overview";
1213
import { validateJavaRuntime } from "./java-runtime";
1314
// import { JavaGettingStartedViewSerializer } from "./getting-started";
@@ -23,6 +24,7 @@ async function initializeExtension(operationId: string, context: vscode.Extensio
2324
initCommands(context);
2425
initRecommendations(context);
2526
initMisc(context);
27+
initExp(context);
2628

2729
// disable webview serializer because of https://github.com/microsoft/vscode/issues/80185
2830
// context.subscriptions.push(vscode.window.registerWebviewPanelSerializer("java.overview", new OverviewViewSerializer()));
@@ -45,6 +47,12 @@ async function initializeExtension(operationId: string, context: vscode.Extensio
4547
}
4648

4749
async function presentFirstView(context: vscode.ExtensionContext) {
50+
const presentExtensionGuideByDefault: boolean = await getExpService()?.isFlightEnabledAsync("presentExtensionGuideByDefault") || false;
51+
if (presentExtensionGuideByDefault) {
52+
showExtensionGuide(context);
53+
return;
54+
}
55+
4856
const config = vscode.workspace.getConfiguration("java.help");
4957
const firstView = config.get("firstView");
5058
if (firstView === HelpViewType.GettingStarted) {
@@ -54,6 +62,15 @@ async function presentFirstView(context: vscode.ExtensionContext) {
5462
}
5563
}
5664

65+
async function showExtensionGuide(context: vscode.ExtensionContext) {
66+
if (!!context.globalState.get("isExtensionGuidePresented")) {
67+
return;
68+
}
69+
70+
await vscode.commands.executeCommand("java.extGuide");
71+
context.globalState.update("isExtensionGuidePresented", true);
72+
}
73+
5774
async function showGettingStartedView(context: vscode.ExtensionContext, isForce: boolean = false) {
5875
if (!!context.globalState.get("isGettingStartedPresented")) {
5976
return;

src/utils/extension.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
export function getExtensionName() {
5+
const packageInfo = getPackageInfo();
6+
return `${packageInfo["publisher"]}.${packageInfo["name"]}`;
7+
}
8+
9+
export function getExtensionVersion() {
10+
return getPackageInfo()["version"];
11+
}
12+
13+
function getPackageInfo() {
14+
return {} = require("../../package.json");
15+
}

src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ export async function loadTextFromFile(resourceUri: string) {
4848

4949
export * from "./command";
5050
export * from "./release-notes";
51+
export * from "./extension";

0 commit comments

Comments
 (0)