public IProjectEntry AnalyzeFile(string path) { IProjectEntry item; if (!_projectFiles.TryGetValue(path, out item)) { if (path.EndsWith(".py", StringComparison.OrdinalIgnoreCase)) { var modName = PythonAnalyzer.PathToModuleName(path); item = _analysisState.AddModule( modName, path, null ); } else if (path.EndsWith(".xaml", StringComparison.Ordinal)) { item = _analysisState.AddXamlFile(path, null); } if (item != null) { _projectFiles[path] = item; } } if (item != null) { _queue.EnqueueFile(item, path); } return(item); }
private IProjectEntry CreateProjectEntry(ITextBuffer buffer, IAnalysisCookie analysisCookie) { var replEval = buffer.GetReplEvaluator(); if (replEval != null) { // We have a repl window, create an untracked module. return(_analysisState.AddModule(null, null, analysisCookie)); } string path = buffer.GetFilePath(); if (path == null) { return(null); } IProjectEntry entry; if (!_projectFiles.TryGetValue(path, out entry)) { var modName = PythonAnalyzer.PathToModuleName(path); if (buffer.ContentType.IsOfType(PythonCoreConstants.ContentType)) { entry = _analysisState.AddModule( modName, buffer.GetFilePath(), analysisCookie ); } else if (buffer.ContentType.IsOfType("XAML")) { entry = _analysisState.AddXamlFile(buffer.GetFilePath()); } else { return(null); } _projectFiles[path] = entry; if (ImplicitProject && !Path.GetFullPath(path).StartsWith(Path.GetDirectoryName(_interpreterFactory.Configuration.InterpreterPath), StringComparison.OrdinalIgnoreCase)) // don't analyze std lib // TODO: We're doing this on the UI thread and when we end up w/ a lot to queue here we hang for a while... // But this adds files to the analyzer so it's not as simple as queueing this onto another thread. { AddImplicitFiles(Path.GetDirectoryName(Path.GetFullPath(path))); } } return(entry); }
public PythonAnalyzer AnalyzeStdLib() { string dir = Path.Combine("C:\\Python27\\Lib"); List <string> files = new List <string>(); CollectFiles(dir, files); List <FileStreamReader> sourceUnits = new List <FileStreamReader>(); foreach (string file in files) { sourceUnits.Add( new FileStreamReader(file) ); } Stopwatch sw = new Stopwatch(); sw.Start(); long start0 = sw.ElapsedMilliseconds; var projectState = new PythonAnalyzer(Interpreter, PythonLanguageVersion.V27); var modules = new List <IPythonProjectEntry>(); foreach (var sourceUnit in sourceUnits) { modules.Add(projectState.AddModule(PythonAnalyzer.PathToModuleName(sourceUnit.Path), sourceUnit.Path, null)); } long start1 = sw.ElapsedMilliseconds; Console.WriteLine("AddSourceUnit: {0} ms", start1 - start0); var nodes = new List <Microsoft.PythonTools.Parsing.Ast.PythonAst>(); for (int i = 0; i < modules.Count; i++) { PythonAst ast = null; try { var sourceUnit = sourceUnits[i]; ast = Parser.CreateParser(sourceUnit, Microsoft.PythonTools.Parsing.ErrorSink.Null, PythonLanguageVersion.V27).ParseFile(); } catch (Exception) { } nodes.Add(ast); } long start2 = sw.ElapsedMilliseconds; Console.WriteLine("Parse: {0} ms", start2 - start1); for (int i = 0; i < modules.Count; i++) { var ast = nodes[i]; if (ast != null) { modules[i].UpdateTree(ast, null); } } long start3 = sw.ElapsedMilliseconds; for (int i = 0; i < modules.Count; i++) { Console.WriteLine("Analyzing {1}: {0} ms", sw.ElapsedMilliseconds - start3, sourceUnits[i].Path); var ast = nodes[i]; if (ast != null) { modules[i].Analyze(true); } } if (modules.Count > 0) { Console.WriteLine("Analyzing queue"); modules[0].AnalysisGroup.AnalyzeQueuedEntries(); } long start4 = sw.ElapsedMilliseconds; Console.WriteLine("Analyze: {0} ms", start4 - start3); return(projectState); }