public PythonNavigateToItemDisplay(NavigateToItem item) { _item = item; var tag = (PythonNavigateToItemProvider.ItemTag)item.Tag; _node = tag.Node; _icon = GetIcon(tag.GlyphService, _node.GlyphType); var descrItems = new List<DescriptionItem>(); IVsHierarchy hier; uint itemId; uint itemsCount; _node.SourceItems(out hier, out itemId, out itemsCount); if (hier != null) { descrItems.Add(new DescriptionItem( Array.AsReadOnly(new[] { new DescriptionRun("Project:", bold: true) }), Array.AsReadOnly(new[] { new DescriptionRun(hier.GetProject().FullName) }))); string fileName; hier.GetCanonicalName(itemId, out fileName); if (fileName != null) { descrItems.Add(new DescriptionItem( Array.AsReadOnly(new[] { new DescriptionRun("File:", bold: true) }), Array.AsReadOnly(new[] { new DescriptionRun(fileName) }))); var commonNode = _node as CommonLibraryNode; if (commonNode != null && commonNode.CanGoToSource) { descrItems.Add(new DescriptionItem( Array.AsReadOnly(new[] { new DescriptionRun("Line:", bold: true) }), Array.AsReadOnly(new[] { new DescriptionRun((commonNode.SourceSpan.iStartLine + 1).ToString()) }))); } } } _descrItems = descrItems.AsReadOnly(); }
public PythonNavigateToItemDisplay(NavigateToItem item) { _item = item; var tag = (PythonNavigateToItemProvider.ItemTag)item.Tag; _node = tag.Node; _icon = GetIcon(tag.GlyphService, _node.GlyphType); var descrItems = new List <DescriptionItem>(); IVsHierarchy hier; uint itemId; uint itemsCount; _node.SourceItems(out hier, out itemId, out itemsCount); if (hier != null) { descrItems.Add(new DescriptionItem( Array.AsReadOnly(new[] { new DescriptionRun("Project:", bold: true) }), Array.AsReadOnly(new[] { new DescriptionRun(hier.GetProject().FullName) }))); string fileName; hier.GetCanonicalName(itemId, out fileName); if (fileName != null) { descrItems.Add(new DescriptionItem( Array.AsReadOnly(new[] { new DescriptionRun("File:", bold: true) }), Array.AsReadOnly(new[] { new DescriptionRun(fileName) }))); var commonNode = _node as CommonLibraryNode; if (commonNode != null && commonNode.CanGoToSource) { descrItems.Add(new DescriptionItem( Array.AsReadOnly(new[] { new DescriptionRun("Line:", bold: true) }), Array.AsReadOnly(new[] { new DescriptionRun((commonNode.SourceSpan.iStartLine + 1).ToString()) }))); } } } _descrItems = descrItems.AsReadOnly(); }
public bool EnterNode(LibraryNode node, CancellationToken ct) { if (ct.IsCancellationRequested) { _navCallback.Invalidate(); return false; } IVsHierarchy hierarchy; uint itemId, itemsCount; Guid projectType; node.SourceItems(out hierarchy, out itemId, out itemsCount); if (hierarchy != null) { ErrorHandler.ThrowOnFailure(hierarchy.GetGuidProperty( (uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_TypeGuid, out projectType )); if (projectType != _projectType) { return false; } } var parentNode = _path.Peek(); _path.Push(node); // We don't want to report modules, since they map 1-to-1 to files, and those are already reported by the standard item provider if (node.NodeType.HasFlag(LibraryNodeType.Package)) { return true; } // Match name against search string. string name = node.Name ?? ""; MatchKind matchKind; if (_searchValue.Length > 2 && _searchValue.StartsWith("/") && _searchValue.EndsWith("/")) { if (!_regexComparer.IsCandidateMatch(name, _searchValue.Substring(1, _searchValue.Length - 2))) { return true; } matchKind = MatchKind.Regular; } else if (name.Equals(_searchValue, StringComparison.Ordinal)) { matchKind = MatchKind.Exact; } else if (_comparer.IsCandidateMatch(name, _searchValue)) { matchKind = MatchKind.Regular; } else { return true; } string kind; if (!_sggToNavItemKind.TryGetValue(node.GlyphType, out kind)) { kind = ""; } var text = node.GetTextRepresentation(VSTREETEXTOPTIONS.TTO_DISPLAYTEXT); if (parentNode != null) { switch (parentNode.GlyphType) { case StandardGlyphGroup.GlyphGroupModule: text += string.Format(" [of module {0}]", parentNode.Name); break; case StandardGlyphGroup.GlyphGroupClass: text += string.Format(" [of class {0}]", parentNode.Name); break; case StandardGlyphGroup.GlyphGroupMethod: text += string.Format(" [nested in function {0}]", parentNode.Name); break; } } var tag = new ItemTag { Node = node, GlyphService = _itemProvider._glyphService }; _navCallback.AddItem(new NavigateToItem(text, kind, "Python", "", tag, matchKind, PythonNavigateToItemDisplayFactory.Instance)); return true; }
public bool EnterNode(LibraryNode node, CancellationToken ct) { if (ct.IsCancellationRequested) { _navCallback.Invalidate(); return(false); } IVsHierarchy hierarchy; uint itemId, itemsCount; Guid projectType; node.SourceItems(out hierarchy, out itemId, out itemsCount); if (hierarchy != null) { ErrorHandler.ThrowOnFailure(hierarchy.GetGuidProperty( (uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_TypeGuid, out projectType )); if (projectType != _projectType) { return(false); } } var parentNode = _path.Peek(); _path.Push(node); // We don't want to report modules, since they map 1-to-1 to files, and those are already reported by the standard item provider if (node.NodeType.HasFlag(LibraryNodeType.Package)) { return(true); } // Match name against search string. string name = node.Name ?? ""; MatchKind matchKind; if (_searchValue.Length > 2 && _searchValue.StartsWith("/") && _searchValue.EndsWith("/")) { if (!_regexComparer.IsCandidateMatch(name, _searchValue.Substring(1, _searchValue.Length - 2))) { return(true); } matchKind = MatchKind.Regular; } else if (name.Equals(_searchValue, StringComparison.Ordinal)) { matchKind = MatchKind.Exact; } else if (_comparer.IsCandidateMatch(name, _searchValue)) { matchKind = MatchKind.Regular; } else { return(true); } string kind; if (!_sggToNavItemKind.TryGetValue(node.GlyphType, out kind)) { kind = ""; } var text = node.GetTextRepresentation(VSTREETEXTOPTIONS.TTO_DISPLAYTEXT); if (parentNode != null) { switch (parentNode.GlyphType) { case StandardGlyphGroup.GlyphGroupModule: text += string.Format(" [of module {0}]", parentNode.Name); break; case StandardGlyphGroup.GlyphGroupClass: text += string.Format(" [of class {0}]", parentNode.Name); break; case StandardGlyphGroup.GlyphGroupMethod: text += string.Format(" [nested in function {0}]", parentNode.Name); break; } } var tag = new ItemTag { Node = node, GlyphService = _itemProvider._glyphService }; _navCallback.AddItem(new NavigateToItem(text, kind, "Python", "", tag, matchKind, PythonNavigateToItemDisplayFactory.Instance)); return(true); }