@@ -68,7 +68,7 @@ public partial class PythonAnalyzer : IPythonAnalyzer, IDisposable {
68
68
public static async Task < PythonAnalyzer > CreateAsync ( IPythonInterpreterFactory factory , CancellationToken token = default ) {
69
69
var analyzer = new PythonAnalyzer ( factory ) ;
70
70
try {
71
- await analyzer . ReloadModulesAsync ( token ) . ConfigureAwait ( false ) ;
71
+ await analyzer . ReloadModulesAsync ( false , token ) . ConfigureAwait ( false ) ;
72
72
} catch ( Exception ) {
73
73
analyzer . Dispose ( ) ;
74
74
throw ;
@@ -140,7 +140,9 @@ private void ReloadModulePaths(in IEnumerable<string> rootPaths) {
140
140
/// This method should be called on the analysis thread and is usually invoked
141
141
/// when the interpreter signals that it's modules have changed.
142
142
/// </summary>
143
- public async Task ReloadModulesAsync ( CancellationToken token = default ) {
143
+ public Task ReloadModulesAsync ( CancellationToken token = default ) => ReloadModulesAsync ( true , token ) ;
144
+
145
+ private async Task ReloadModulesAsync ( bool reScanRoots , CancellationToken token ) {
144
146
if ( ! _reloadLock . Wait ( 0 ) ) {
145
147
// If we don't lock immediately, wait for the current reload to
146
148
// complete and then return.
@@ -156,6 +158,11 @@ public async Task ReloadModulesAsync(CancellationToken token = default) {
156
158
InterpreterFactory . NotifyImportNamesChanged ( ) ;
157
159
// Now initialize the interpreter
158
160
Interpreter . Initialize ( this ) ;
161
+ // Rescan roots for modules if requested
162
+ if ( reScanRoots ) {
163
+ ReloadModulePaths ( CurrentPathResolver . GetRootPaths ( ) ) ;
164
+ }
165
+
159
166
// Reload importable modules
160
167
Modules . Reload ( ) ;
161
168
// Load known types from the selected interpreter
@@ -760,7 +767,7 @@ public void AnalyzeQueuedEntries(CancellationToken cancel) {
760
767
761
768
if ( _builtinModule == null ) {
762
769
Debug . Fail ( "Used analyzer without reloading modules" ) ;
763
- ReloadModulesAsync ( cancel ) . WaitAndUnwrapExceptions ( ) ;
770
+ ReloadModulesAsync ( true , cancel ) . WaitAndUnwrapExceptions ( ) ;
764
771
}
765
772
766
773
var ddg = new DDG ( ) ;
0 commit comments