From 40f37f6527a322c644e1877f1a8c6ba20a6b6ba0 Mon Sep 17 00:00:00 2001 From: yanzh Date: Fri, 22 Sep 2017 16:41:24 +0800 Subject: [PATCH 1/4] periodically query usage data --- package.json | 4 ++++ src/commands.ts | 27 +++++++++++++-------------- src/extension.ts | 30 ++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 630f9601..3de29589 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "version": "0.1.0", "publisher": "vscjava", "preview": true, + "aiKey": "67d4461e-ccba-418e-8082-1bd0acfe8516", "icon": "logo.png", "keywords": [ "java", @@ -199,5 +200,8 @@ "tslint": "^5.7.0", "typescript": "^2.0.3", "vscode": "^1.1.5" + }, + "dependencies": { + "vscode-extension-telemetry": "0.0.8" } } diff --git a/src/commands.ts b/src/commands.ts index 8055969e..9279f81a 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -1,14 +1,13 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -export const VSCODE_STARTDEBUG = "vscode.startDebug"; - -export const VSCODE_ADD_DEBUGCONFIGURATION = "debug.addConfiguration"; - -export const JAVA_START_DEBUGSESSION = "vscode.java.startDebugSession"; - -export const JAVA_RESOLVE_CLASSPATH = "vscode.java.resolveClasspath"; - -export const JAVA_BUILD_WORKSPACE = "vscode.java.buildWorkspace"; - -export const JAVA_EXECUTE_WORKSPACE_COMMAND = "java.execute.workspaceCommand"; +export const VSCODE_STARTDEBUG = "vscode.startDebug"; + +export const VSCODE_ADD_DEBUGCONFIGURATION = "debug.addConfiguration"; + +export const JAVA_START_DEBUGSESSION = "vscode.java.startDebugSession"; + +export const JAVA_RESOLVE_CLASSPATH = "vscode.java.resolveClasspath"; + +export const JAVA_BUILD_WORKSPACE = "vscode.java.buildWorkspace"; + +export const JAVA_EXECUTE_WORKSPACE_COMMAND = "java.execute.workspaceCommand"; + +export const JAVA_FETCH_USAGE_DATA = "vscode.java.fetchUsageData"; diff --git a/src/extension.ts b/src/extension.ts index f3cbc0e8..7302ca81 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -4,6 +4,9 @@ import * as path from "path"; import * as vscode from "vscode"; import * as commands from "./commands"; +import TelemetryReporter from "vscode-extension-telemetry"; + +const TELEMETRY_QUERY_INTERVEL_MS = 5000; const status: any = {}; @@ -61,6 +64,29 @@ export function activate(context: vscode.ExtensionContext) { } } }); + + // Telemetry. TODO: refactor + const extensionPackage = require(context.asAbsolutePath("./package.json")); + if (extensionPackage) { + const packageInfo = { + name: extensionPackage.name, + version: extensionPackage.version, + aiKey: extensionPackage.aiKey, + }; + if (packageInfo.aiKey) { + const reporter = new TelemetryReporter(packageInfo.name, packageInfo.version, packageInfo.aiKey); + setInterval(function() { + fetchUsageData().then(ret => { + if (Array.isArray(ret) && ret.length) { + ret.forEach(entry => { + console.log(entry); + reporter.sendTelemetryEvent("usageData", entry, {}); + }); + } + }); + }, TELEMETRY_QUERY_INTERVEL_MS); + } + } } // this method is called when your extension is deactivated @@ -75,6 +101,10 @@ function resolveClasspath(mainClass, projectName) { return executeJavaLanguageServerCommand(commands.JAVA_RESOLVE_CLASSPATH, mainClass, projectName); } +function fetchUsageData() { + return executeJavaLanguageServerCommand(commands.JAVA_FETCH_USAGE_DATA); +} + function executeJavaLanguageServerCommand(...rest) { return vscode.commands.executeCommand(commands.JAVA_EXECUTE_WORKSPACE_COMMAND, ...rest); } From ed0b489c8bf7676e896c2ba0b2839039aafe5d22 Mon Sep 17 00:00:00 2001 From: Yan Zhang Date: Mon, 25 Sep 2017 08:52:23 +0800 Subject: [PATCH 2/4] add back license --- src/commands.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/commands.ts b/src/commands.ts index 9279f81a..55f9e3e5 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + export const VSCODE_STARTDEBUG = "vscode.startDebug"; export const VSCODE_ADD_DEBUGCONFIGURATION = "debug.addConfiguration"; From aab8e26a1799700aa33ee8d0e63d54f7456c6ef2 Mon Sep 17 00:00:00 2001 From: yanzh Date: Mon, 25 Sep 2017 09:55:53 +0800 Subject: [PATCH 3/4] increase usage data query interval to 60s --- src/extension.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 7302ca81..7dec1080 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -6,7 +6,7 @@ import * as vscode from "vscode"; import * as commands from "./commands"; import TelemetryReporter from "vscode-extension-telemetry"; -const TELEMETRY_QUERY_INTERVEL_MS = 5000; +const TELEMETRY_QUERY_INTERVEL_MS = 60000; const status: any = {}; @@ -79,7 +79,6 @@ export function activate(context: vscode.ExtensionContext) { fetchUsageData().then(ret => { if (Array.isArray(ret) && ret.length) { ret.forEach(entry => { - console.log(entry); reporter.sendTelemetryEvent("usageData", entry, {}); }); } From 70dd10927345a2c1e386600d0eb71fce5c34a545 Mon Sep 17 00:00:00 2001 From: yanzh Date: Mon, 25 Sep 2017 15:59:12 +0800 Subject: [PATCH 4/4] query usage data when terminating debug session --- package.json | 2 +- src/extension.ts | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 3de29589..2227486c 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "debugger" ], "engines": { - "vscode": "^1.14.0" + "vscode": "^1.15.0" }, "categories": [ "Debuggers" diff --git a/src/extension.ts b/src/extension.ts index 7dec1080..d4b44224 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -6,8 +6,6 @@ import * as vscode from "vscode"; import * as commands from "./commands"; import TelemetryReporter from "vscode-extension-telemetry"; -const TELEMETRY_QUERY_INTERVEL_MS = 60000; - const status: any = {}; export function activate(context: vscode.ExtensionContext) { @@ -65,7 +63,7 @@ export function activate(context: vscode.ExtensionContext) { } }); - // Telemetry. TODO: refactor + // Telemetry. const extensionPackage = require(context.asAbsolutePath("./package.json")); if (extensionPackage) { const packageInfo = { @@ -75,7 +73,7 @@ export function activate(context: vscode.ExtensionContext) { }; if (packageInfo.aiKey) { const reporter = new TelemetryReporter(packageInfo.name, packageInfo.version, packageInfo.aiKey); - setInterval(function() { + vscode.debug.onDidTerminateDebugSession(() => { fetchUsageData().then(ret => { if (Array.isArray(ret) && ret.length) { ret.forEach(entry => { @@ -83,7 +81,7 @@ export function activate(context: vscode.ExtensionContext) { }); } }); - }, TELEMETRY_QUERY_INTERVEL_MS); + }); } } } @@ -106,4 +104,4 @@ function fetchUsageData() { function executeJavaLanguageServerCommand(...rest) { return vscode.commands.executeCommand(commands.JAVA_EXECUTE_WORKSPACE_COMMAND, ...rest); -} +} \ No newline at end of file