public void LoadAndUnloadModule() { var factories = new[] { InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(new Version(3, 3)) }; using (var analyzer = new VsProjectAnalyzer(PythonToolsTestUtilities.CreateMockServiceProvider(), factories[0], factories)) { var m1Path = TestData.GetPath("TestData\\SimpleImport\\module1.py"); var m2Path = TestData.GetPath("TestData\\SimpleImport\\module2.py"); var entry1 = analyzer.AnalyzeFile(m1Path) as IPythonProjectEntry; var entry2 = analyzer.AnalyzeFile(m2Path) as IPythonProjectEntry; analyzer.WaitForCompleteAnalysis(_ => true); AssertUtil.ContainsExactly( analyzer.Project.GetEntriesThatImportModule("module1", true).Select(m => m.ModuleName), "module2" ); AssertUtil.ContainsExactly( entry2.Analysis.GetValuesByIndex("x", 0).Select(v => v.TypeId), BuiltinTypeId.Int ); analyzer.UnloadFile(entry1); analyzer.WaitForCompleteAnalysis(_ => true); // Even though module1 has been unloaded, we still know that // module2 imports it. AssertUtil.ContainsExactly( analyzer.Project.GetEntriesThatImportModule("module1", true).Select(m => m.ModuleName), "module2" ); AssertUtil.ContainsExactly( entry2.Analysis.GetValuesByIndex("x", 0).Select(v => v.TypeId) ); analyzer.AnalyzeFile(m1Path); analyzer.WaitForCompleteAnalysis(_ => true); AssertUtil.ContainsExactly( analyzer.Project.GetEntriesThatImportModule("module1", true).Select(m => m.ModuleName), "module2" ); AssertUtil.ContainsExactly( entry2.Analysis.GetValuesByIndex("x", 0).Select(v => v.TypeId), BuiltinTypeId.Int ); } }
private void Reanalyze(HierarchyNode node, VsProjectAnalyzer newAnalyzer) { if (node != null) { for (var child = node.FirstChild; child != null; child = child.NextSibling) { if (child is PackageJsonFileNode) { ((PackageJsonFileNode)child).AnalyzePackageJson(newAnalyzer); } else if (child is NodejsFileNode) { if (((NodejsFileNode)child).ShouldAnalyze) { newAnalyzer.AnalyzeFile(child.Url, !child.IsNonMemberItem); } } Reanalyze(child, newAnalyzer); } } }