Skip to content

Commit

Permalink
feat: Added telemetry that obeys VSC telemetry settings
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljolley committed Jan 6, 2024
1 parent 9b82435 commit a18d15b
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
indent_size = 2
indent_style = tab
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
"out",
"dist",
"**/*.d.ts"
],
"extends": [
"prettier"
]
}
}
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
162 changes: 160 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,16 @@
"@vscode/test-electron": "^2.2.3",
"conventional-changelog-conventionalcommits": "^7.0.2",
"eslint": "^8.34.0",
"eslint-config-prettier": "^9.1.0",
"glob": "^8.1.0",
"mocha": "^10.2.0",
"prettier": "^3.1.1",
"semantic-release": "^22.0.1",
"semantic-release-stop-before-publish": "^1.0.0",
"semantic-release-vsce": "^5.6.1",
"typescript": "^4.9.5"
},
"dependencies": {
"@vscode/extension-telemetry": "^0.9.2"
}
}
3 changes: 3 additions & 0 deletions src/commands/collapseToDefinitions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from "vscode";
import { Telemetry } from "../telemetry";

export async function collapseToDefinitions() {
const textEditor = vscode.window.activeTextEditor;
Expand Down Expand Up @@ -29,4 +30,6 @@ export async function collapseToDefinitions() {

await vscode.commands.executeCommand("editor.unfoldAll");
await vscode.commands.executeCommand("editor.foldLevel" + levels);

Telemetry.sendTelemetryEvent("collapseToDefinitions");
}
3 changes: 3 additions & 0 deletions src/commands/toggleAllOutlining.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Telemetry } from "../telemetry";
import { collapseToDefinitions } from "./collapseToDefinitions";
import { toggleOutliningExpansion } from "./toggleOutliningExpansion";

Expand All @@ -11,4 +12,6 @@ export async function toggleAllOutlining() {
}

toggleState = !toggleState;

Telemetry.sendTelemetryEvent("toggleAllOutlining");
}
3 changes: 3 additions & 0 deletions src/commands/toggleOutliningExpansion.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from "vscode";
import { Telemetry } from "../telemetry";

export async function toggleOutliningExpansion() {
const textEditor = vscode.window.activeTextEditor;
Expand All @@ -7,4 +8,6 @@ export async function toggleOutliningExpansion() {
}

await vscode.commands.executeCommand("editor.unfoldAll");

Telemetry.sendTelemetryEvent("toggleOutliningExpansion");
}
5 changes: 5 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import * as vscode from "vscode";

import { collapseToDefinitions } from "./commands/collapseToDefinitions";
import { toggleOutliningExpansion } from "./commands/toggleOutliningExpansion";
import { toggleAllOutlining } from "./commands/toggleAllOutlining";
import { Telemetry } from "./telemetry";

export function activate(context: vscode.ExtensionContext) {
// If enabled, initialize telemetry
Telemetry.initialize(context);

const collapseToDefinitionsDisposable = vscode.commands.registerCommand(
"vscode-vs-outlining.collapseToDefinitions",
collapseToDefinitions,
Expand Down
33 changes: 33 additions & 0 deletions src/telemetry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as vscode from "vscode";
import TelemetryReporter from "@vscode/extension-telemetry";
import type {
TelemetryEventProperties,
TelemetryEventMeasurements,
} from "@vscode/extension-telemetry";

const key = "0a889129-3c63-4826-8c5b-40b268ada9b0";

export abstract class Telemetry {
private static reporter: TelemetryReporter;

public static initialize(context: vscode.ExtensionContext) {
this.reporter = Telemetry.reporter = new TelemetryReporter(key);
context.subscriptions.push(this.reporter);
}

public static sendTelemetryEvent(
eventName: string,
properties?: TelemetryEventProperties,
measurements?: TelemetryEventMeasurements,
): void {
this.reporter.sendTelemetryEvent(eventName, properties, measurements);
}

public static sendTelemetryErrorEvent(
eventName: string,
properties?: TelemetryEventProperties,
measurements?: TelemetryEventMeasurements,
): void {
this.reporter.sendTelemetryErrorEvent(eventName, properties, measurements);
}
}

0 comments on commit a18d15b

Please sign in to comment.