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

Merge pull request #4526 from brettfo/null-filepath-in-project

Don't execute a progression search query on projects without a FilePath.
......@@ -30,6 +30,13 @@ namespace Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
{
public partial class TestWorkspaceFactory
{
/// <summary>
/// This place-holder value is used to set a project's file path to be null. It was explicitly chosen to be
/// convoluted to avoid any accidental usage (e.g., what if I really wanted FilePath to be the string "null"?),
/// obvious to anybody debugging that it is a special value, and invalid as an actual file path.
/// </summary>
public const string NullFilePath = "NullFilePath::{AFA13775-BB7D-4020-9E58-C68CF43D8A68}";
private class TestDocumentationProvider : DocumentationProvider
{
protected override string GetDocumentationForSymbol(string documentationMemberID, CultureInfo preferredCulture, CancellationToken cancellationToken = default(CancellationToken))
......@@ -225,6 +232,11 @@ public static TestWorkspace CreateWorkspace(string xmlDefinition, bool completed
if (projectElement.Attribute(FilePathAttributeName) != null)
{
filePath = projectElement.Attribute(FilePathAttributeName).Value;
if (string.Compare(filePath, NullFilePath, StringComparison.Ordinal) == 0)
{
// allow explicit null file path
filePath = null;
}
}
else
{
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
......@@ -27,7 +26,10 @@ public async Task<GraphBuilder> GetGraphAsync(Solution solution, IGraphContext c
{
var graphBuilder = await GraphBuilder.CreateForInputNodesAsync(solution, context.InputNodes, cancellationToken).ConfigureAwait(false);
var searchTasks = solution.Projects.Select(p => ProcessProjectAsync(p, graphBuilder, cancellationToken)).ToArray();
var searchTasks = solution.Projects
.Where(p => p.FilePath != null)
.Select(p => ProcessProjectAsync(p, graphBuilder, cancellationToken))
.ToArray();
await Task.WhenAll(searchTasks).ConfigureAwait(false);
return graphBuilder;
......
' 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 Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Imports Microsoft.VisualStudio.GraphModel
Imports Microsoft.VisualStudio.LanguageServices.Implementation.Progression
Imports Roslyn.Test.Utilities
......@@ -376,5 +377,37 @@ End Namespace
</DirectedGraph>)
End Using
End Sub
<Fact, Trait(Traits.Feature, Traits.Features.Progression)>
Public Sub SearchWithNullFilePathsOnProject()
Using testState = New ProgressionTestState(
<Workspace>
<Project Language="C#" CommonReferences="true" FilePath=<%= TestWorkspaceFactory.NullFilePath %>>
<Document FilePath="Z:\SomeVenusDocument.aspx.cs">
namespace Animal { class Dog&lt;X&gt; { void Bark() { } } }
</Document>
</Project>
</Workspace>)
Dim outputContext = testState.GetGraphContextAfterQuery(New Graph(), New SearchGraphQuery(searchPattern:="A.D.B"), GraphContextDirection.Custom)
' When searching, don't descend into projects with a null FilePath because they are artifacts and not
' representable in the Solution Explorer, e.g., Venus projects create sub-projects with a null file
' path for each .aspx file. Documents, on the other hand, are never allowed to have a null file path
' and as such are not tested here. The project/document structure for these scenarios would look
' similar to this:
'
' Project: SomeVenusProject, FilePath=C:\path\to\project.csproj
' + Document: SomeVenusDocument.aspx, FilePath=C:\path\to\SomeVenusDocument.aspx
' + Project: 1_SomeNamespace_SomeVenusDocument.aspx, FilePath=null <- the problem is here
' + Document: SomeVenusDocument.aspx.cs
AssertSimplifiedGraphIs(
outputContext.Graph,
<DirectedGraph xmlns="http://schemas.microsoft.com/vs/2009/dgml">
<Nodes/>
<Links/>
</DirectedGraph>)
End Using
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册