private bool TryGetCurrentLanguageBufferExtent(IProjectionSnapshot projectionSnapshot, out Span result) { if (projectionSnapshot.SpanCount == 0) { result = default(Span); return(false); } // the last source snapshot is always a projection of a language buffer: var snapshot = projectionSnapshot.GetSourceSpan(projectionSnapshot.SpanCount - 1).Snapshot; if (snapshot.TextBuffer != _currentLanguageBuffer) { result = default(Span); return(false); } SnapshotPoint start = new SnapshotPoint(snapshot, 0); SnapshotPoint end = new SnapshotPoint(snapshot, snapshot.Length); // projection of the previous version of current language buffer snapshot: var surfaceSpans = projectionSnapshot.MapFromSourceSnapshot(new SnapshotSpan(start, end)); // the language buffer might be projected to multiple surface lines: Debug.Assert(surfaceSpans.Count > 0); result = new Span(surfaceSpans[0].Start, surfaceSpans.Last().End); return(true); }
/// <remarks> /// This should only be called from within the current language buffer. If there are /// any output or standard input buffers between the specified line and the end of the /// surface buffer, then the result will be incorrect. /// </remarks> private int GetProjectionSpanIndexFromEditableBufferPosition(IProjectionSnapshot surfaceSnapshot, int projectionSpansCount, int surfaceLineNumber) { // The current language buffer is projected to a set of projections interleaved regularly by prompt projections // and ending at the end of the projection buffer, each language buffer projection is on a separate line: // [prompt)[language)...[prompt)[language)<end of projection buffer> int result = projectionSpansCount - (surfaceSnapshot.LineCount - surfaceLineNumber) * SpansPerLineOfInput + 1; Debug.Assert(GetSpanKind(surfaceSnapshot.GetSourceSpan(result)) == ReplSpanKind.Language); return(result); }
/// <remarks> /// This should only be called from within the current language buffer. If there are /// any output or standard input buffers between the specified line and the end of the /// surface buffer, then the result will be incorrect. /// </remarks> private int GetProjectionSpanIndexFromEditableBufferPosition(IProjectionSnapshot surfaceSnapshot, int projectionSpansCount, int surfaceLineNumber) { // The current language buffer is projected to a set of projections interleaved regularly by prompt projections // and ending at the end of the projection buffer, each language buffer projection is on a separate line: // [prompt)[language)...[prompt)[language)<end of projection buffer> int result = projectionSpansCount - (surfaceSnapshot.LineCount - surfaceLineNumber) * SpansPerLineOfInput + 1; Debug.Assert(GetSpanKind(surfaceSnapshot.GetSourceSpan(result)) == ReplSpanKind.Input); return result; }
private bool TryGetCurrentLanguageBufferExtent(IProjectionSnapshot projectionSnapshot, out Span result) { if (projectionSnapshot.SpanCount == 0) { result = default(Span); return false; } // the last source snapshot is always a projection of a language buffer: var snapshot = projectionSnapshot.GetSourceSpan(projectionSnapshot.SpanCount - 1).Snapshot; if (snapshot.TextBuffer != CurrentLanguageBuffer) { result = default(Span); return false; } SnapshotPoint start = new SnapshotPoint(snapshot, 0); SnapshotPoint end = new SnapshotPoint(snapshot, snapshot.Length); // projection of the previous version of current language buffer snapshot: var surfaceSpans = projectionSnapshot.MapFromSourceSnapshot(new SnapshotSpan(start, end)); // the language buffer might be projected to multiple surface lines: Debug.Assert(surfaceSpans.Count > 0); result = new Span(surfaceSpans[0].Start, surfaceSpans.Last().End); return true; }