private static void AnalyzeCode( out PythonAnalyzer analyzer, out IPythonProjectEntry entry, string code, Version preferredVersion = null, InterpreterArchitecture preferredArch = null, string module = "test-module" ) { var provider = InterpFactory; var factory = provider.GetInterpreterFactories().OrderByDescending(f => f.Configuration.Version) .Where(f => preferredVersion == null || f.Configuration.Version == preferredVersion) .Where(f => preferredArch == null || f.Configuration.Architecture == preferredArch) .FirstOrDefault(); Assert.IsNotNull(factory, "no factory found"); analyzer = PythonAnalyzer.CreateSynchronously(factory); var path = Path.Combine(TestData.GetTempPath(randomSubPath: true), module.Replace('.', '\\')); Directory.CreateDirectory(PathUtils.GetParent(path)); File.WriteAllText(path, code); entry = analyzer.AddModule(module, path); PythonAst ast; using (var p = Parser.CreateParser(new StringReader(code), factory.GetLanguageVersion())) { ast = p.ParseFile(); entry.UpdateTree(ast, null); } entry.Analyze(CancellationToken.None, true); }
public void UpdateModule(IPythonProjectEntry entry, string code) { CollectingErrorSink errors = null; if (code != null) { PythonAst ast; errors = new CollectingErrorSink(); using (var p = Parser.CreateParser( new StringReader(code), _analyzer.LanguageVersion, new ParserOptions { BindReferences = true, ErrorSink = errors } )) { ast = p.ParseFile(); entry.UpdateTree(ast, null); } if (errors.Errors.Any() || errors.Warnings.Any()) { if (AssertOnParseErrors) { var errorMsg = MakeMessage(errors); Trace.TraceError(errorMsg); Assert.Fail("Errors parsing " + entry.FilePath, errorMsg); } } } entry.Analyze(CancellationToken.None, true); }