public IProjectEntry AnalyzeTextView(ITextView textView) { // Get an AnalysisItem for this file, creating one if necessary var res = textView.TextBuffer.Properties.GetOrCreateSingletonProperty <IProjectEntry>(() => { string path = textView.GetFilePath(); if (path == null) { return(null); } IProjectEntry entry; if (!_projectFiles.TryGetValue(path, out entry)) { var modName = PathToModuleName(path); var initialSnapshot = textView.TextBuffer.CurrentSnapshot; if (textView.TextBuffer.ContentType.IsOfType(PythonCoreConstants.ContentType)) { entry = _analysisState.AddModule( modName, textView.GetFilePath(), new SnapshotCookie(initialSnapshot) ); } else if (textView.TextBuffer.ContentType.IsOfType("xaml")) { entry = _analysisState.AddXamlFile(path); } else { return(null); } _projectFiles[path] = entry; if (ImplicitProject) { AddImplicitFiles(Path.GetDirectoryName(Path.GetFullPath(path))); } } return(entry); }); // kick off initial processing on the ITextWindow _queue.EnqueueBuffer(textView); return(res); }
private static ProjectEntry ParseText(ProjectState state, SourceUnit sourceUnit, string moduleName) { var newEntry = state.AddModule(moduleName, moduleName, null); Prepare(newEntry, sourceUnit); foreach (var entry in state.ProjectEntries) { entry.Analyze(); } return(newEntry); }
public void TestAnalyzeStdLib() { //string dir = Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles"), "IronPython 2.6 for .NET 4.0 RC\\Lib"); string dir = Path.Combine("C:\\Python27\\Lib"); List <string> files = new List <string>(); CollectFiles(dir, files); List <SourceUnit> sourceUnits = new List <SourceUnit>(); foreach (string file in files) { sourceUnits.Add( new SourceUnit( HostingHelpers.GetLanguageContext(_engine), new FileTextContentProvider(new FileStreamContentProvider(file)), Path.GetFileNameWithoutExtension(file), SourceCodeKind.File ) ); } Stopwatch sw = new Stopwatch(); sw.Start(); long start0 = sw.ElapsedMilliseconds; var projectState = new ProjectState(_engine); List <ProjectEntry> modules = new List <ProjectEntry>(); PythonOptions EmptyOptions = new PythonOptions(); foreach (var sourceUnit in sourceUnits) { modules.Add(projectState.AddModule(Path.GetFileNameWithoutExtension(sourceUnit.Path), sourceUnit.Path, null)); } long start1 = sw.ElapsedMilliseconds; Console.WriteLine("AddSourceUnit: {0} ms", start1 - start0); List <PythonAst> nodes = new List <PythonAst>(); for (int i = 0; i < modules.Count; i++) { PythonAst ast = null; try { var sourceUnit = sourceUnits[i]; var context = new CompilerContext(sourceUnit, HostingHelpers.GetLanguageContext(_engine).GetCompilerOptions(), ErrorSink.Null); ast = Parser.CreateParser(context, EmptyOptions).ParseFile(false); } 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(); } } long start4 = sw.ElapsedMilliseconds; Console.WriteLine("Analyze: {0} ms", start4 - start3); Console.ReadLine(); }
public void TestAnalyzeStdLib() { //string dir = Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles"), "IronPython 2.6 for .NET 4.0 RC\\Lib"); string dir = Path.Combine("C:\\Python27\\Lib"); List<string> files = new List<string>(); CollectFiles(dir, files); List<SourceUnit> sourceUnits = new List<SourceUnit>(); foreach (string file in files) { sourceUnits.Add( new SourceUnit( HostingHelpers.GetLanguageContext(_engine), new FileTextContentProvider(new FileStreamContentProvider(file)), Path.GetFileNameWithoutExtension(file), SourceCodeKind.File ) ); } Stopwatch sw = new Stopwatch(); sw.Start(); long start0 = sw.ElapsedMilliseconds; var projectState = new ProjectState(_engine); List<ProjectEntry> modules = new List<ProjectEntry>(); PythonOptions EmptyOptions = new PythonOptions(); foreach (var sourceUnit in sourceUnits) { modules.Add(projectState.AddModule(Path.GetFileNameWithoutExtension(sourceUnit.Path), sourceUnit.Path, null)); } long start1 = sw.ElapsedMilliseconds; Console.WriteLine("AddSourceUnit: {0} ms", start1 - start0); List<PythonAst> nodes = new List<PythonAst>(); for (int i = 0; i < modules.Count; i++) { PythonAst ast = null; try { var sourceUnit = sourceUnits[i]; var context = new CompilerContext(sourceUnit, HostingHelpers.GetLanguageContext(_engine).GetCompilerOptions(), ErrorSink.Null); ast = Parser.CreateParser(context, EmptyOptions).ParseFile(false); } 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(); } } long start4 = sw.ElapsedMilliseconds; Console.WriteLine("Analyze: {0} ms", start4 - start3); Console.ReadLine(); }
private static ProjectEntry ParseText(ProjectState state, SourceUnit sourceUnit, string moduleName) { var newEntry = state.AddModule(moduleName, moduleName, null); Prepare(newEntry, sourceUnit); foreach (var entry in state.ProjectEntries) { entry.Analyze(); } return newEntry; }