终于搞清 VS Code 打开项目时 Git 的加载逻辑,终于不用忍受打开项目时 Git 一次性加载 50 个 Git 库的卡爆。
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 - subFolders和scanRepositories影响 ;- 以上操作都会调用的
openRepository(),影响项有ignoredRepositories; - 基本的
open()操作,影响项有detectSubmodules和detectSubmodulesLimit;
所以,先 autoRepositoryDetection 和 scanRepositories 定总量,再 ignoredRepositories、detectSubmodules 和 detectSubmodulesLimit 筛部分。