|
36 | 36 | namespace Microsoft.Python.Analysis.Modules.Resolution { |
37 | 37 | internal sealed class MainModuleResolution : ModuleResolutionBase, IModuleManagement { |
38 | 38 | private readonly ConcurrentDictionary<string, IPythonModule> _specialized = new ConcurrentDictionary<string, IPythonModule>(); |
| 39 | + private IModuleDatabaseService _dbService; |
39 | 40 | private IRunningDocumentTable _rdt; |
40 | 41 |
|
41 | 42 | public MainModuleResolution(string root, IServiceContainer services) |
@@ -76,11 +77,6 @@ protected override IPythonModule CreateModule(string name) { |
76 | 77 | } |
77 | 78 | } |
78 | 79 |
|
79 | | - var dbs = _services.GetService<IModuleDatabaseService>(); |
80 | | - if (dbs != null && dbs.TryCreateModule(name, moduleImport.ModulePath, out var m) != ModuleStorageState.DoesNotExist && m != null) { |
81 | | - return m; |
82 | | - } |
83 | | - |
84 | 80 | // If there is a stub, make sure it is loaded and attached |
85 | 81 | // First check stub next to the module. |
86 | 82 | if (!TryCreateModuleStub(name, moduleImport.ModulePath, out var stub)) { |
@@ -156,8 +152,17 @@ public IPythonModule SpecializeModule(string name, Func<string, IPythonModule> s |
156 | 152 | /// <summary> |
157 | 153 | /// Returns specialized module, if any. |
158 | 154 | /// </summary> |
159 | | - public IPythonModule GetSpecializedModule(string name) |
160 | | - => _specialized.TryGetValue(name, out var module) ? module : null; |
| 155 | + public IPythonModule GetSpecializedModule(string fullName, string modulePath = null) { |
| 156 | + if (_specialized.TryGetValue(fullName, out var module)) { |
| 157 | + return module; |
| 158 | + } |
| 159 | + var dbs = GetDbService(); |
| 160 | + if (dbs != null && dbs.TryCreateModule(fullName, modulePath, out module) != ModuleStorageState.DoesNotExist && module != null) { |
| 161 | + SpecializeModule(fullName, s => module); |
| 162 | + return module; |
| 163 | + } |
| 164 | + return null; |
| 165 | + } |
161 | 166 |
|
162 | 167 | internal async Task LoadBuiltinTypesAsync(CancellationToken cancellationToken = default) { |
163 | 168 | var analyzer = _services.GetService<IPythonAnalyzer>(); |
@@ -237,5 +242,8 @@ private bool TryCreateModuleStub(string name, string modulePath, out IPythonModu |
237 | 242 |
|
238 | 243 | private IRunningDocumentTable GetRdt() |
239 | 244 | => _rdt ?? (_rdt = _services.GetService<IRunningDocumentTable>()); |
| 245 | + |
| 246 | + private IModuleDatabaseService GetDbService() |
| 247 | + => _dbService ?? (_dbService = _services.GetService<IModuleDatabaseService>()); |
240 | 248 | } |
241 | 249 | } |
0 commit comments