From f67c2474a3cb6bec0e5d5a320c370b9564a06be6 Mon Sep 17 00:00:00 2001 From: Tom Meschter Date: Thu, 11 May 2017 14:17:01 -0700 Subject: [PATCH] Filter projects based on language name Avoids [VSO bug 433873](https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems/edit/433873). When mapping an `IVsHierarchy` to the related Roslyn project we end up asking each project for its associated `IVsHierarchy` and checking if various properties match up with those on the "origin" hierarchy. The properties supported and the interpretation of their values varies from one project system to another. The `HierarchyItemToProjectIdMap` class was implemented when Roslyn only supported C# and VB projects, and was designed with those in mind. Now that TypeScript can also have Roslyn projects we need to filter out everything that isn't C# or VB or we risk asking for properties that aren't supported or possibly misinterpret the values. --- .../HierarchyItemToProjectIdMap.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/VisualStudio/Core/SolutionExplorerShim/HierarchyItemToProjectIdMap.cs b/src/VisualStudio/Core/SolutionExplorerShim/HierarchyItemToProjectIdMap.cs index 46c6e7688b7d1..4932a8941a31c 100644 --- a/src/VisualStudio/Core/SolutionExplorerShim/HierarchyItemToProjectIdMap.cs +++ b/src/VisualStudio/Core/SolutionExplorerShim/HierarchyItemToProjectIdMap.cs @@ -6,7 +6,6 @@ using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem; using Microsoft.VisualStudio.Shell; -using Microsoft.VisualStudio.Shell.Interop; namespace Microsoft.VisualStudio.LanguageServices.Implementation.SolutionExplorer { @@ -47,6 +46,16 @@ public bool TryGetProjectId(IVsHierarchyItem hierarchyItem, string targetFramewo var project = _workspace.DeferredState.ProjectTracker.ImmutableProjects .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