private void UpdateCodeMarks(ConcurrentDictionary <int, CoveredLinePoco> coveredLines) { FileCodeModel fcm = _coverageProvider.GetFileCodeModel(_documentName); int apparentLineNumber = 0; double accumulatedHeight = 0.0; double minLineHeight = _textViewHost.TextView.TextViewLines.Min(x => x.Height); //if (fcm != null) //{ // var project = fcm.DTE.Solution.FindProjectItem(_documentName).ContainingProject; // if (project.FullName.EndsWith("Test.csproj")) // { // apparentLineNumber++; // } //} foreach (ITextViewLine textViewLine in _textViewHost.TextView.TextViewLines.ToList()) { if (textViewLine.VisibilityState == VisibilityState.FullyVisible && coveredLines.Count > 0) { apparentLineNumber++; int lineNumber = textViewLine.Start.GetContainingLine().LineNumber; accumulatedHeight += textViewLine.Height; var coveredLine = new CoveredLinePoco(); ITextSnapshotLine g = _textViewHost.TextView.TextBuffer.CurrentSnapshot.Lines.FirstOrDefault( x => x.LineNumber.Equals(lineNumber)); bool isCovered = coveredLines.TryGetValue(lineNumber + 1, out coveredLine); var text = g.Extent.GetText(); if (text.Trim().StartsWith("[Test")) { //apparentLineNumber--; } if (g.Extent.IsEmpty == false && isCovered && text != "\t\t#endregion") { Debug.WriteLine("Text for Line # " + (lineNumber + 1) + " = " + text); //double yPos = (_textViewHost.TextView.ZoomLevel / 100) * (apparentLineNumber - 1) * _textViewHost.TextView.LineHeight + (.1 * _textViewHost.TextView.LineHeight); // GetYCoordinateForBookmark(coveredLine); double yPos = (_textViewHost.TextView.ZoomLevel / 100) * ((accumulatedHeight - minLineHeight) + (.1 * _textViewHost.TextView.LineHeight)); // GetYCoordinateForBookmark(coveredLine); var glyph = CreateCodeMarkGlyph(coveredLine, yPos); _marginCanvas.Children.Add(glyph); } } } var pont = new SnapshotPoint(_textViewHost.TextView.TextSnapshot, 0); }
public CodeMarkGlyph(IWpfTextView view, CoveredLinePoco line, double yPosition) : this() { YPosition = yPosition; this._view = view; _coveredLine = line; Ellipse.Height = (view.LineHeight * view.ZoomLevel / 100) * .8; Ellipse.Width = Ellipse.Height; if (!line.UnitTests.Any() && line.IsCode) { Ellipse.Fill = new SolidColorBrush(Colors.Orange); Ellipse.Stroke = new SolidColorBrush(Colors.Orange); } else if (line.UnitTests.All(x => x.IsSuccessful.Equals(true))) { Ellipse.Fill = new SolidColorBrush(Colors.Green); Ellipse.Stroke = new SolidColorBrush(Colors.Green); } else { Ellipse.Fill = new SolidColorBrush(Colors.Red); Ellipse.Stroke = new SolidColorBrush(Colors.Red); } }
private CodeMarkGlyph CreateCodeMarkGlyph(CoveredLinePoco line, double yPos) { // create a glyph var glyph = new CodeMarkGlyph(_textViewHost.TextView, line, yPos); // position it Canvas.SetTop(glyph, yPos); Canvas.SetLeft(glyph, 0); var tooltip = new StringBuilder(); tooltip.AppendFormat("Covering Tests:\t {0}\n", line.UnitTests.Count); foreach (UnitTest test in line.UnitTests.OrderBy(x => x.IsSuccessful)) { tooltip.AppendFormat("{0}\n", test.TestMethodName); } glyph.ToolTip = tooltip.ToString(); return(glyph); // so we have the glyph now }
// get y position for this bookmark private double GetYCoordinateForBookmark(CoveredLinePoco line) { // calculate y position from line number with this bookmark return(GetYCoordinateFromLineNumber(line.LineNumber)); }