예제 #1
0
        /// <summary>
        /// Computes a model for the given snapshot.
        /// </summary>
        private async Task <NavigationBarModel> ComputeModelAsync(Document document, ITextSnapshot snapshot, CancellationToken cancellationToken)
        {
            // TODO: remove .FirstOrDefault()
            var languageService = document.LanguageServices.GetService <INavigationBarItemService>();

            if (languageService != null)
            {
                //// check whether we can re-use lastCompletedModel. otherwise, update lastCompletedModel here.
                //// the model should be only updated here
                //if (_lastCompletedModel != null)
                //{
                //    var semanticVersion = await document.Project.GetDependentSemanticVersionAsync(CancellationToken.None).ConfigureAwait(false);
                //    if (_lastCompletedModel.SemanticVersionStamp == semanticVersion && SpanStillValid(_lastCompletedModel, snapshot, cancellationToken))
                //    {
                //        // it looks like we can re-use previous model
                //        return _lastCompletedModel;
                //    }
                //}

                //using (Logger.LogBlock(FunctionId.NavigationBar_ComputeModelAsync, cancellationToken))
                {
                    var items = await languageService.GetItemsAsync(document, cancellationToken).ConfigureAwait(false);

                    if (items != null)
                    {
                        items.Do(i => i.InitializeTrackingSpans(snapshot));
                        //var version = await document.Project.GetDependentSemanticVersionAsync(cancellationToken).ConfigureAwait(false);

                        //_lastCompletedModel = new NavigationBarModel(items, version, languageService);
                        _lastCompletedModel = new NavigationBarModel(items, VersionStamp.Default, languageService);
                        return(_lastCompletedModel);
                    }
                }
            }

            _lastCompletedModel = _lastCompletedModel ??
                                  new NavigationBarModel(SpecializedCollections.EmptyList <NavigationBarItem>(), new VersionStamp(), null);
            return(_lastCompletedModel);
        }
예제 #2
0
        internal static NavigationBarSelectedTypeAndMember ComputeSelectedTypeAndMember(NavigationBarModel model, SnapshotPoint caretPosition, CancellationToken cancellationToken)
        {
            var leftItem = GetMatchingItem(model.Types, caretPosition, model.ItemService, cancellationToken);

            if (leftItem.item == null)
            {
                // Nothing to show at all
                return(new NavigationBarSelectedTypeAndMember(null, null));
            }

            var rightItem = GetMatchingItem(leftItem.item.ChildItems, caretPosition, model.ItemService, cancellationToken);

            return(new NavigationBarSelectedTypeAndMember(leftItem.item, leftItem.gray, rightItem.item, rightItem.gray));
        }