{"size": 2212, "ext": "js", "max_stars_repo_path": "dbux-code/src/codeUtil/editorUtil.js", "max_stars_repo_name": "Domiii/code-dbgs", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "dbux-code/src/codeUtil/editorUtil.js", "max_issues_repo_name": "Domiii/code-dbgs", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dbux-code/src/codeUtil/editorUtil.js", "max_forks_repo_name": "Domiii/code-dbgs", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 35.6774193548, "max_line_length": 124, "alphanum_fraction": 0.650994575}
import { commands } from 'vscode';

/**
 * Close all editors in the window
 * @param {string} folderPath 
 * @returns 
 */
export async function closeAllEditors() {
  await commands.executeCommand('workbench.action.closeAllEditors');

  /**
   * NOTE: `window.visibleTextEditors` sometimes broken, there is no simple workaround to partially close the related files.
   */
  // await runTaskWithProgressBar(async (progress) => {
  //   progress.report({ message: 'Closing project related files...' });

  //   let textEditor;
  //   while (true) {
  //     if (!isInvalidEditor(textEditor, folderPath)) {
  //       textEditor = window.visibleTextEditors.find(e => isInvalidEditor(e, folderPath));
  //       if (!textEditor) {
  //         break;
  //       }
  //     }
  //     await window.showTextDocument(textEditor.document, textEditor.viewColumn);
  //     textEditor = await closeAndWaitForNextActiveEditor();
  //     console.log(`next active editor: ${textEditor?.document.uri.fsPath}`);
  //   }
  //   const visibleEditors = window.visibleTextEditors;
  //   for (const editor of visibleEditors) {
  //     let currentEditor = editor;
  //     await window.showTextDocument(currentEditor.document, currentEditor.viewColumn);
  //     while (isInvalidEditor(currentEditor, folderPath)) {
  //       await commands.executeCommand('workbench.action.closeActiveEditor');
  //       currentEditor = await waitForNextActiveEditor();
  //     }
  //   }
  // }, { cancellable: false });
}

// /**
//  * Determine if the editor should be closed.
//  * @param {import('vscode').TextEditor} editor 
//  * @param {string} folderPath 
//  * @returns 
//  */
// function isInvalidEditor(editor, folderPath) {
//   if (editor?.document.uri.scheme === 'file' && isFileInPath(folderPath, editor.document.uri.fsPath)) {
//     return true;
//   }
//   return false;
// }

// async function closeAndWaitForNextActiveEditor() {
//   return new Promise((resolve, reject) => {
//     const subscription = window.onDidChangeActiveTextEditor((editor) => {
//       subscription.dispose();
//       resolve(editor);
//     });
//     commands.executeCommand('workbench.action.closeActiveEditor').catch(reject);
//   });
// }