示例#1
0
            public SearchResult(Document document, DeclaredSymbolInfo declaredSymbolInfo, string kind, MatchKind matchKind, bool isCaseSensitive, INavigableItem navigableItem)
            {
                _document           = document;
                _declaredSymbolInfo = declaredSymbolInfo;
                Kind            = kind;
                MatchKind       = matchKind;
                IsCaseSensitive = isCaseSensitive;
                NavigableItem   = navigableItem;
                SecondarySort   = ConstructSecondarySortString(declaredSymbolInfo);

                var declaredNavigableItem = navigableItem as NavigableItemFactory.DeclaredSymbolNavigableItem;

                Debug.Assert(declaredNavigableItem != null);

                _lazySummary        = new Lazy <string>(() => declaredNavigableItem.Symbol?.GetDocumentationComment()?.SummaryText);
                _lazyAdditionalInfo = new Lazy <string>(() =>
                {
                    switch (declaredSymbolInfo.Kind)
                    {
                    case DeclaredSymbolInfoKind.Class:
                    case DeclaredSymbolInfoKind.Enum:
                    case DeclaredSymbolInfoKind.Interface:
                    case DeclaredSymbolInfoKind.Module:
                    case DeclaredSymbolInfoKind.Struct:
                        return(EditorFeaturesResources.Project + document.Project.Name);

                    default:
                        return(EditorFeaturesResources.Type + declaredSymbolInfo.ContainerDisplayName);
                    }
                });
            }
示例#2
0
            public SearchResult(
                Document document, DeclaredSymbolInfo declaredSymbolInfo, string kind,
                NavigateToMatchKind matchKind, bool isCaseSensitive, INavigableItem navigableItem,
                ImmutableArray <TextSpan> nameMatchSpans)
            {
                Document           = document;
                DeclaredSymbolInfo = declaredSymbolInfo;
                Kind            = kind;
                MatchKind       = matchKind;
                IsCaseSensitive = isCaseSensitive;
                NavigableItem   = navigableItem;
                NameMatchSpans  = nameMatchSpans;

                _lazyAdditionalInfo = new Lazy <string>(() =>
                {
                    switch (declaredSymbolInfo.Kind)
                    {
                    case DeclaredSymbolInfoKind.Class:
                    case DeclaredSymbolInfoKind.Enum:
                    case DeclaredSymbolInfoKind.Interface:
                    case DeclaredSymbolInfoKind.Module:
                    case DeclaredSymbolInfoKind.Struct:
                        if (!declaredSymbolInfo.IsNestedType)
                        {
                            return(string.Format(FeaturesResources.project_0, document.Project.Name));
                        }
                        break;
                    }

                    return(string.Format(FeaturesResources.in_0_project_1, declaredSymbolInfo.ContainerDisplayName, document.Project.Name));
                });
            }
            public SearchResult(
                Document document, DeclaredSymbolInfo declaredSymbolInfo, string kind,
                NavigateToMatchKind matchKind, bool isCaseSensitive, INavigableItem navigableItem,
                ImmutableArray <TextSpan> nameMatchSpans)
            {
                _document           = document;
                _declaredSymbolInfo = declaredSymbolInfo;
                Kind            = kind;
                MatchKind       = matchKind;
                IsCaseSensitive = isCaseSensitive;
                NavigableItem   = navigableItem;
                NameMatchSpans  = nameMatchSpans;
                SecondarySort   = ConstructSecondarySortString(document, declaredSymbolInfo);

                var declaredNavigableItem = navigableItem as NavigableItemFactory.DeclaredSymbolNavigableItem;

                Debug.Assert(declaredNavigableItem != null);

                _lazyAdditionalInfo = new Lazy <string>(() =>
                {
                    switch (declaredSymbolInfo.Kind)
                    {
                    case DeclaredSymbolInfoKind.Class:
                    case DeclaredSymbolInfoKind.Enum:
                    case DeclaredSymbolInfoKind.Interface:
                    case DeclaredSymbolInfoKind.Module:
                    case DeclaredSymbolInfoKind.Struct:
                        return(FeaturesResources.project_space + document.Project.Name);

                    default:
                        return(FeaturesResources.type_space + declaredSymbolInfo.ContainerDisplayName);
                    }
                });
            }
            public SearchResult(Document document, DeclaredSymbolInfo declaredSymbolInfo, string kind, MatchKind matchKind, bool isCaseSensitive, INavigableItem navigableItem)
            {
                _document = document;
                _declaredSymbolInfo = declaredSymbolInfo;
                Kind = kind;
                MatchKind = matchKind;
                IsCaseSensitive = isCaseSensitive;
                NavigableItem = navigableItem;
                SecondarySort = ConstructSecondarySortString(declaredSymbolInfo);

                var declaredNavigableItem = navigableItem as NavigableItemFactory.DeclaredSymbolNavigableItem;
                Debug.Assert(declaredNavigableItem != null);

                _lazySummary = new Lazy<string>(() => declaredNavigableItem.Symbol?.GetDocumentationComment()?.SummaryText);
                _lazyAdditionalInfo = new Lazy<string>(() =>
                {
                    switch (declaredSymbolInfo.Kind)
                    {
                        case DeclaredSymbolInfoKind.Class:
                        case DeclaredSymbolInfoKind.Enum:
                        case DeclaredSymbolInfoKind.Interface:
                        case DeclaredSymbolInfoKind.Module:
                        case DeclaredSymbolInfoKind.Struct:
                            return EditorFeaturesResources.Project + document.Project.Name;
                        default:
                            return EditorFeaturesResources.Type + declaredSymbolInfo.ContainerDisplayName;
                    }
                });
            }
        private static bool TryGoToSingleLocation(
            INavigableItem navigableItem, OptionSet options, bool throwOnHiddenDefinition)
        {
            var firstItem         = navigableItem;
            var workspace         = firstItem.Document.Project.Solution.Workspace;
            var navigationService = workspace.Services.GetService <IDocumentNavigationService>();

            if (navigationService.CanNavigateToSpan(workspace, firstItem.Document.Id, firstItem.SourceSpan))
            {
                return(navigationService.TryNavigateToSpan(
                           workspace,
                           documentId: firstItem.Document.Id,
                           textSpan: firstItem.SourceSpan,
                           options: options.WithChangedOption(NavigationOptions.PreferProvisionalTab, true)));
            }
            else
            {
                if (throwOnHiddenDefinition)
                {
                    const int E_FAIL = -2147467259;
                    throw new COMException(EditorFeaturesResources.The_definition_of_the_object_is_hidden, E_FAIL);
                }
                else
                {
                    return(false);
                }
            }
        }
示例#6
0
 public NavigateToSearchResult(string additionalInformation, string kind, NavigateToMatchKind matchKind, bool isCaseSensitive, string name, string secondarySort, string summary, INavigableItem navigableItem)
 {
     AdditionalInformation = additionalInformation;
     Kind = kind;
     MatchKind = matchKind;
     IsCaseSensitive = isCaseSensitive;
     Name = name;
     SecondarySort = secondarySort;
     Summary = summary;
     NavigableItem = navigableItem;
 }
示例#7
0
 public NavigateToSearchResult(string additionalInformation, string kind, NavigateToMatchKind matchKind, bool isCaseSensitive, string name, string secondarySort, string summary, INavigableItem navigableItem)
 {
     AdditionalInformation = additionalInformation;
     Kind            = kind;
     MatchKind       = matchKind;
     IsCaseSensitive = isCaseSensitive;
     Name            = name;
     SecondarySort   = secondarySort;
     Summary         = summary;
     NavigableItem   = navigableItem;
 }
        private AbstractTreeItem CreateTreeItem(INavigableItem item, int commonPathElements)
        {
            var result = new SourceReferenceTreeItem(item.Document, item.SourceSpan, item.Glyph.GetGlyphIndex(), commonPathElements, displayText: item.DisplayString, includeFileLocation: item.DisplayFileLocation);

            if (!item.ChildItems.IsEmpty)
            {
                var childItems = CreateNavigableItemTreeItems(item.ChildItems, commonPathElements);
                result.Children.AddRange(childItems);
                result.SetReferenceCount(childItems.Count);
            }

            return(result);
        }
示例#9
0
 public static SerializableNavigableItem Dehydrate(INavigableItem item)
 {
     return new SerializableNavigableItem
     {
         Glyph = item.Glyph,
         DisplayTaggedParts = SerializableTaggedText.Dehydrate(item.DisplayTaggedParts),
         DisplayFileLocation = item.DisplayFileLocation,
         IsImplicitlyDeclared = item.IsImplicitlyDeclared,
         Document = item.Document.Id,
         SourceSpan = item.SourceSpan,
         ChildItems = SerializableNavigableItem.Dehydrate(item.ChildItems)
     };
 }
示例#10
0
 public SearchResult(
     LogicalDocument document, ISymbol declaredSymbol, string kind,
     NavigateToMatchKind matchKind, bool isCaseSensitive, INavigableItem navigableItem)
 {
     _document       = document;
     _declaredSymbol = declaredSymbol;
     Kind            = kind;
     MatchKind       = matchKind;
     IsCaseSensitive = isCaseSensitive;
     NavigableItem   = navigableItem;
     //SecondarySort = ConstructSecondarySortString(document, declaredSymbolInfo);
     SecondarySort = null;
 }
示例#11
0
 public static SerializableNavigableItem Dehydrate(INavigableItem item)
 {
     return(new SerializableNavigableItem
     {
         Glyph = item.Glyph,
         DisplayTaggedParts = SerializableTaggedText.Dehydrate(item.DisplayTaggedParts),
         DisplayFileLocation = item.DisplayFileLocation,
         IsImplicitlyDeclared = item.IsImplicitlyDeclared,
         Document = SerializableDocumentId.Dehydrate(item.Document),
         SourceSpan = SerializableTextSpan.Dehydrate(item.SourceSpan),
         ChildItems = SerializableNavigableItem.Dehydrate(item.ChildItems)
     });
 }
示例#12
0
 public static SerializableNavigableItem Dehydrate(INavigableItem item)
 {
     return(new SerializableNavigableItem
     {
         Glyph = item.Glyph,
         DisplayTaggedParts = item.DisplayTaggedParts,
         DisplayFileLocation = item.DisplayFileLocation,
         IsImplicitlyDeclared = item.IsImplicitlyDeclared,
         Document = item.Document.Id,
         SourceSpan = item.SourceSpan,
         ChildItems = item.ChildItems.SelectAsArray(Dehydrate)
     });
 }
示例#13
0
        private MenuItemModel GetMenuItem(INavigableItem item)
        {
            var result = new MenuItemModel()
            {
                MenuItem = item,
            };

            result.Children = item.Axes.GetChildren()
                .OfType<INavigableItem>()
                .Where(i => i.IncludedInNavigation.Value)
                .Select(c => GetMenuItem(c));

            return result;
        }
        private AbstractTreeItem CreateTreeItem(INavigableItem item)
        {
            var displayText = !item.ChildItems.IsEmpty ? item.DisplayName : null;
            var result      = new SourceReferenceTreeItem(item.Document, item.SourceSpan, item.Glyph.GetGlyphIndex(), displayText);

            if (!item.ChildItems.IsEmpty)
            {
                var childItems = CreateGoToDefinitionItems(item.ChildItems);
                result.Children.AddRange(childItems);
                result.SetReferenceCount(childItems.Count);
            }

            return(result);
        }
            // local functions
            static bool ShouldInclude(INavigableItem item, bool typeOnly)
            {
                if (item.Glyph is Glyph.Namespace)
                {
                    // Never return namespace symbols as part of the go to definition result.
                    return(false);
                }

                if (!typeOnly)
                {
                    return(true);
                }

                switch (item.Glyph)
                {
                case Glyph.ClassPublic:
                case Glyph.ClassProtected:
                case Glyph.ClassPrivate:
                case Glyph.ClassInternal:
                case Glyph.DelegatePublic:
                case Glyph.DelegateProtected:
                case Glyph.DelegatePrivate:
                case Glyph.DelegateInternal:
                case Glyph.EnumPublic:
                case Glyph.EnumProtected:
                case Glyph.EnumPrivate:
                case Glyph.EnumInternal:
                case Glyph.EventPublic:
                case Glyph.EventProtected:
                case Glyph.EventPrivate:
                case Glyph.EventInternal:
                case Glyph.InterfacePublic:
                case Glyph.InterfaceProtected:
                case Glyph.InterfacePrivate:
                case Glyph.InterfaceInternal:
                case Glyph.ModulePublic:
                case Glyph.ModuleProtected:
                case Glyph.ModulePrivate:
                case Glyph.ModuleInternal:
                case Glyph.StructurePublic:
                case Glyph.StructureProtected:
                case Glyph.StructurePrivate:
                case Glyph.StructureInternal:
                    return(true);

                default:
                    return(false);
                }
            }
示例#16
0
        public static TextSpan GetBoundedSpan(INavigableItem item, SourceText sourceText)
        {
            var spanStart = item.SourceSpan.Start;
            var spanEnd   = item.SourceSpan.End;

            if (item.IsStale)
            {
                // in the case of a stale item, the span may be out of bounds of the document. Cap
                // us to the end of the document as that's where we're going to navigate the user
                // to.
                spanStart = spanStart > sourceText.Length ? sourceText.Length : spanStart;
                spanEnd   = spanEnd > sourceText.Length ? sourceText.Length : spanEnd;
            }

            return(TextSpan.FromBounds(spanStart, spanEnd));
        }
        protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
        {
            FrameworkElement frameworkElement = container as FrameworkElement;

            if (frameworkElement == null || item == null || !(item is INavigableItem))
            {
                return(null);
            }
            INavigableItem navigableItem = item as INavigableItem;

            if (navigableItem.IsVirtualItem)
            {
                return(this.VirtualItemTemplate);
            }
            return(this.ContentItemTemplate);
        }
            // local functions
            static bool ShouldInclude(INavigableItem item, bool typeOnly)
            {
                if (!typeOnly)
                {
                    return(true);
                }

                switch (item.Glyph)
                {
                case Glyph.ClassPublic:
                case Glyph.ClassProtected:
                case Glyph.ClassPrivate:
                case Glyph.ClassInternal:
                case Glyph.DelegatePublic:
                case Glyph.DelegateProtected:
                case Glyph.DelegatePrivate:
                case Glyph.DelegateInternal:
                case Glyph.EnumPublic:
                case Glyph.EnumProtected:
                case Glyph.EnumPrivate:
                case Glyph.EnumInternal:
                case Glyph.EventPublic:
                case Glyph.EventProtected:
                case Glyph.EventPrivate:
                case Glyph.EventInternal:
                case Glyph.InterfacePublic:
                case Glyph.InterfaceProtected:
                case Glyph.InterfacePrivate:
                case Glyph.InterfaceInternal:
                case Glyph.ModulePublic:
                case Glyph.ModuleProtected:
                case Glyph.ModulePrivate:
                case Glyph.ModuleInternal:
                case Glyph.StructurePublic:
                case Glyph.StructureProtected:
                case Glyph.StructurePrivate:
                case Glyph.StructureInternal:
                    return(true);

                default:
                    return(false);
                }
            }
 public SearchResult(
     Document document,
     DeclaredSymbolInfo declaredSymbolInfo,
     string kind,
     NavigateToMatchKind matchKind,
     bool isCaseSensitive,
     INavigableItem navigableItem,
     ImmutableArray <TextSpan> nameMatchSpans,
     ImmutableArray <Project> additionalMatchingProjects)
 {
     Name                  = declaredSymbolInfo.Name;
     Kind                  = kind;
     MatchKind             = matchKind;
     IsCaseSensitive       = isCaseSensitive;
     NavigableItem         = navigableItem;
     NameMatchSpans        = nameMatchSpans;
     AdditionalInformation = ComputeAdditionalInformation(document, declaredSymbolInfo, additionalMatchingProjects);
     SecondarySort         = ConstructSecondarySortString(document, declaredSymbolInfo);
 }
        private AbstractTreeItem CreateTreeItem(INavigableItem item, int commonPathElements)
        {
            var displayText = !item.ChildItems.IsEmpty ? item.DisplayName : null;
            var result = new SourceReferenceTreeItem(item.Document, item.SourceSpan, item.Glyph.GetGlyphIndex(), commonPathElements, displayText);

            if (!item.ChildItems.IsEmpty)
            {
                var childItems = CreateNavigableItemTreeItems(item.ChildItems, commonPathElements);
                result.Children.AddRange(childItems);
                result.SetReferenceCount(childItems.Count);
            }

            return result;
        }
示例#21
0
        public static void Show(string groupName, string entityName = null)
        {
            if (MEF.Application == null || MEF.Application.ExplorerGroupsManager == null)
            {
                return;
            }

            var groupsManager = MEF.Application.ExplorerGroupsManager.Value;

            if (groupsManager == null)
            {
                return;
            }

            //Left panel group items: { Resources, TestProcedures, Results, System, Data, TestExecution }
            var groups = ObjectExtensions.GetProperty <IEnumerable <Lazy <IItemContainerWithState <IReadOnlyDisplayItem>, IActiveItemMetadata> > >(groupsManager, "Items");

            if (groups == null)
            {
                return;
            }

            INavigableItem view = null;

            foreach (var group in groups)
            {
                //Specific view as determined by Type <T> (i.e. Tests view)
                if (((IItemsCollection <Lazy <INavigableItem, IExplorerItemMetadata> >)group.Value.Item).Items.Any(x => x.Metadata.Uri.Contains(groupName)))
                {
                    view = ((IItemsCollection <Lazy <INavigableItem, IExplorerItemMetadata> >)group.Value.Item).Items.FirstOrDefault(x => x.Metadata.Uri.Contains(groupName)).Value;
                    break;
                }
            }
            if (view == null)
            {
                return;
            }

            if (entityName == null)
            {
                //No entity specified, load top level view (i.e. show all tests)
                MEF.Application.WorkspaceManager.Value.ActivateItem(view);
                return;
            }

            var entityView = ((IItemsCollection <Lazy <IEntityViewModel> >)view).Items.FirstOrDefault(x => x.Value.Name.Value == entityName);

            if (entityView == null)
            {
                return;
            }

            var selectedItem = ObjectExtensions.GetProperty <IObservableValue <Lazy <IEntityViewModel> > >(view, "SelectedItem");

            if (selectedItem == null)
            {
                return;
            }

            var commands = ObjectExtensions.GetProperty <ICommandViewModelManager>(view, "Commands");

            if (commands == null)
            {
                return;
            }

            var command = commands.Commands.FirstOrDefault(x => x.Value.DisplayName == "Edit").Value.Command;

            if (command == null)
            {
                return;
            }

            //Set the selected item to the entity having specified entityName and execute the 'edit' command
            selectedItem.Value = entityView;
            command.Execute(new object());
        }
        private AbstractTreeItem CreateTreeItem(INavigableItem item, int commonPathElements)
        {
            var result = new SourceReferenceTreeItem(
                item.Document, item.SourceSpan, item.Glyph.GetGlyphIndex(), commonPathElements,
                displayText: item.DisplayTaggedParts.JoinText(),
                includeFileLocation: item.DisplayFileLocation);

            if (!item.ChildItems.IsEmpty)
            {
                var childItems = CreateNavigableItemTreeItems(item.ChildItems, commonPathElements);
                result.Children.AddRange(childItems);
                result.SetReferenceCount(childItems.Count);
            }

            return result;
        }