提交 786eeffd 编写于 作者: A Artur Spychaj

Merge pull request #7811 from drognanar/issue7645

Construct submissions with empty file path in VS
......@@ -202,6 +202,38 @@ class D { }
}
}
[Fact]
public async void TestAddedSubmissionParseTreeHasEmptyFilePath()
{
using (var workspace = CreateWorkspace())
{
var document1 = new TestHostDocument("var x = 1;", displayName: "Sub1", sourceCodeKind: SourceCodeKind.Script);
var project1 = new TestHostProject(workspace, document1, name: "Submission");
var document2 = new TestHostDocument("var x = 2;", displayName: "Sub2", sourceCodeKind: SourceCodeKind.Script, filePath: "a.csx");
var project2 = new TestHostProject(workspace, document2, name: "Script");
workspace.AddTestProject(project1);
workspace.AddTestProject(project2);
workspace.TryApplyChanges(workspace.CurrentSolution);
// Check that a parse tree for a submission has an empty file path.
SyntaxTree tree1 = await workspace.CurrentSolution
.GetProjectState(project1.Id)
.GetDocumentState(document1.Id)
.GetSyntaxTreeAsync(CancellationToken.None);
Assert.Equal("", tree1.FilePath);
// Check that a parse tree for a script does not have an empty file path.
SyntaxTree tree2 = await workspace.CurrentSolution
.GetProjectState(project2.Id)
.GetDocumentState(document2.Id)
.GetSyntaxTreeAsync(CancellationToken.None);
Assert.Equal("a.csx", tree2.FilePath);
}
}
private static async Task VerifyRootTypeNameAsync(TestWorkspace workspaceSnapshotBuilder, string typeName)
{
var currentSnapshot = workspaceSnapshotBuilder.CurrentSolution;
......
......@@ -140,7 +140,7 @@ public TextLoader Loader
_loader = new TestDocumentLoader(this);
}
public TestHostDocument(string text = "", string displayName = "", SourceCodeKind sourceCodeKind = SourceCodeKind.Regular, DocumentId id = null)
public TestHostDocument(string text = "", string displayName = "", SourceCodeKind sourceCodeKind = SourceCodeKind.Regular, DocumentId id = null, string filePath = null)
{
_exportProvider = TestExportProvider.ExportProviderWithCSharpAndVisualBasic;
_id = id;
......@@ -148,6 +148,7 @@ public TestHostDocument(string text = "", string displayName = "", SourceCodeKin
_name = displayName;
_sourceCodeKind = sourceCodeKind;
_loader = new TestDocumentLoader(this);
_filePath = filePath;
}
internal void SetProject(TestHostProject project)
......
......@@ -87,10 +87,17 @@ internal bool SupportsSyntaxTree
}
// This is the string used to represent the FilePath property on a SyntaxTree object.
// if the document does not yet have a file path, use the document's name instead.
// if the document does not yet have a file path, use the document's name instead in regular code
// or an empty string in script code.
private static string GetSyntaxTreeFilePath(DocumentInfo info)
{
return info.FilePath ?? info.Name;
if (info.FilePath != null)
{
return info.FilePath;
}
return info.SourceCodeKind == SourceCodeKind.Regular
? info.Name
: "";
}
private static ValueSource<TreeAndVersion> CreateLazyFullyParsedTree(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册