以前时不时遇到这个问题,直到昨天上 SO 搜索了一番,据说是因为文件夹太大,导致它扫描的文件过多,加载变慢。一个权宜之计是将代码文件放在子文件夹里,然后单独打开子文件夹。
我还尝试了几种其他办法,都无济于事:
- 用工作区形式打开文件夹,然后把其中比较大的数据文件夹忽略
- 重新加载窗口
- 重新安装、重启插件
5 月 3 日更新: 今天打开输出 panel,没想到里面其实已有提示:
INFO
2024-05-02 16:02:53.690 [info] [Error - 16:02:53] (62805) Enumeration of workspace source files is taking longer than 10 seconds.
This may be because:
You have opened your home directory or entire hard drive as a workspace Your workspace contains a very large number of directories and files Your workspace contains a symlink to a directory with many files Your workspace is remote, and file enumeration is slow To reduce this time, open a workspace directory with fewer files or add a pyrightconfig.json configuration file with an "exclude" section to exclude subdirectories from your workspace. For more details, refer to https://github.com/microsoft/pyright/blob/main/docs/configuration.md.
只需要在文件夹根目录下配置pyrightconfig.json
文件如下即可:
{"exclude": ["**/data"]}