private @Nullable RunnerAndConfigurationSettings findPreferredConfiguration(@NotNull List<ExistingConfiguration> existingConfigurations,
                                                                              @NotNull PsiElement psiElement) {
    List<ConfigurationFromContext> configurationsFromContext = getConfigurationsFromContext();
    if (configurationsFromContext == null) return null;
    for (ExistingConfiguration configuration : existingConfigurations) {
      RunnerAndConfigurationSettings settings = configuration.getSettings();
      if (settings.equals(myConfiguration)) {
        return settings;
      }
      if (myRuntimeConfiguration != null && settings.getConfiguration() == myRuntimeConfiguration) {
        return settings;
      }
    }
    Set<RunnerAndConfigurationSettings> fromContextSettings =
      configurationsFromContext.stream().map(c -> c.getConfigurationSettings()).collect(Collectors.toSet());

    if (!ContainerUtil.exists(existingConfigurations, e -> fromContextSettings.contains(e.getSettings()))) {
      return null;
    }

    if (Registry.is("suggest.all.run.configurations.from.context")) {
      return null;
    }
    List<ConfigurationFromContext> contexts = ContainerUtil.mapNotNull(existingConfigurations, configuration -> {
      if (configuration.getProducer() == null || !fromContextSettings.contains(configuration.getSettings())) {
        return null;
      }
      return new ConfigurationFromContextImpl(configuration.getProducer(), configuration.getSettings(), psiElement);
    });
    if (!contexts.isEmpty()) {
      ConfigurationFromContext min = Collections.min(contexts, ConfigurationFromContext.COMPARATOR);
      return min.getConfigurationSettings();
    }
    ExistingConfiguration first = ContainerUtil.getFirstItem(existingConfigurations);
    return first != null ? first.getSettings() : null;
  }
private @Nullable RunnerAndConfigurationSettings findPreferredConfiguration(@NotNull List<ExistingConfiguration> existingConfigurations,
                                                                              @NotNull PsiElement psiElement)