()
| 949 | } |
| 950 | |
| 951 | function getVSCodeIDECommandByParentProcess(): string | null { |
| 952 | try { |
| 953 | const platform = getPlatform() |
| 954 | |
| 955 | // Only supported on OSX, where Cursor has the ability to |
| 956 | // register itself as the 'code' command. |
| 957 | if (platform !== 'macos') { |
| 958 | return null |
| 959 | } |
| 960 | |
| 961 | let pid = process.ppid |
| 962 | |
| 963 | // Walk up the process tree to find the actual app |
| 964 | for (let i = 0; i < 10; i++) { |
| 965 | if (!pid || pid === 0 || pid === 1) break |
| 966 | |
| 967 | // Get the command for this PID |
| 968 | // this function already returned if not running on macos |
| 969 | const command = execSyncWithDefaults_DEPRECATED( |
| 970 | // eslint-disable-next-line custom-rules/no-direct-ps-commands |
| 971 | `ps -o command= -p ${pid}`, |
| 972 | )?.trim() |
| 973 | |
| 974 | if (command) { |
| 975 | // Check for known applications and extract the path up to and including .app |
| 976 | const appNames = { |
| 977 | 'Visual Studio Code.app': 'code', |
| 978 | 'Cursor.app': 'cursor', |
| 979 | 'Windsurf.app': 'windsurf', |
| 980 | 'Visual Studio Code - Insiders.app': 'code', |
| 981 | 'VSCodium.app': 'codium', |
| 982 | } |
| 983 | const pathToExecutable = '/Contents/MacOS/Electron' |
| 984 | |
| 985 | for (const [appName, executableName] of Object.entries(appNames)) { |
| 986 | const appIndex = command.indexOf(appName + pathToExecutable) |
| 987 | if (appIndex !== -1) { |
| 988 | // Extract the path from the beginning to the end of the .app name |
| 989 | const folderPathEnd = appIndex + appName.length |
| 990 | // These are all known VSCode variants with the same structure |
| 991 | return ( |
| 992 | command.substring(0, folderPathEnd) + |
| 993 | '/Contents/Resources/app/bin/' + |
| 994 | executableName |
| 995 | ) |
| 996 | } |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | // Get parent PID |
| 1001 | // this function already returned if not running on macos |
| 1002 | const ppidStr = execSyncWithDefaults_DEPRECATED( |
| 1003 | // eslint-disable-next-line custom-rules/no-direct-ps-commands |
| 1004 | `ps -o ppid= -p ${pid}`, |
| 1005 | )?.trim() |
| 1006 | if (!ppidStr) { |
| 1007 | break |
| 1008 | } |
no test coverage detected