(
onIdeDetected: (ide: DetectedIDEInfo | null) => void,
ideToInstallExtension: IdeType | null,
onShowIdeOnboarding: () => void,
onInstallationComplete: (
status: IDEExtensionInstallationStatus | null,
) => void,
)
| 1286 | * @param onInstallationComplete Callback to be called when extension installation is complete |
| 1287 | */ |
| 1288 | export async function initializeIdeIntegration( |
| 1289 | onIdeDetected: (ide: DetectedIDEInfo | null) => void, |
| 1290 | ideToInstallExtension: IdeType | null, |
| 1291 | onShowIdeOnboarding: () => void, |
| 1292 | onInstallationComplete: ( |
| 1293 | status: IDEExtensionInstallationStatus | null, |
| 1294 | ) => void, |
| 1295 | ): Promise<void> { |
| 1296 | // Don't await so we don't block startup, but return a promise that resolves with the status |
| 1297 | void findAvailableIDE().then(onIdeDetected) |
| 1298 | |
| 1299 | const shouldAutoInstall = getGlobalConfig().autoInstallIdeExtension ?? true |
| 1300 | if ( |
| 1301 | !isEnvTruthy(process.env.CLAUDE_CODE_IDE_SKIP_AUTO_INSTALL) && |
| 1302 | shouldAutoInstall |
| 1303 | ) { |
| 1304 | const ideType = ideToInstallExtension ?? getTerminalIdeType() |
| 1305 | if (ideType) { |
| 1306 | if (isVSCodeIde(ideType)) { |
| 1307 | void isIDEExtensionInstalled(ideType).then(async isAlreadyInstalled => { |
| 1308 | void maybeInstallIDEExtension(ideType) |
| 1309 | .catch(error => { |
| 1310 | const ideInstallationStatus: IDEExtensionInstallationStatus = { |
| 1311 | installed: false, |
| 1312 | error: error.message || 'Installation failed', |
| 1313 | installedVersion: null, |
| 1314 | ideType: ideType, |
| 1315 | } |
| 1316 | return ideInstallationStatus |
| 1317 | }) |
| 1318 | .then(status => { |
| 1319 | onInstallationComplete(status) |
| 1320 | |
| 1321 | if (status?.installed) { |
| 1322 | // If we installed and don't yet have an IDE, search again. |
| 1323 | void findAvailableIDE().then(onIdeDetected) |
| 1324 | } |
| 1325 | |
| 1326 | if ( |
| 1327 | !isAlreadyInstalled && |
| 1328 | status?.installed === true && |
| 1329 | !ideOnboardingDialog().hasIdeOnboardingDialogBeenShown() |
| 1330 | ) { |
| 1331 | onShowIdeOnboarding() |
| 1332 | } |
| 1333 | }) |
| 1334 | }) |
| 1335 | } else if (isJetBrainsIde(ideType)) { |
| 1336 | // Always check installation to populate the sync cache used by status notices |
| 1337 | void isIDEExtensionInstalled(ideType).then(async installed => { |
| 1338 | if ( |
| 1339 | installed && |
| 1340 | !ideOnboardingDialog().hasIdeOnboardingDialogBeenShown() |
| 1341 | ) { |
| 1342 | onShowIdeOnboarding() |
| 1343 | } |
| 1344 | }) |
| 1345 | } |
no test coverage detected