public virtual bool Supports(IVsHierarchyItem item) { var project = item.GetExtenderObject() as EnvDTE.Project; return project != null && project.Object is EnvDTE80.SolutionFolder; }
bool Supports (IVsHierarchyItem item, out IVsHierarchyItem actualItem) { actualItem = item; if (!item.HierarchyIdentity.IsRoot) return false; // We need the hierarchy fully loaded if it's not yet. if (!item.GetProperty<bool> (__VSPROPID4.VSPROPID_IsSolutionFullyLoaded)) { Guid guid; if (ErrorHandler.Succeeded (item.GetActualHierarchy ().GetGuidProperty ((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out guid)) && // For the solution root item itself, the GUID will be empty. guid != Guid.Empty) { if (ErrorHandler.Succeeded (((IVsSolution4)solution.Value).EnsureProjectIsLoaded (ref guid, (uint)__VSBSLFLAGS.VSBSLFLAGS_None))) actualItem = hierarchyManager.GetHierarchyItem (item.GetActualHierarchy (), item.GetActualItemId ()); } } if (!(actualItem.GetActualHierarchy () is IVsProject)) return false; // Finally, solution folders look like projects, but they are not. // We need to filter them out too. var extenderObject = actualItem.GetExtenderObject(); var dteProject = extenderObject as EnvDTE.Project; if (extenderObject != null && extenderObject.GetType ().FullName == "Microsoft.VisualStudio.Project.Automation.OAProject") return false; if (extenderObject != null && dteProject != null && (dteProject.Object is EnvDTE80.SolutionFolder)) return false; return true; }
// Returns true if filters hierarchy item name for given filter; otherwise, false</returns> private bool ShouldIncludeInFilter(IVsHierarchyItem hierarchyItem) { if (hierarchyItem?.CanonicalName == null) return false; UnifiedDiff diff; return _pullRequestFilterProvider.UnifiedDiffs.TryGetValue(hierarchyItem.CanonicalName, out diff); }
public ISolutionExplorerNode CreateNode(IVsHierarchyItem item) { if (item == null) return null; var factory = customFactories.FirstOrDefault(f => f.Supports(item)) ?? defaultFactories.FirstOrDefault(f => f.Supports(item)); return factory == null ? new GenericNode(item, this, adapter, solutionExplorer) : factory.CreateNode(item); }
public AnalyzersFolderItemSource(Workspace workspace, ProjectId projectId, IVsHierarchyItem projectHierarchyItem) { _workspace = workspace; _projectId = projectId; _projectHierarchyItem = projectHierarchyItem; _folderItems = new ObservableCollection<AnalyzersFolderItem>(); Update(); }
public virtual bool Supports(IVsHierarchyItem item) { // TODO: why wouldn't something like this work? // // ((VSProject)((Project)hierarchyNode.GetExtenderObject ()).Object).References); // \o/: heuristics, no extender object and "References" display name :S var extObj = item.GetExtenderObject(); // TODO: see if we get the VSProject from VSLangProj and compare to the References property there. return extObj == null && item.Text == "References"; }
/// <summary> /// Initializes a new instance of the <see cref="ProjectItemNode"/> class. /// </summary> /// <param name="kind">The kind of project node.</param> /// <param name="hierarchyNode">The underlying hierarchy represented by this node.</param> /// <param name="nodeFactory">The factory for child nodes.</param> /// <param name="adapter">The adapter service that implements the smart cast <see cref="ISolutionExplorerNode.As{T}"/>.</param> public ProjectItemNode( SolutionNodeKind kind, IVsHierarchyItem hierarchyNode, ISolutionExplorerNodeFactory nodeFactory, IAdapterService adapter, Lazy<IVsUIHierarchyWindow> solutionExplorer) : base(kind, hierarchyNode, nodeFactory, adapter, solutionExplorer) { this.nodeFactory = nodeFactory; owningProject = new Lazy<IProjectNode>(() => this.nodeFactory.CreateNode(hierarchyNode.GetRoot ()) as IProjectNode); }
public AnalyzersFolderItem( Workspace workspace, ProjectId projectId, IVsHierarchyItem parentItem, IContextMenuController contextMenuController) : base(SolutionExplorerShim.AnalyzersFolderItem_Name) { _workspace = workspace; _projectId = projectId; _parentItem = parentItem; _contextMenuController = contextMenuController; }
public virtual bool Supports(IVsHierarchyItem hierarchy) { if (hierarchy.Parent == null) return false; var ext = hierarchy.GetExtenderObject(); var item = ext as ProjectItem; var project = hierarchy.Parent.GetExtenderObject() as Project; return project != null && item != null && project.Object is EnvDTE80.SolutionFolder; }
public virtual bool Supports(IVsHierarchyItem item) { var extenderObject = item.GetExtenderObject(); var projectItem = extenderObject as EnvDTE.ProjectItem; if (extenderObject == null || projectItem == null) return false; try { // Fails in F# projects. return projectItem.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFile; } catch (Exception) { return false; } }
//Lazy<string> name; //Lazy<string> caption; internal VsSolutionItemNode (IVsHierarchyItem item) { if (item.HierarchyIdentity.IsNestedItem) { VsHierarchy = item.HierarchyIdentity.NestedHierarchy; ItemId = item.HierarchyIdentity.NestedItemID; } else { VsHierarchy = item.HierarchyIdentity.Hierarchy; ItemId = item.HierarchyIdentity.ItemID; } extensibilityObject = new Lazy<object>(() => item.GetProperty((int)__VSHPROPID.VSHPROPID_ExtObject)); serviceProvider = new Lazy<IServiceProvider> (() => item.GetServiceProvider ()); //name = new Lazy<string> (() => item.GetProperty<string> ((int)__VSHPROPID.VSHPROPID_Name)); //caption = new Lazy<string> (() => item.GetProperty<string> ((int)__VSHPROPID.VSHPROPID_Caption)); parent = new Lazy<VsSolutionItemNode> (() => item.Parent == null ? null : new VsSolutionItemNode (item.Parent)); }
public virtual bool Supports (IVsHierarchyItem item) { var extenderObject = item.GetExtenderObject(); var projectItem = extenderObject as EnvDTE.ProjectItem; if (extenderObject == null || projectItem == null) return false; if (extenderObject.GetType ().FullName == "Microsoft.VisualStudio.Project.Automation.OAFolderItem") return true; try { // Fails in F# projects. return projectItem.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFolder; } catch (Exception) { return false; } }
public bool TryGetProjectId(IVsHierarchyItem hierarchyItem, out ProjectId projectId) { var project = _workspace.ProjectTracker.ImmutableProjects .Where(p => p.Hierarchy == hierarchyItem.HierarchyIdentity.NestedHierarchy) .Where(p => p.ProjectSystemName == hierarchyItem.CanonicalName) .SingleOrDefault(); if (project == null) { projectId = default(ProjectId); return false; } else { projectId = project.Id; return true; } }
public bool TryGetHierarchyItem(IVsHierarchy hierarchy, uint itemid, out IVsHierarchyItem item) { item = null; return false; }
public void SubmitResult(IRelatableItem?item) { if (item == null) { return; } item = DeduplicateItem(item); PopulateAncestors(item); _inner.SubmitResult(item); void PopulateAncestors(IRelatableItem childItem) { if (childItem.ContainedByCollection != null) { // We've already populated this item's ancestors. It's likely an ancestor of // another search result. This also prevents runaway in case of cycles. return; } ImmutableArray <IRelation> containedByRelations = _relationProvider.GetContainedByRelationsFor(childItem.GetType()); if (containedByRelations.IsEmpty) { // We should never have a scenario where an item type does not have a parent. TraceUtilities.TraceError($"No IRelation exports exist that provide parent (ContainedBy) items for type {childItem.GetType()}."); return; } var allParentItems = new List <object>(); foreach (IRelation relation in containedByRelations) { IEnumerable <IRelatableItem>?relationParentItems = relation.CreateContainedByItems(childItem); if (relationParentItems != null) { foreach (IRelatableItem parentItem in relationParentItems) { IRelatableItem deduplicateItem = DeduplicateItem(parentItem); allParentItems.Add(deduplicateItem); if (deduplicateItem.TryGetProjectNode(_targetRootNode, parentItem, out IProjectTree? projectNode)) { uint itemId = (uint)projectNode.Identity.ToInt32(); IVsHierarchyItem hierarchyItem = _hierarchyItemManager.GetHierarchyItem(_projectVsServices.VsHierarchy, itemId); allParentItems.Add(hierarchyItem); } if (deduplicateItem.ContainedByCollection == null) { PopulateAncestors(deduplicateItem); } } } } childItem.ContainedByCollection = new AggregateContainedByRelationCollection(allParentItems); } IRelatableItem DeduplicateItem(IRelatableItem item) { object key = GetItemKey(item); if (_itemByKey.TryGetValue(key, out IRelatableItem existingItem)) { return(existingItem); } _itemByKey.Add(key, item); return(item); } }
public virtual bool Supports(IVsHierarchyItem item) => item.GetExtenderObject() is VSLangProj.Reference;
public virtual ISolutionExplorerNode CreateNode(IVsHierarchyItem item) => Supports(item) ? new SolutionItemNode(item, childNodeFactory.Value, adapter, solutionExplorer) : null;
public bool TryGetProjectId(IVsHierarchyItem hierarchyItem, string targetFrameworkMoniker, out ProjectId projectId) { if (_workspace.DeferredState == null) { projectId = default(ProjectId); return(false); } // A project node is represented in two different hierarchies: the solution's IVsHierarchy (where it is a leaf node) // and the project's own IVsHierarchy (where it is the root node). The IVsHierarchyItem joins them together for the // purpose of creating the tree displayed in Solution Explorer. The project's hierarchy is what is passed from the // project system to the language service, so that's the one the one to query here. To do that we need to get // the "nested" hierarchy from the IVsHierarchyItem. var nestedHierarchy = hierarchyItem.HierarchyIdentity.NestedHierarchy; var nestedHierarchyId = hierarchyItem.HierarchyIdentity.NestedItemID; if (!nestedHierarchy.TryGetCanonicalName(nestedHierarchyId, out string nestedCanonicalName) || !nestedHierarchy.TryGetItemName(nestedHierarchyId, out string nestedName)) { projectId = default(ProjectId); return(false); } var project = _workspace.DeferredState.ProjectTracker.ImmutableProjects .Where(p => { // Here we try to match the hierarchy from Solution Explorer to a hierarchy from the Roslyn project. // The canonical name of a hierarchy item must be unique _within_ an hierarchy, but since we're // examining multiple hierarchies the canonical name could be the same. Indeed this happens when two // project files are in the same folder--they both use the full path to the _folder_ as the canonical // name. To distinguish them we also examine the "regular" name, which will necessarily be different // if the two projects are in the same folder. if (p.Hierarchy.TryGetCanonicalName((uint)VSConstants.VSITEMID.Root, out string projectCanonicalName) && p.Hierarchy.TryGetItemName((uint)VSConstants.VSITEMID.Root, out string projectName) && projectCanonicalName.Equals(nestedCanonicalName, System.StringComparison.OrdinalIgnoreCase) && projectName.Equals(nestedName)) { if (targetFrameworkMoniker == null) { return(true); } return(p.Hierarchy.TryGetTargetFrameworkMoniker((uint)VSConstants.VSITEMID.Root, out string projectTargetFrameworkMoniker) && projectTargetFrameworkMoniker.Equals(targetFrameworkMoniker)); } return(false); }) .SingleOrDefault(); if (project == null) { projectId = default(ProjectId); return(false); } else { projectId = project.Id; return(true); } }
public virtual ISolutionExplorerNode CreateNode(IVsHierarchyItem item) => Supports(item) ? new SolutionNode(services, item, nodeFactory.Value, adapter, selection, solutionExplorer) : null;
Lazy<ISolutionExplorerNode> GetParent (IVsHierarchyItem hierarchy) => hierarchy.Parent == null ? null : new Lazy<ISolutionExplorerNode> (() => this.nodeFactory.CreateNode (hierarchy.Parent));
public static object GetProperty(this IVsHierarchyItem item, int propId, object defaultValue = null) { return(GetProperty <object>(item, propId, defaultValue)); }
/// <summary> /// Gets the DTE extensibility object for the given hierarchy item. /// </summary> public static T GetExtenderObject <T>(this IVsHierarchyItem item) { return((T)GetExtenderObject(item)); }
/// <summary> /// Gets the DTE extensibility object for the given hierarchy item. /// </summary> public static object GetExtenderObject(this IVsHierarchyItem item) { return(item.GetProperty((int)__VSHPROPID.VSHPROPID_ExtObject)); }
/// <summary> /// Gets the actual item id, which is the nested id if the item is nested. /// </summary> public static uint GetActualItemId(this IVsHierarchyItem item) { return(item.HierarchyIdentity.IsNestedItem ? item.HierarchyIdentity.NestedItemID : item.HierarchyIdentity.ItemID); }
/// <summary> /// Gets the actual item hierarchy, which is the nested hierarchy if the item is nested. /// </summary> public static IVsHierarchy GetActualHierarchy(this IVsHierarchyItem item) { return(item.HierarchyIdentity.IsNestedItem ? item.HierarchyIdentity.NestedHierarchy : item.HierarchyIdentity.Hierarchy); }
Lazy <ISolutionExplorerNode> GetParent(IVsHierarchyItem hierarchy) => hierarchy.Parent == null ? null : new Lazy <ISolutionExplorerNode>(() => nodeFactory.CreateNode(hierarchy.Parent));
public static T GetProperty <T>(this IVsHierarchyItem item, __VSPROPID5 propId, T defaultValue = default(T)) { return(item.GetProperty <T>((int)propId, defaultValue)); }
public ItemProperties(ItemNode item) { this.item = item.HierarchyNode.GetExtenderObject() as ProjectItem; node = item.HierarchyNode; msBuild = item.OwningProject.AsVsBuildPropertyStorage(); }
public bool Contains(IVsHierarchyItem item) => filteredItems.Contains(item);
public virtual bool Supports(IVsHierarchyItem item) => item.HierarchyIdentity.Hierarchy is IVsSolution;
/// <summary> /// Creates a new instance of the solution item. /// </summary> protected SolutionItem(IVsHierarchyItem item, SolutionItemType type) { ThreadHelper.ThrowIfNotOnUIThread(); Type = type; Update(item); }
public CpsDiagnosticItemSource(Workspace workspace, string projectPath, ProjectId projectId, IVsHierarchyItem item, IAnalyzersCommandHandler commandHandler, IDiagnosticAnalyzerService analyzerService) : base(workspace, projectId, commandHandler, analyzerService) { _item = item; _projectDirectoryPath = Path.GetDirectoryName(projectPath); _analyzerReference = TryGetAnalyzerReference(Workspace.CurrentSolution); if (_analyzerReference == null) { // The workspace doesn't know about the project and/or the analyzer yet. // Hook up an event handler so we can update when it does. Workspace.WorkspaceChanged += OnWorkspaceChangedLookForAnalyzer; } }
public virtual ISolutionExplorerNode CreateNode (IVsHierarchyItem item) => Supports (item) ? new FolderNode (item, childNodeFactory.Value, adapter, solutionExplorer) : null;
public ItemProperties(ItemNode item) { this.item = item.HierarchyNode.GetExtenderObject() as ProjectItem; node = item.HierarchyNode; msBuild = item.HierarchyNode.GetRoot().HierarchyIdentity.Hierarchy as IVsBuildPropertyStorage; }
public bool TryGetProjectId(IVsHierarchyItem hierarchyItem, string targetFrameworkMoniker, out ProjectId projectId) { // A project node is represented in two different hierarchies: the solution's IVsHierarchy (where it is a leaf node) // and the project's own IVsHierarchy (where it is the root node). The IVsHierarchyItem joins them together for the // purpose of creating the tree displayed in Solution Explorer. The project's hierarchy is what is passed from the // project system to the language service, so that's the one the one to query here. To do that we need to get // the "nested" hierarchy from the IVsHierarchyItem. var nestedHierarchy = hierarchyItem.HierarchyIdentity.NestedHierarchy; var nestedHierarchyId = hierarchyItem.HierarchyIdentity.NestedItemID; if (!nestedHierarchy.TryGetCanonicalName(nestedHierarchyId, out string nestedCanonicalName) || !nestedHierarchy.TryGetItemName(nestedHierarchyId, out string nestedName)) { projectId = default(ProjectId); return(false); } // First filter the projects by matching up properties on the input hierarchy against properties on each // project's hierarchy. var candidateProjects = _workspace.CurrentSolution.Projects .Where(p => { // We're about to access various properties of the IVsHierarchy associated with the project. // The properties supported and the interpretation of their values varies from one project system // to another. This code is designed with C# and VB in mind, so we need to filter out everything // else. if (p.Language != LanguageNames.CSharp && p.Language != LanguageNames.VisualBasic) { return(false); } // Here we try to match the hierarchy from Solution Explorer to a hierarchy from the Roslyn project. // The canonical name of a hierarchy item must be unique _within_ an hierarchy, but since we're // examining multiple hierarchies the canonical name could be the same. Indeed this happens when two // project files are in the same folder--they both use the full path to the _folder_ as the canonical // name. To distinguish them we also examine the "regular" name, which will necessarily be different // if the two projects are in the same folder. // Note that if a project has been loaded with Lightweight Solution Load it won't even have a // hierarchy, so we need to check for null first. var hierarchy = _workspace.GetHierarchy(p.Id); if (hierarchy != null && hierarchy.TryGetCanonicalName((uint)VSConstants.VSITEMID.Root, out string projectCanonicalName) && hierarchy.TryGetItemName((uint)VSConstants.VSITEMID.Root, out string projectName) && projectCanonicalName.Equals(nestedCanonicalName, System.StringComparison.OrdinalIgnoreCase) && projectName.Equals(nestedName)) { if (targetFrameworkMoniker == null) { return(true); } return(hierarchy.TryGetTargetFrameworkMoniker((uint)VSConstants.VSITEMID.Root, out string projectTargetFrameworkMoniker) && projectTargetFrameworkMoniker.Equals(targetFrameworkMoniker)); } return(false); }) .ToArray(); // If we only have one candidate then no further checks are required. if (candidateProjects.Length == 1) { projectId = candidateProjects[0].Id; return(true); } // If we have multiple candidates then we might be dealing with Web Application Projects. In this case // there will be one main project plus one project for each open aspx/cshtml/vbhtml file, all with // identical properties on their hierarchies. We can find the main project by taking the first project // without a ContainedDocument. foreach (var candidateProject in candidateProjects) { if (!candidateProject.DocumentIds.Any(id => ContainedDocument.TryGetContainedDocument(id) != null)) { projectId = candidateProject.Id; return(true); } } projectId = default(ProjectId); return(false); }
public virtual bool Supports (IVsHierarchyItem item) => item.HierarchyIdentity.Hierarchy is IVsSolution;
public IProjectNode WithInnerHierarchy(IVsHierarchyItem innerHierarchyItem) => new ProjectNode(hierarchyItem, nodeFactory, adapter, solutionExplorer, ExpressionEvaluator, innerHierarchyItem);
/// <summary> /// Creates a new child node using the node factory received in the constructor. /// </summary> /// <param name="item">The hierarchy node to create the child node for.</param> /// <remarks> /// This method is used for example when the node exposes child node creation APIs, such as /// the <see cref="FolderNode"/>. /// </remarks> protected virtual ISolutionExplorerNode CreateNode(IVsHierarchyItem item) => nodeFactory.CreateNode(item);
public virtual bool Supports (IVsHierarchyItem item) => Supports (item, out item);
internal PhysicalFile(IVsHierarchyItem item, SolutionItemType type) : base(item, type) { ThreadHelper.ThrowIfNotOnUIThread(); }
public virtual bool Supports(IVsHierarchyItem item) => Supports(item, out item);
public bool TryGetHierarchyItem(IVsHierarchy hierarchy, uint itemid, out IVsHierarchyItem item) { item = null; return(false); }
public virtual ISolutionExplorerNode CreateNode(IVsHierarchyItem item) => Supports(item, out item) ? new ProjectNode(item, childNodeFactory.Value, adapter, solutionExplorer, expressionEvaluator) : null;
public virtual ISolutionExplorerNode CreateNode (IVsHierarchyItem item) => Supports (item, out item) ? new ProjectNode (item, childNodeFactory.Value, adapter, solutionExplorer, expressionEvaluator) : null;
/// <summary> /// Creates collection sources for selected hierarchy items, depending upon the implementation. /// </summary> /// <remarks> /// Only called for hierarchy items whose flags match those passed to the constructor. <paramref name="flagsString"/> is /// provided in case further information is needed. /// </remarks> protected abstract bool TryCreateCollectionSource( IVsHierarchyItem hierarchyItem, string flagsString, string?target, IRelationProvider relationProvider, [NotNullWhen(returnValue: true)] out AggregateRelationCollectionSource?containsCollectionSource);
public ItemProperties (ItemNode item) { this.item = item.HierarchyNode.GetExtenderObject () as ProjectItem; node = item.HierarchyNode; msBuild = item.HierarchyNode.GetRoot ().HierarchyIdentity.Hierarchy as IVsBuildPropertyStorage; }
/// <summary> /// Gets information from the underlying data types. /// </summary> public void GetItemInfo(out IVsHierarchy hierarchy, out uint itemId, out IVsHierarchyItem hierarchyItem) { hierarchy = _hierarchy; itemId = _itemId; hierarchyItem = _item; }
public virtual ISolutionExplorerNode CreateNode (IVsHierarchyItem item) => Supports (item) ? new SolutionNode (services, item, nodeFactory.Value, adapter, selection, solutionExplorer) : null;
private static bool MeetsFilter(IVsHierarchyItem item) { return((item != null) && _pattern.IsMatch(item.Text)); }