Skip to content

Commit

Permalink
feat: 🔊 fallback unique id when vscode returns someValue.machineId
Browse files Browse the repository at this point in the history
  • Loading branch information
sestinj committed Aug 29, 2023
1 parent 60d1e9a commit c479442
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
11 changes: 11 additions & 0 deletions extension/package-lock.json

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

1 change: 1 addition & 0 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
"fkill": "^8.1.0",
"highlight.js": "^11.7.0",
"highlightable": "^1.3.0-beta.0",
"node-machine-id": "^1.1.12",
"posthog-node": "^3.1.2",
"react-markdown": "^8.0.7",
"react-redux": "^8.0.5",
Expand Down
8 changes: 6 additions & 2 deletions extension/src/continueIdeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import {
showSuggestion as showSuggestionInEditor,
SuggestionRanges,
} from "./suggestions";
import { openEditorAndRevealRange, uriFromFilePath } from "./util/vscode";
import {
getUniqueId,
openEditorAndRevealRange,
uriFromFilePath,
} from "./util/vscode";
import { FileEdit } from "../schema/FileEdit";
import { RangeInFile } from "../schema/RangeInFile";
import * as vscode from "vscode";
Expand Down Expand Up @@ -367,7 +371,7 @@ class IdeProtocolClient {
}

getUniqueId() {
return vscode.env.machineId;
return getUniqueId();
}

// ------------------------------------ //
Expand Down
3 changes: 2 additions & 1 deletion extension/src/debugPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getContinueServerUrl } from "./bridge";
import {
getExtensionUri,
getNonce,
getUniqueId,
openEditorAndRevealRange,
} from "./util/vscode";
import { RangeInFile } from "../schema/RangeInFile";
Expand Down Expand Up @@ -183,7 +184,7 @@ export function setupDebugPanel(
const sessionId = await sessionIdPromise;
panel.webview.postMessage({
type: "onLoad",
vscMachineId: vscode.env.machineId,
vscMachineId: getUniqueId(),
apiUrl: getContinueServerUrl(),
workspacePaths: vscode.workspace.workspaceFolders?.map(
(folder) => folder.uri.fsPath
Expand Down
5 changes: 3 additions & 2 deletions extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import * as vscode from "vscode";
import { getExtensionVersion } from "./activation/environmentSetup";
import { getUniqueId } from "./util/vscode";

let client: any = undefined;
async function capture(args: any) {
Expand All @@ -21,7 +22,7 @@ async function dynamicImportAndActivate(context: vscode.ExtensionContext) {
if (!context.globalState.get("hasBeenInstalled")) {
context.globalState.update("hasBeenInstalled", true);
capture({
distinctId: vscode.env.machineId,
distinctId: getUniqueId(),
event: "install",
properties: {
extensionVersion: getExtensionVersion(),
Expand Down Expand Up @@ -57,7 +58,7 @@ export function activate(context: vscode.ExtensionContext) {

export function deactivate() {
capture({
distinctId: vscode.env.machineId,
distinctId: getUniqueId(),
event: "deactivate",
properties: {
extensionVersion: getExtensionVersion(),
Expand Down
9 changes: 9 additions & 0 deletions extension/src/util/vscode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from "vscode";
import { machineIdSync } from "node-machine-id";

export function translate(range: vscode.Range, lines: number): vscode.Range {
return new vscode.Range(
Expand Down Expand Up @@ -115,3 +116,11 @@ export function uriFromFilePath(filepath: string): vscode.Uri {
return vscode.Uri.file(filepath);
}
}

export function getUniqueId() {
const id = vscode.env.machineId;
if (id === "someValue.machineId") {
return machineIdSync();
}
return vscode.env.machineId;
}

0 comments on commit c479442

Please sign in to comment.