private void removeRunContentWhenProcessIsTerminated(@NotNull RunContentDescriptor descriptor) {
    ProcessHandler processHandler = descriptor.getProcessHandler();
    if (processHandler != null) {
      processHandler.addProcessListener(new ProcessAdapter() {
        @Override
        public void processTerminated(@NotNull ProcessEvent event) {
          final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject);
          ToolWindow window = toolWindowManager.getToolWindow(ToolWindowId.DEBUG);
          if (window != null) {
            ContentManager contentManager = window.getContentManager();
            Content content = descriptor.getAttachedContent();
            if (content != null) {
              ApplicationManager.getApplication().invokeLater(() -> contentManager.removeContent(content, true));
            }
          }
        }
      });
    }
  }
private void removeRunContentWhenProcessIsTerminated(@NotNull RunContentDescriptor descriptor)