private void FindAndUpdateSpans(TextExtent extent, SnapshotPoint request)
        {
            var wordSpans = new List <SnapshotSpan>();
            var text      = request.Snapshot.GetText(extent.Span);

            if (!IsComment(extent))
            {
                if (text.Any(c => char.IsLetter(c)))
                {
                    if (!_currentToken.HasValue || extent.Span != _currentToken)
                    {
                        // Find the new spans
                        var findData = new FindData(extent.Span.GetText(), extent.Span.Snapshot)
                        {
                            FindOptions = FindOptions.WholeWord | FindOptions.MatchCase
                        };

                        var tagger = new GLSLTaggerProvider().CreateTagger <IGLSLTag>(_buffer) as GLSLTagger;
                        var scope  = tagger.GetScope(extent.Span);

                        var spans = _textSearchService.FindAll(findData);

                        foreach (var span in spans)
                        {
                            var spanScope = tagger.GetScope(span);
                            if (spanScope == scope || spanScope.IsDescendentOf(scope) || spanScope.IsAncestorOf(scope))
                            {
                                lock (_spanLock)
                                {
                                    if (!_commentSpans.CloneAndTrackTo(extent.Span.Snapshot, SpanTrackingMode.EdgePositive).OverlapsWith(span) &&
                                        _tokenSpans.CloneAndTrackTo(extent.Span.Snapshot, SpanTrackingMode.EdgePositive).OverlapsWith(span))
                                    {
                                        wordSpans.Add(span);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    var span = GetMatchingBracketSpan(extent, text);

                    if (span.HasValue && (!_currentToken.HasValue || extent.Span != _currentToken))
                    {
                        wordSpans.Add(span.Value);
                    }
                }
            }

            // If another change hasn't happened, do a real update
            if (request == _requestedPoint)
            {
                SynchronousUpdate(request, new NormalizedSnapshotSpanCollection(wordSpans), extent.Span);
            }
        }
Exemplo n.º 2
0
        private void UpdateDirtySpans(TextContentChangedEventArgs e)
        {
            _currentSnapshot = e.After;

            var newDirtySpans = _dirtySpans.CloneAndTrackTo(e.After, SpanTrackingMode.EdgeInclusive);

            newDirtySpans = e.Changes
                            .Aggregate(newDirtySpans, (current, change) => NormalizedSnapshotSpanCollection.Union(
                                           current, new NormalizedSnapshotSpanCollection(e.After, change.NewSpan)));

            _dirtySpans = newDirtySpans;
        }
Exemplo n.º 3
0
        private void UpdateDirtySpans(TextContentChangedEventArgs e)
        {
            currentSnapshot = e.After;

            var newDirtySpans = dirtySpans.CloneAndTrackTo(e.After, SpanTrackingMode.EdgeInclusive);

            foreach (var change in e.Changes)
            {
                newDirtySpans = NormalizedSnapshotSpanCollection.Union(newDirtySpans, new NormalizedSnapshotSpanCollection(e.After, change.NewSpan));
            }

            dirtySpans = newDirtySpans;
        }
Exemplo n.º 4
0
        private void OnBufferChange(object sender, TextContentChangedEventArgs e)
        {
            _currentSnapshot = e.After;

            // Translate all of the old dirty spans to the new snapshot.
            NormalizedSnapshotSpanCollection newDirtySpans = _dirtySpans.CloneAndTrackTo(e.After, SpanTrackingMode.EdgeInclusive);

            // Dirty all the spans that changed.
            foreach (var change in e.Changes)
            {
                newDirtySpans = NormalizedSnapshotSpanCollection.Union(newDirtySpans, new NormalizedSnapshotSpanCollection(e.After, change.NewSpan));
            }

            // Translate all the security errors to the new snapshot (and remove anything that is a dirty
            // region since we will need to check that again).
            var oldSecurityErrors = this.Factory.CurrentSnapshot;
            var newSecurityErrors = new DevSkimErrorsSnapshot(this.FilePath, oldSecurityErrors.VersionNumber + 1);

            // Copy all of the old errors to the new errors unless the error was affected by the text change
            foreach (var error in oldSecurityErrors.Errors)
            {
                Debug.Assert(error.NextIndex == -1);

                var newError = DevSkimError.CloneAndTranslateTo(error, e.After);

                if (newError != null)
                {
                    Debug.Assert(newError.Span.Length == error.Span.Length);

                    error.NextIndex = newSecurityErrors.Errors.Count;
                    newSecurityErrors.Errors.Add(newError);
                }
            }

            this.UpdateSecurityErrors(newSecurityErrors);

            _dirtySpans = newDirtySpans;

            // Start processing the dirty spans (which no-ops if we're already doing it).
            if (_dirtySpans.Count != 0)
            {
                this.KickUpdate();
            }
        }