private async runInstaller()

in src/server/install.ts [171:227]


  private async runInstaller(
    coursierPath: string,
    root: string,
    config: InstallConfig
  ): Promise<number | null> {
    this.outputChannel.appendLine(
      `Launching Bazel BSP installer from Maven package: ${MAVEN_PACKAGE}`
    )
    const bazelPath = path.join(root, config.bazelBinaryPath)

    // Flags to be passed to the installer.
    // See CliOptionsProvider in the server code for available options.
    const installFlags: Map<string, string> = new Map([
      // Set Bazel project details to be used if a project file is not already present.
      ['--project-view-file', config.bazelProjectFilePath],
      ['--bazel-binary', bazelPath],
      ['--targets', '//your/targets/here/...'],
    ])

    const flagsString = Array.from(installFlags.entries())
      .map(([key, value]) => `${key} "${value}"`)
      .join(' ')
    const additionalInstallFlags = getExtensionSetting(
      SettingName.ADDITIONAL_INSTALL_FLAGS
    )
    const additionalInstallFlagsString = additionalInstallFlags
      ? additionalInstallFlags.join(' ')
      : ''

    const javaVersion =
      os.platform() === 'darwin' ? TEMURIN_JAVA_17 : OPEN_JDK_JAVA_17
    this.outputChannel.appendLine(`Using Java version: ${javaVersion}`)
    const installCommand = `"${coursierPath}" launch --jvm ${javaVersion} ${MAVEN_PACKAGE}:${config.serverVersion} -M ${INSTALL_METHOD} ${additionalInstallFlagsString} -- ${flagsString}`
    this.outputChannel.appendLine(`Running command: ${installCommand}`)

    // Report progress in output channel.
    const installProcess = cp.spawn(installCommand, {cwd: root, shell: true})
    installProcess.stdout?.on('data', chunk => {
      this.outputChannel.appendLine(chunk.toString())
    })
    installProcess.stderr?.on('data', chunk => {
      this.outputChannel.appendLine(chunk.toString())
    })
    return new Promise<number | null>(resolve => {
      // Handle cases where process is already exited (e.g. tests), or exits later on.
      if (installProcess.exitCode !== null) resolve(installProcess.exitCode)
      installProcess.on('exit', code => {
        resolve(code)
      })

      // Handle cases where the process fails to start.
      installProcess.on('error', err => {
        this.outputChannel.appendLine(`Failed to start installer: ${err}`)
        resolve(null)
      })
    })
  }