Skip to content

Commit f191fbd

Browse files
authored
Use telemetry wrapper to unify BI format. (#417)
* Use telemetry wrapper to unify BI format. * Turn off debug mode. * Resolve comments: not export help function.
1 parent 8eb2078 commit f191fbd

File tree

4 files changed

+99
-17
lines changed

4 files changed

+99
-17
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@
393393
"dependencies": {
394394
"lodash": "^4.17.10",
395395
"opn": "^5.3.0",
396-
"vscode-extension-telemetry": "0.0.18"
396+
"vscode-extension-telemetry": "0.0.18",
397+
"vscode-extension-telemetry-wrapper": "^0.3.1"
397398
}
398399
}

src/configurationProvider.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as os from "os";
55
import * as path from "path";
66
import * as vscode from "vscode";
77

8+
import { instrumentOperation } from "vscode-extension-telemetry-wrapper";
89
import * as anchor from "./anchor";
910
import * as commands from "./commands";
1011
import { logger, Type } from "./logger";
@@ -30,20 +31,26 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
3031
// Returns an initial debug configurations based on contextual information.
3132
public provideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken):
3233
vscode.ProviderResult<vscode.DebugConfiguration[]> {
33-
return <Thenable<vscode.DebugConfiguration[]>>this.provideDebugConfigurationsAsync(folder);
34+
const provideDebugConfigurationsHandler = instrumentOperation("provideDebugConfigurations", (operationId: string) => {
35+
return <Thenable<vscode.DebugConfiguration[]>>this.provideDebugConfigurationsAsync(folder);
36+
});
37+
return provideDebugConfigurationsHandler();
3438
}
3539

3640
// Try to add all missing attributes to the debug configuration being launched.
3741
public resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, token?: vscode.CancellationToken):
3842
vscode.ProviderResult<vscode.DebugConfiguration> {
39-
this.resolveVariables(folder, config);
40-
return this.heuristicallyResolveDebugConfiguration(folder, config);
43+
const resolveDebugConfigurationHandler = instrumentOperation("resolveDebugConfiguration", (operationId: string) => {
44+
this.resolveVariables(folder, config);
45+
return this.heuristicallyResolveDebugConfiguration(folder, config);
46+
});
47+
return resolveDebugConfigurationHandler();
4148
}
4249

4350
private provideDebugConfigurationsAsync(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken) {
44-
return vscode.window.withProgress({location: vscode.ProgressLocation.Window}, (p) => {
51+
return vscode.window.withProgress({ location: vscode.ProgressLocation.Window }, (p) => {
4552
return new Promise((resolve, reject) => {
46-
p.report({message: "Auto generating configuration..."});
53+
p.report({ message: "Auto generating configuration..." });
4754
resolveMainClass(folder ? folder.uri : undefined).then((res: IMainClassOption[]) => {
4855
let cache;
4956
cache = {};
@@ -75,7 +82,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
7582
};
7683
resolve([defaultLaunchConfig, ...launchConfigs, defaultAttachConfig]);
7784
}, (ex) => {
78-
p.report({message: `failed to generate configuration. ${ex}`});
85+
p.report({ message: `failed to generate configuration. ${ex}` });
7986
reject(ex);
8087
});
8188
});
@@ -84,8 +91,8 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
8491

8592
private resolveVariables(folder: vscode.WorkspaceFolder, config: vscode.DebugConfiguration): void {
8693
// all the properties whose values are string or array of string
87-
const keys = ["mainClass", "args", "vmArgs", "modulePaths", "classPaths", "projectName",
88-
"env", "sourcePaths", "encoding", "cwd", "hostName"];
94+
const keys = ["mainClass", "args", "vmArgs", "modulePaths", "classPaths", "projectName",
95+
"env", "sourcePaths", "encoding", "cwd", "hostName"];
8996
if (!config) {
9097
return;
9198
}
@@ -225,7 +232,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
225232
* Converts an array of arguments to a string as the args and vmArgs.
226233
*/
227234
private concatArgs(args: any[]): string {
228-
return _.join(_.map(args, (arg: any): string => {
235+
return _.join(_.map(args, (arg: any): string => {
229236
const str = String(arg);
230237
// if it has quotes or spaces, use double quotes to wrap it
231238
if (/['"\s]/.test(str)) {
@@ -440,7 +447,7 @@ function resolveMainClass(workspaceUri: vscode.Uri): Promise<IMainClassOption[]>
440447

441448
function validateLaunchConfig(workspaceUri: vscode.Uri, mainClass: string, projectName: string, containsExternalClasspaths: boolean):
442449
Promise<ILaunchValidationResponse> {
443-
return <Promise<ILaunchValidationResponse>> commands.executeJavaLanguageServerCommand(commands.JAVA_VALIDATE_LAUNCHCONFIG,
450+
return <Promise<ILaunchValidationResponse>>commands.executeJavaLanguageServerCommand(commands.JAVA_VALIDATE_LAUNCHCONFIG,
444451
workspaceUri ? workspaceUri.toString() : undefined, mainClass, projectName, containsExternalClasspaths);
445452
}
446453

src/extension.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import * as path from "path";
55
import * as vscode from "vscode";
6+
import { initializeFromJsonFile, instrumentOperation } from "vscode-extension-telemetry-wrapper";
67
import * as commands from "./commands";
78
import { JavaDebugConfigurationProvider } from "./configurationProvider";
89
import { HCR_EVENT, JAVA_LANGID, USER_NOTIFICATION_EVENT } from "./constants";
@@ -11,7 +12,12 @@ import { handleHotCodeReplaceCustomEvent, initializeHotCodeReplace } from "./hot
1112
import { logger, Type } from "./logger";
1213
import * as utility from "./utility";
1314

14-
export function activate(context: vscode.ExtensionContext) {
15+
export async function activate(context: vscode.ExtensionContext) {
16+
await initializeFromJsonFile(context.asAbsolutePath("./package.json"));
17+
await instrumentOperation("activation", initializeExtension)(context);
18+
}
19+
20+
function initializeExtension(operationId: string, context: vscode.ExtensionContext) {
1521
logger.initialize(context);
1622
logger.log(Type.ACTIVATEEXTENSION, {}); // TODO: Activation belongs to usage data, remove this line.
1723
logger.log(Type.USAGEDATA, {
@@ -39,7 +45,7 @@ export function activate(context: vscode.ExtensionContext) {
3945
});
4046

4147
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider("java", new JavaDebugConfigurationProvider()));
42-
context.subscriptions.push(vscode.commands.registerCommand("JavaDebug.SpecifyProgramArgs", async () => {
48+
context.subscriptions.push(instrumentAndRegisterCommand("JavaDebug.SpecifyProgramArgs", async () => {
4349
return specifyProgramArguments(context);
4450
}));
4551
initializeHotCodeReplace(context);
@@ -102,3 +108,8 @@ function specifyProgramArguments(context: vscode.ExtensionContext): Thenable<str
102108
return text || " ";
103109
});
104110
}
111+
112+
function instrumentAndRegisterCommand(name: string, cb: (...args: any[]) => any) {
113+
const instrumented = instrumentOperation(name, async (_operationId, myargs) => await cb(myargs));
114+
return vscode.commands.registerCommand(name, instrumented);
115+
}

0 commit comments

Comments
 (0)