提交 e49eebfe 编写于 作者: B Brett Forsgren

Merge pull request #7996 from brettfo/file-graph-query

don't assume a file uri is absolute
......@@ -53,9 +53,11 @@ public async Task<GraphBuilder> 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);
}
......
' 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
<Fact, Trait(Traits.Feature, Traits.Features.Progression)>
Public Async Function ContainsChildrenForDocument() As Threading.Tasks.Task
Public Async Function ContainsChildrenForDocument() As Task
Using testState = Await ProgressionTestState.CreateAsync(
<Workspace>
<Project Language="C#" CommonReferences="true" FilePath="Z:\Project.csproj">
......@@ -38,7 +40,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Progression
End Function
<Fact, Trait(Traits.Feature, Traits.Features.Progression)>
Public Async Function ContainsChildrenForEmptyDocument() As Threading.Tasks.Task
Public Async Function ContainsChildrenForEmptyDocument() As Task
Using testState = Await ProgressionTestState.CreateAsync(
<Workspace>
<Project Language="C#" CommonReferences="true" FilePath="Z:\Project.csproj">
......@@ -68,7 +70,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Progression
<WorkItem(789685)>
<WorkItem(794846)>
<Fact, Trait(Traits.Feature, Traits.Features.Progression)>
Public Async Function ContainsChildrenForNotYetLoadedSolution() As Threading.Tasks.Task
Public Async Function ContainsChildrenForNotYetLoadedSolution() As Task
Using testState = Await ProgressionTestState.CreateAsync(
<Workspace>
<Project Language="C#" CommonReferences="true" FilePath="Z:\Project.csproj">
......@@ -104,5 +106,40 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Progression
End Using
End Function
<WorkItem(165369, "https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems#_a=edit&id=165369")>
<Fact, Trait(Traits.Feature, Traits.Features.Progression)>
Public Async Function ContainsChildrenForNodeWithRelativeUriPath() As Task
Using testState = Await ProgressionTestState.CreateAsync(
<Workspace>
<Project Language="Visual Basic" CommonReferences="true" FilePath="Z:\Project.vbproj">
<Document FilePath="Z:\Project.vb">
Class C
End Class
</Document>
</Project>
</Workspace>)
' 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,
<DirectedGraph xmlns="http://schemas.microsoft.com/vs/2009/dgml">
<Nodes>
<Node Id="(@1)" Category="File" ContainsChildren="False"/>
</Nodes>
<Links/>
<IdentifierAliases>
<Alias n="1" Uri="File=/Z:/Project.vb"/>
</IdentifierAliases>
</DirectedGraph>)
End Using
End Function
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册