终于搞清 VS Code 打开项目时 Git 的加载逻辑,终于不用忍受打开项目时 Git 一次性加载 50 个 Git 库的卡爆。

详见:git/src/model.ts

private async doInitialScan(): Promise<void> {
  await Promise.all([
    this.onDidChangeWorkspaceFolders({ added: workspace.workspaceFolders || [], removed: [] }),
    this.onDidChangeVisibleTextEditors(window.visibleTextEditors),
    this.scanWorkspaceFolders()
  ]);
}

主要涉及的配置有:docs/settings

{
  // Configures when repositories should be automatically detected.
  //  - true: Scan for both subfolders of the current opened folder and parent folders of open files.
  //  - false: Disable automatic repository scanning.
  //  - subFolders: Scan for subfolders of the currently opened folder.
  //  - openEditors: Scan for parent folders of open files.
  "git.autoRepositoryDetection": true,

  // List of paths to search for git repositories in.
  "git.scanRepositories": [],

  // List of git repositories to ignore.
  "git.ignoredRepositories": [],

  // Controls whether to automatically detect git submodules.
  "git.detectSubmodules": true,

  // Controls the limit of git submodules detected.
  "git.detectSubmodulesLimit": 10,
}

其中,

  • onDidChangeWorkspaceFolders() 加载 workspace.workspaceFolders 项;
  • onDidChangeVisibleTextEditors(),受 autoRepositoryDetection - openEditors 影响;
  • scanWorkspaceFolders(),受 autoRepositoryDetection - subFoldersscanRepositories 影响 ;
  • 以上操作都会调用的openRepository(),影响项有 ignoredRepositories
  • 基本的 open() 操作,影响项有 detectSubmodulesdetectSubmodulesLimit

所以,先 autoRepositoryDetectionscanRepositories 定总量,再 ignoredRepositoriesdetectSubmodulesdetectSubmodulesLimit 筛部分。


Related Posts


Published

Category

toolchains

Tags

Contact