public void NotifyParseDataChanged(ICodeDocument document, ParseDataPropertyChangedEventArgs e)
        {
            var documentIdManager = document.Properties.GetOrCreateSingleton(() => new DocumentReferencedIdManager());

            UpdateReferences(document, documentIdManager);
        }
        /// <summary>
        /// Occurs when the document parse data is changed.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">A <c>ParseDataPropertyChangedEventArgs</c> that contains the event data.</param>
        private void OnDocumentParseDataChanged(object sender, ParseDataPropertyChangedEventArgs e)
        {
            if (this.Document == null)
            {
                return;
            }

            var snapshot = this.Document.CurrentSnapshot;

            var parseData = e.NewValue as CodeLensParseData;

            if (parseData != null)
            {
                int?invalidStartOffset = null;
                int?invalidEndOffset   = null;

                var cacheIndex = 0;
                foreach (var declaration in parseData.Declarations)
                {
                    var declarationStartOffset = declaration.VersionRange.Translate(snapshot).StartOffset;

                    // Remove old cached declarations that no longer apply and are before the current declaration
                    var currentCachedDeclarationMatchesOffset = false;
                    while (cacheIndex < cachedDeclarations.Count)
                    {
                        var cachedDeclarationStartOffset = cachedDeclarations[cacheIndex].VersionRange.Translate(snapshot).StartOffset;

                        if (cachedDeclarationStartOffset < declarationStartOffset)
                        {
                            cachedDeclarations.RemoveAt(cacheIndex);

                            if (!invalidStartOffset.HasValue)
                            {
                                invalidStartOffset = cachedDeclarationStartOffset;
                            }
                            invalidEndOffset = cachedDeclarationStartOffset;
                        }
                        else
                        {
                            currentCachedDeclarationMatchesOffset = (cachedDeclarationStartOffset == declarationStartOffset);
                            break;
                        }
                    }

                    // If the current cached declaration matches the current declaration's offset...
                    if (currentCachedDeclarationMatchesOffset)
                    {
                        // If there is a key match...
                        if (declaration.Key == cachedDeclarations[cacheIndex].Key)
                        {
                            // Keep using the same declaration as before
                            cacheIndex++;
                            continue;
                        }
                        else
                        {
                            // Since the key has changed, remove the old cached declaration
                            cachedDeclarations.RemoveAt(cacheIndex);
                        }
                    }

                    // Add a new declaration
                    cachedDeclarations.Insert(cacheIndex++, declaration);

                    if (!invalidStartOffset.HasValue)
                    {
                        invalidStartOffset = declarationStartOffset;
                    }
                    invalidEndOffset = declarationStartOffset;
                }

                // Remove remaining old cached declarations
                while (cacheIndex < cachedDeclarations.Count)
                {
                    var cachedDeclarationStartOffset = cachedDeclarations[cacheIndex].VersionRange.Translate(snapshot).StartOffset;
                    cachedDeclarations.RemoveAt(cacheIndex);

                    if (!invalidStartOffset.HasValue)
                    {
                        invalidStartOffset = cachedDeclarationStartOffset;
                    }
                    invalidEndOffset = cachedDeclarationStartOffset;
                }

                // Invalidate any affected range
                if (invalidStartOffset.HasValue)
                {
                    this.OnTagsChanged(new TagsChangedEventArgs(new TextSnapshotRange(snapshot, invalidStartOffset.Value, invalidEndOffset.Value)));
                }
            }
            else if (cachedDeclarations.Count > 0)
            {
                var snapshotRange = new TextSnapshotRange(snapshot, cachedDeclarations[0].VersionRange.Translate(snapshot).StartOffset,
                                                          cachedDeclarations[cachedDeclarations.Count - 1].VersionRange.Translate(snapshot).StartOffset);

                cachedDeclarations.Clear();

                this.OnTagsChanged(new TagsChangedEventArgs(snapshotRange));
            }
        }
 private void DocumentOnParseDataChanged(object sender, ParseDataPropertyChangedEventArgs e)
 {
     UpdateTags();
 }
 public void NotifyParseDataChanged(ICodeDocument document, ParseDataPropertyChangedEventArgs e)
 {
     var documentIdManager = document.Properties.GetOrCreateSingleton(() => new DocumentReferencedIdManager());
     UpdateReferences(document, documentIdManager);
 }