未验证 提交 3094a62b 编写于 作者: J Jason Malinowski 提交者: GitHub

Merge pull request #36982 from jasonmalinowski/fix-stale-filepath-bug

Fix Solution.WithDocumentFilePath not updating the file path of the tree
......@@ -401,12 +401,14 @@ public DocumentState UpdateFolders(IList<string> folders)
public DocumentState UpdateFilePath(string filePath)
{
var newAttributes = this.Attributes.With(filePath: filePath);
// TODO: it's overkill to fully reparse the tree if we had the tree already; all we have to do is update the
// file path and diagnostic options for that tree.
var newTreeSource = CreateLazyFullyParsedTree(
this.TextAndVersionSource,
this.Id.ProjectId,
GetSyntaxTreeFilePath(this.Attributes),
GetSyntaxTreeFilePath(newAttributes),
_options,
_analyzerConfigSetSource,
_languageServices,
......@@ -416,7 +418,7 @@ public DocumentState UpdateFilePath(string filePath)
_languageServices,
this.solutionServices,
this.Services,
this.Attributes.With(filePath: filePath),
newAttributes,
_options,
_analyzerConfigSetSource,
this.sourceTextOpt,
......
......@@ -19,6 +19,7 @@
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.VisualBasic;
using Microsoft.VisualStudio.Threading;
using Roslyn.Test.Utilities;
using Roslyn.Utilities;
using Xunit;
......@@ -642,6 +643,35 @@ public void TestUpdateSyntaxTreeWithAnnotations()
Assert.Equal(true, root2.HasAnnotation(annotation));
}
[Fact, Trait(Traits.Feature, Traits.Features.Workspace)]
public void TestUpdatingFilePathUpdatesSyntaxTree()
{
var projectId = ProjectId.CreateNewId();
var documentId = DocumentId.CreateNewId(projectId);
const string OldFilePath = @"Z:\OldFilePath.cs";
const string NewFilePath = @"Z:\NewFilePath.cs";
var solution = CreateSolution()
.AddProject(projectId, "goo", "goo.dll", LanguageNames.CSharp)
.AddDocument(documentId, "OldFilePath.cs", "public class Goo { }", filePath: OldFilePath);
// scope so later asserts don't accidentally use oldDocument
{
var oldDocument = solution.GetDocument(documentId);
Assert.Equal(OldFilePath, oldDocument.FilePath);
Assert.Equal(OldFilePath, oldDocument.GetSyntaxTreeAsync().Result.FilePath);
}
solution = solution.WithDocumentFilePath(documentId, NewFilePath);
{
var newDocument = solution.GetDocument(documentId);
Assert.Equal(NewFilePath, newDocument.FilePath);
Assert.Equal(NewFilePath, newDocument.GetSyntaxTreeAsync().Result.FilePath);
}
}
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/13433"), Trait(Traits.Feature, Traits.Features.Workspace)]
public void TestSyntaxRootNotKeptAlive()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册