diff --git a/src/VisualStudio/Core/Def/Implementation/Progression/GraphQueries/ContainsChildrenGraphQuery.cs b/src/VisualStudio/Core/Def/Implementation/Progression/GraphQueries/ContainsChildrenGraphQuery.cs index ff6d7ce9a4ee132b2ca146c11afeefee7873ca25..02b5b060c39fa0f4174c98e91ed55d65faefde25 100644 --- a/src/VisualStudio/Core/Def/Implementation/Progression/GraphQueries/ContainsChildrenGraphQuery.cs +++ b/src/VisualStudio/Core/Def/Implementation/Progression/GraphQueries/ContainsChildrenGraphQuery.cs @@ -53,9 +53,11 @@ public async Task GetGraphAsync(Solution solution, IGraphContext c // even when its extension fails to say so. One option would be to call DTEWrapper.IsRegisteredForLangService, // which may not be called here however since deadlock could happen. - string ext = Path.GetExtension(uri.AbsolutePath); - if (!string.IsNullOrEmpty(ext) && - (ext.Equals(".cs", StringComparison.OrdinalIgnoreCase) || ext.Equals(".vb", StringComparison.OrdinalIgnoreCase))) + // The Uri returned by `GetNestedValueByName()` above isn't necessarily absolute and the `OriginalString` is + // the only property that doesn't throw if the UriKind is relative, so `OriginalString` must be used instead + // of `AbsolutePath`. + string ext = Path.GetExtension(uri.OriginalString); + if (ext.Equals(".cs", StringComparison.OrdinalIgnoreCase) || ext.Equals(".vb", StringComparison.OrdinalIgnoreCase)) { graphBuilder.AddDeferredPropertySet(node, DgmlNodeProperties.ContainsChildren, false); } diff --git a/src/VisualStudio/Core/Test/Progression/ContainsChildrenGraphQueryTests.vb b/src/VisualStudio/Core/Test/Progression/ContainsChildrenGraphQueryTests.vb index 6e38cac13eacef5744924af56c995d4d7d9e7457..0ead7a0cb51425c62d213be0073a8b04630bed57 100644 --- a/src/VisualStudio/Core/Test/Progression/ContainsChildrenGraphQueryTests.vb +++ b/src/VisualStudio/Core/Test/Progression/ContainsChildrenGraphQueryTests.vb @@ -1,13 +1,15 @@ ' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +Imports System.Threading.Tasks Imports Microsoft.VisualStudio.GraphModel +Imports Microsoft.VisualStudio.GraphModel.Schemas Imports Microsoft.VisualStudio.LanguageServices.Implementation.Progression Imports Roslyn.Test.Utilities Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Progression Public Class ContainsChildrenGraphQueryTests - Public Async Function ContainsChildrenForDocument() As Threading.Tasks.Task + Public Async Function ContainsChildrenForDocument() As Task Using testState = Await ProgressionTestState.CreateAsync( @@ -38,7 +40,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Progression End Function - Public Async Function ContainsChildrenForEmptyDocument() As Threading.Tasks.Task + Public Async Function ContainsChildrenForEmptyDocument() As Task Using testState = Await ProgressionTestState.CreateAsync( @@ -68,7 +70,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Progression - Public Async Function ContainsChildrenForNotYetLoadedSolution() As Threading.Tasks.Task + Public Async Function ContainsChildrenForNotYetLoadedSolution() As Task Using testState = Await ProgressionTestState.CreateAsync( @@ -104,5 +106,40 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Progression End Using End Function + + + + Public Async Function ContainsChildrenForNodeWithRelativeUriPath() As Task + Using testState = Await ProgressionTestState.CreateAsync( + + + + Class C + End Class + + + ) + + ' Force creation of a graph node that has a nested relative URI file path. This simulates nodes that + ' other project types can give us for non-code files. E.g., `favicon.ico` for web projects. + Dim nodeId = GraphNodeId.GetNested(GraphNodeId.GetPartial(CodeGraphNodeIdName.File, New Uri("/Z:/Project.vb", UriKind.Relative))) + Dim inputGraph = New Graph() + Dim node = inputGraph.Nodes.GetOrCreate(nodeId) + node.AddCategory(CodeNodeCategories.File) + + Dim outputContext = Await testState.GetGraphContextAfterQuery(inputGraph, New ContainsChildrenGraphQuery(), GraphContextDirection.Any) + AssertSimplifiedGraphIs( + outputContext.Graph, + + + + + + + + + ) + End Using + End Function End Class End Namespace