Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion agent-support/vscode/src/utils/host-kind.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as vscode from "vscode";
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";

export type IDEHostConfiguration = {
Expand All @@ -19,18 +21,48 @@ export type IDEHostKind =
| typeof IDEHostKindVSCode
| typeof IDEHostKindUnknown;

/**
* Loads the list of IDE names that should be treated as VSCode by checking the configuration file.
*/
function loadVscodeIdeNames(): string[] {
try {
const filePath = path.join(os.homedir(), ".git-ai", "VSCODE_IDE_NAMES");
const content = fs.readFileSync(filePath, "utf-8");
return content
.split("\n")
.map((line: string) => line.trim().toLowerCase())
.filter((line: string) => line.length > 0);
} catch {
return [];
}
}

export function detectIDEHost(): IDEHostConfiguration {
const appName = (vscode.env.appName ?? "").toLowerCase();
const uriScheme = (vscode.env.uriScheme ?? "").toLowerCase();
const execPath = (process.execPath ?? "").toLowerCase();

const has = (s: string) => appName.includes(s) || uriScheme === s || execPath.includes(`${path.sep}${s}`);

const kind: IDEHostKind =
let kind: IDEHostKind =
has("cursor") ? "cursor" :
has("windsurf") ? "windsurf" :
has("vscodium") || uriScheme === "vscode-insiders" || uriScheme === "vscode" || appName.includes("visual studio code") ? "vscode" :
"unknown";

// If we don't recognize the IDE, check if it's a custom VSCode-like IDE that should be treated as VSCode by checking the configuration file.
if (kind === "unknown") {
const vscodeIdeNames = loadVscodeIdeNames();
if (vscodeIdeNames.length > 0) {
console.log('[git-ai] Checking for VSCode-like IDE: ', vscodeIdeNames);
if (vscodeIdeNames.some(has)) {
kind = "vscode";
console.log('[git-ai] Found VSCode-like IDE: ', kind);
}
}
} else {
console.log('[git-ai] Recognized IDE: ', kind);
}

return { kind, appName: vscode.env.appName, uriScheme: vscode.env.uriScheme, execPath: process.execPath };
}
Loading