private static ExpressionAnalysis AnalyzeExpression(int location, string sourceCode) { if (location < 0) { location = sourceCode.Length + location + 1; } var analyzer = new ProjectAnalyzer(new IronPythonInterpreterFactory(), new MockErrorProviderFactory()); var buffer = new MockTextBuffer(sourceCode); buffer.AddProperty(typeof(ProjectAnalyzer), analyzer); var textView = new MockTextView(buffer); var item = analyzer.MonitorTextBuffer(textView.TextBuffer); // We leak here because we never un-monitor, but it's a test. while (!item.ProjectEntry.IsAnalyzed) { Thread.Sleep(100); } var snapshot = (MockTextSnapshot)buffer.CurrentSnapshot; return(snapshot.AnalyzeExpression(new MockTrackingSpan(snapshot, location, location == snapshot.Length ? 0 : 1))); }