public static void detachProject(
    @NotNull Project project,
    @NotNull ProjectSystemId projectSystemId,
    @NotNull ProjectData projectData,
    @Nullable ProjectNode projectNode
  ) {
    String externalProjectPath = projectData.getLinkedExternalProjectPath();

    ExternalSystemTelemetryUtil.runWithSpan(projectSystemId, "Remove project from local settings", __ -> {
      AbstractExternalSystemLocalSettings<?> localSettings = ExternalSystemApiUtil.getLocalSettings(project, projectSystemId);
      localSettings.forgetExternalProjects(Collections.singleton(externalProjectPath));
    });

    ExternalSystemTelemetryUtil.runWithSpan(projectSystemId, "Remove project from system settings", __ -> {
      AbstractExternalSystemSettings<?, ?, ?> settings = ExternalSystemApiUtil.getSettings(project, projectSystemId);
      settings.unlinkExternalProject(externalProjectPath);
    });

    ExternalSystemTelemetryUtil.runWithSpan(projectSystemId, "Remove project from data storage", __ -> {
      ExternalProjectsManagerImpl externalProjectsManager = ExternalProjectsManagerImpl.getInstance(project);
      externalProjectsManager.forgetExternalProjectData(projectSystemId, externalProjectPath);
    });

    ExternalSystemTelemetryUtil.runWithSpan(projectSystemId, "Remove project from tool window", __ -> {
      if (projectNode != null) {
        ExternalSystemNode<?> group = projectNode.getGroup();
        group.remove(projectNode);
      }
    });

    ExternalSystemTelemetryUtil.runWithSpan(projectSystemId, "Remove project from workspace model", __ -> {
      List<Module> orphanModules = collectExternalSystemModules(project, projectSystemId, externalProjectPath);
      if (!orphanModules.isEmpty()) {
        ProjectDataManagerImpl projectDataManager = ProjectDataManagerImpl.getInstance();
        projectDataManager.removeData(ProjectKeys.MODULE, orphanModules, Collections.emptyList(), projectData, project, false);
      }
    });
  }
public static void detachProject(
    @NotNull Project project,
    @NotNull ProjectSystemId projectSystemId,
    @NotNull ProjectData projectData,
    @Nullable ProjectNode projectNode
  )