internal PersistentSpan Create(SnapshotSpan span, SpanTrackingMode trackingMode) { var persistentSpan = new PersistentSpan(span, trackingMode, this); this.Spans.Add(persistentSpan); return(persistentSpan); }
internal void DocumentReopened(ITextDocument document) { _document = document; ITextSnapshot snapshot = document.TextBuffer.CurrentSnapshot; SnapshotPoint start; SnapshotPoint end; if (_useLineIndex) { start = PersistentSpan.LineIndexToSnapshotPoint(_startLine, _startIndex, snapshot); end = PersistentSpan.LineIndexToSnapshotPoint(_endLine, _endIndex, snapshot); if (end < start) { //Guard against the case where _start & _end are something like (100,2) & (101, 1). //Those points would pass the argument validation (since _endLine > _startLine) but //would cause problems if the document has only 5 lines since they would map to //(5, 2) & (5, 1). end = start; } } else { start = new SnapshotPoint(snapshot, Math.Min(_nonTrackingSpan.Start, snapshot.Length)); end = new SnapshotPoint(snapshot, Math.Min(_nonTrackingSpan.End, snapshot.Length)); } _span = snapshot.CreateTrackingSpan(new SnapshotSpan(start, end), _trackingMode); _filePath = null; }
public IPersistentSpan Create(string filePath, int startLine, int startIndex, int endLine, int endIndex, SpanTrackingMode trackingMode) { if (string.IsNullOrEmpty(filePath)) { throw new ArgumentException("filePath"); } if (startLine < 0) { throw new ArgumentOutOfRangeException("startLine", "Must be non-negative."); } if (startIndex < 0) { throw new ArgumentOutOfRangeException("startIndex", "Must be non-negative."); } if (endLine < startLine) { throw new ArgumentOutOfRangeException("endLine", "Must be >= startLine."); } if ((endIndex < 0) || ((startLine == endLine) && (endIndex < startIndex))) { throw new ArgumentOutOfRangeException("endIndex", "Must be non-negative and (endLine,endIndex) may not be before (startLine,startIndex)."); } if (((int)trackingMode < (int)SpanTrackingMode.EdgeExclusive) || ((int)trackingMode > (int)(SpanTrackingMode.EdgeNegative))) { throw new ArgumentOutOfRangeException("trackingMode"); } PersistentSpan persistentSpan = new PersistentSpan(filePath, startLine, startIndex, endLine, endIndex, trackingMode, this); this.AddSpan(new FileNameKey(filePath), persistentSpan); return(persistentSpan); }
internal void DocumentClosed(ITextSnapshot savedSnapshot) { Assumes.NotNull(_originalVersion); if ((savedSnapshot != null) && (savedSnapshot.Version.VersionNumber > _originalVersion.VersionNumber)) { // The document was saved and we want to line/column indices in the saved snapshot (& not the current snapshot) var savedSpan = new SnapshotSpan(savedSnapshot, Tracking.TrackSpanForwardInTime(_trackingMode, _originalSpan, _originalVersion, savedSnapshot.Version)); PersistentSpan.SnapshotPointToLineIndex(savedSpan.Start, out _startLine, out _startIndex); PersistentSpan.SnapshotPointToLineIndex(savedSpan.End, out _endLine, out _endIndex); } else { // The document was never saved (or was saved before we created) so continue to use the old line/column indices. // Since those are set when either the span is created (against an open document) or when the document is reopened, // they don't need to be changed. } //We set this to false when the document is closed because we have an accurate line/index and that is more stable //than a simple offset. _useLineIndex = true; _originalSpan = default(Span); _originalVersion = null; _span = null; }
internal PersistentSpan Create(int startLine, int startIndex, int endLine, int endIndex, SpanTrackingMode trackingMode) { PersistentSpan persistentSpan = new PersistentSpan(startLine, startIndex, endLine, endIndex, trackingMode, this); this.Spans.Add(persistentSpan); return(persistentSpan); }
private void UpdateStartEnd() { SnapshotSpan span = _span.GetSpan(_span.TextBuffer.CurrentSnapshot); _nonTrackingSpan = span; PersistentSpan.SnapshotPointToLineIndex(span.Start, out _startLine, out _startIndex); PersistentSpan.SnapshotPointToLineIndex(span.End, out _endLine, out _endIndex); }
private SnapshotSpan UpdateStartEnd() { SnapshotSpan span = _span.GetSpan(_span.TextBuffer.CurrentSnapshot); PersistentSpan.SnapshotPointToLineIndex(span.Start, out _startLine, out _startIndex); PersistentSpan.SnapshotPointToLineIndex(span.End, out _endLine, out _endIndex); return(span); }
internal void Delete(PersistentSpanSet spanSet, PersistentSpan span) { lock (_spansOnDocuments) { if (spanSet.Spans.Remove(span) && (spanSet.Spans.Count == 0)) { _spansOnDocuments.Remove(((object)(spanSet.Document)) ?? spanSet.FileKey); spanSet.Dispose(); } } }
internal PersistentSpan Create(ITextSnapshot snapshot, int startLine, int startIndex, int endLine, int endIndex, SpanTrackingMode trackingMode) { var start = PersistentSpan.LineIndexToSnapshotPoint(startLine, startIndex, snapshot); var end = PersistentSpan.LineIndexToSnapshotPoint(endLine, endIndex, snapshot); if (end < start) { end = start; } return(this.Create(new SnapshotSpan(start, end), trackingMode)); }
internal PersistentSpan(SnapshotSpan span, SpanTrackingMode trackingMode, PersistentSpanSet spanSet) { _span = span.Snapshot.CreateTrackingSpan(span, trackingMode); _originalVersion = span.Snapshot.Version; _originalSpan = span; PersistentSpan.SnapshotPointToLineIndex(span.Start, out _startLine, out _startIndex); PersistentSpan.SnapshotPointToLineIndex(span.End, out _endLine, out _endIndex); _trackingMode = trackingMode; this.SpanSet = spanSet; }
public IPersistentSpan Create(SnapshotSpan span, SpanTrackingMode trackingMode) { ITextDocument document; if (this.TextDocumentFactoryService.TryGetTextDocument(span.Snapshot.TextBuffer, out document)) { PersistentSpan persistentSpan = new PersistentSpan(document, span, trackingMode, this); this.AddSpan(document, persistentSpan); return(persistentSpan); } return(null); }
} //For unit tests private void AddSpan(object key, PersistentSpan persistentSpan) { lock (_spansOnDocuments) { FrugalList <PersistentSpan> spans; if (!_spansOnDocuments.TryGetValue(key, out spans)) { this.EnsureEventsHooked(); spans = new FrugalList <PersistentSpan>(); _spansOnDocuments.Add(key, spans); } spans.Add(persistentSpan); } }
public IPersistentSpan Create(string filePath, Span span, SpanTrackingMode trackingMode) { if (string.IsNullOrEmpty(filePath)) { throw new ArgumentException("filePath"); } if (((int)trackingMode < (int)SpanTrackingMode.EdgeExclusive) || ((int)trackingMode > (int)(SpanTrackingMode.EdgeNegative))) { throw new ArgumentOutOfRangeException("trackingMode"); } PersistentSpan persistentSpan = new PersistentSpan(filePath, span, trackingMode, this); this.AddSpan(new FileNameKey(filePath), persistentSpan); return(persistentSpan); }
internal void Delete(PersistentSpan span) { lock (_spansOnDocuments) { ITextDocument document = span.Document; if (document != null) { FrugalList <PersistentSpan> spans; if (_spansOnDocuments.TryGetValue(document, out spans)) { spans.Remove(span); if (spans.Count == 0) { //Last one ... remove all references to document. _spansOnDocuments.Remove(document); } } else { Debug.Fail("There should have been an entry in SpanOnDocuments."); } } else { var path = new FileNameKey(span.FilePath); FrugalList <PersistentSpan> spans; if (_spansOnDocuments.TryGetValue(path, out spans)) { spans.Remove(span); if (spans.Count == 0) { //Last one ... remove all references to path. _spansOnDocuments.Remove(path); } } else { Debug.Fail("There should have been an entry in SpanOnDocuments."); } } } }
public IPersistentSpan Create(ITextSnapshot snapshot, int startLine, int startIndex, int endLine, int endIndex, SpanTrackingMode trackingMode) { ITextDocument document; if (this.TextDocumentFactoryService.TryGetTextDocument(snapshot.TextBuffer, out document)) { var start = PersistentSpan.LineIndexToSnapshotPoint(startLine, startIndex, snapshot); var end = PersistentSpan.LineIndexToSnapshotPoint(endLine, endIndex, snapshot); if (end < start) { end = start; } PersistentSpan persistentSpan = new PersistentSpan(document, new SnapshotSpan(start, end), trackingMode, this); this.AddSpan(document, persistentSpan); return(persistentSpan); } return(null); }
public bool TryGetStartLineIndex(out int startLine, out int startIndex) { if (this.SpanSet == null) { throw new ObjectDisposedException("PersistentSpan"); } if (_span != null) { SnapshotSpan span = _span.GetSpan(_span.TextBuffer.CurrentSnapshot); PersistentSpan.SnapshotPointToLineIndex(span.Start, out startLine, out startIndex); return(true); } else if (_useLineIndex) { startLine = _startLine; startIndex = _startIndex; return(true); } startLine = startIndex = 0; return(false); }
internal void DocumentReopened() { ITextSnapshot snapshot = this.SpanSet.Document.TextBuffer.CurrentSnapshot; SnapshotPoint start; SnapshotPoint end; if (_useLineIndex) { start = PersistentSpan.LineIndexToSnapshotPoint(_startLine, _startIndex, snapshot); end = PersistentSpan.LineIndexToSnapshotPoint(_endLine, _endIndex, snapshot); if (end < start) { //Guard against the case where _start & _end are something like (100,2) & (101, 1). //Those points would pass the argument validation (since _endLine > _startLine) but //would cause problems if the document has only 5 lines since they would map to //(5, 2) & (5, 1). end = start; } } else { start = new SnapshotPoint(snapshot, Math.Min(_originalSpan.Start, snapshot.Length)); end = new SnapshotPoint(snapshot, Math.Min(_originalSpan.End, snapshot.Length)); } var snapshotSpan = new SnapshotSpan(start, end); _span = snapshot.CreateTrackingSpan(snapshotSpan, _trackingMode); _originalSpan = snapshotSpan; _originalVersion = snapshot.Version; PersistentSpan.SnapshotPointToLineIndex(snapshotSpan.Start, out _startLine, out _startIndex); PersistentSpan.SnapshotPointToLineIndex(snapshotSpan.End, out _endLine, out _endIndex); }
internal void Delete(PersistentSpan span) { this.Factory.Delete(this, span); }