MCPcopy Create free account
hub / github.com/Noumena-Network/code / getVSCodeIDECommandByParentProcess

Function getVSCodeIDECommandByParentProcess

src/utils/ide.ts:1010–1075  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1008}
1009
1010function getVSCodeIDECommandByParentProcess(): string | null {
1011 try {
1012 const platform = getPlatform()
1013
1014 // Only supported on OSX, where Cursor has the ability to
1015 // register itself as the 'code' command.
1016 if (platform !== 'macos') {
1017 return null
1018 }
1019
1020 let pid = process.ppid
1021
1022 // Walk up the process tree to find the actual app
1023 for (let i = 0; i < 10; i++) {
1024 if (!pid || pid === 0 || pid === 1) break
1025
1026 // Get the command for this PID
1027 // this function already returned if not running on macos
1028 const command = execSyncWithDefaults_DEPRECATED(
1029 // eslint-disable-next-line custom-rules/no-direct-ps-commands
1030 `ps -o command= -p ${pid}`,
1031 )?.trim()
1032
1033 if (command) {
1034 // Check for known applications and extract the path up to and including .app
1035 const appNames = {
1036 'Visual Studio Code.app': 'code',
1037 'Cursor.app': 'cursor',
1038 'Windsurf.app': 'windsurf',
1039 'Visual Studio Code - Insiders.app': 'code',
1040 'VSCodium.app': 'codium',
1041 }
1042 const pathToExecutable = '/Contents/MacOS/Electron'
1043
1044 for (const [appName, executableName] of Object.entries(appNames)) {
1045 const appIndex = command.indexOf(appName + pathToExecutable)
1046 if (appIndex !== -1) {
1047 // Extract the path from the beginning to the end of the .app name
1048 const folderPathEnd = appIndex + appName.length
1049 // These are all known VSCode variants with the same structure
1050 return (
1051 command.substring(0, folderPathEnd) +
1052 '/Contents/Resources/app/bin/' +
1053 executableName
1054 )
1055 }
1056 }
1057 }
1058
1059 // Get parent PID
1060 // this function already returned if not running on macos
1061 const ppidStr = execSyncWithDefaults_DEPRECATED(
1062 // eslint-disable-next-line custom-rules/no-direct-ps-commands
1063 `ps -o ppid= -p ${pid}`,
1064 )?.trim()
1065 if (!ppidStr) {
1066 break
1067 }

Callers 1

getVSCodeIDECommandFunction · 0.85

Calls 3

getPlatformFunction · 0.85
entriesMethod · 0.80

Tested by

no test coverage detected