override fun getWidgetState()

in src/org/jetbrains/r/configuration/RInterpreterStatusBarWidget.kt [70:112]


  override fun getWidgetState(file: VirtualFile?): WidgetState {
    val now = System.currentTimeMillis()
    val projectInterpreterInfo: RInterpreterInfo? = synchronized(this) {
      val (cached, lastFetchFinishedAtMillis) = cachedValue
      val fresh = lastFetchFinishedAtMillis != 0L && (now - lastFetchFinishedAtMillis) < freshnessMillis
      val promise = fetchInterpreterPromise

      when {
        fresh -> cached

        promise == null || promise.isCancelled || promise.isCompleted -> {
          fetchInterpreterPromise = RPluginCoroutineScope.getScope(project).async {
            val projectInterpreterLocation = settings.interpreterLocation
            val fetched = RInterpreterUtil.suggestAllInterpreters(true)
              .firstOrNull { it.interpreterLocation == projectInterpreterLocation }
            cachedValue = fetched to System.currentTimeMillis()
            fetched
          }
          RPluginCoroutineScope.getScope(project).async {
            fetchInterpreterPromise?.await()
            withContext(Dispatchers.EDT) { update() }
          }
          return WidgetState.NO_CHANGE
        }

        promise.isActive -> cached

        else -> return WidgetState.NO_CHANGE
      }
    }
    return if (projectInterpreterInfo == null) {
      WidgetState("", RBundle.message("interpreter.status.bar.no.interpreter"), true)
    }
    else {
      val descriptionRepresentation = projectInterpreterInfo.stringRepresentation
      val additionalSuffix = projectInterpreterInfo.interpreterLocation.additionalShortRepresentationSuffix().let {
        if (it.isNotBlank()) "($it)" else ""
      }
      val versionWithSuffix = "${projectInterpreterInfo.version} $additionalSuffix"
      WidgetState(RBundle.message("interpreter.status.bar.current.interpreter.tooltip", descriptionRepresentation),
                  RBundle.message("interpreter.status.bar.current.interpreter.name", versionWithSuffix), true)
    }
  }