Skip to content

Commit

Permalink
Ignore documents from projects that do not support EnC when calculati…
Browse files Browse the repository at this point in the history
…ng active statements (#59839)
  • Loading branch information
tmat committed Mar 4, 2022
1 parent 1bc171c commit be223bb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Expand Up @@ -3322,15 +3322,30 @@ public async Task ActiveStatements_SyntaxErrorOrOutOfSyncDocument(bool isOutOfSy
}
}

[Fact]
public async Task ActiveStatements_ForeignDocument()
[Theory]
[CombinatorialData]
public async Task ActiveStatements_ForeignDocument(bool withPath, bool designTimeOnly)
{
var composition = FeaturesTestCompositions.Features.AddParts(typeof(DummyLanguageService));

using var _ = CreateWorkspace(out var solution, out var service, new[] { typeof(DummyLanguageService) });

var project = solution.AddProject("dummy_proj", "dummy_proj", DummyLanguageService.LanguageName);
var document = project.AddDocument("test", SourceText.From("dummy1"));
var project = solution.AddProject("dummy_proj", "dummy_proj", designTimeOnly ? LanguageNames.CSharp : DummyLanguageService.LanguageName);
var filePath = withPath ? Path.Combine(TempRoot.Root, "test") : null;

var documentInfo = DocumentInfo.Create(
DocumentId.CreateNewId(project.Id, "test"),
name: "test",
folders: Array.Empty<string>(),
sourceCodeKind: SourceCodeKind.Regular,
loader: TextLoader.From(TextAndVersion.Create(SourceText.From("dummy1"), VersionStamp.Create(), filePath)),
filePath: filePath,
isGenerated: false,
designTimeOnly: designTimeOnly,
documentServiceProvider: null);

var document = project.Solution.AddDocument(documentInfo).GetDocument(documentInfo.Id);

solution = document.Project.Solution;

var debuggingSession = await StartDebuggingSessionAsync(service, solution);
Expand All @@ -3350,6 +3365,12 @@ public async Task ActiveStatements_ForeignDocument()

var baseSpans = await debuggingSession.GetBaseActiveStatementSpansAsync(solution, ImmutableArray.Create(document.Id), CancellationToken.None);
Assert.Empty(baseSpans.Single());

// update solution:
solution = solution.WithDocumentText(document.Id, SourceText.From("dummy2"));

baseSpans = await debuggingSession.GetBaseActiveStatementSpansAsync(solution, ImmutableArray.Create(document.Id), CancellationToken.None);
Assert.Empty(baseSpans.Single());
}

[Fact, WorkItem(24320, "https://github.com/dotnet/roslyn/issues/24320")]
Expand Down
Expand Up @@ -621,6 +621,12 @@ public async ValueTask<ImmutableArray<ImmutableArray<ActiveStatementSpan>>> GetB
continue;
}

if (!document.Project.SupportsEditAndContinue())
{
// document is in a project that does not support EnC
continue;
}

// Multiple documents may have the same path (linked file).
// The documents represent the files that #line directives map to.
// Documents that have the same path must have different project id.
Expand All @@ -643,6 +649,7 @@ public async ValueTask<ImmutableArray<ImmutableArray<ActiveStatementSpan>>> GetB

var newProject = solution.GetRequiredProject(projectId);
var analyzer = newProject.LanguageServices.GetRequiredService<IEditAndContinueAnalyzer>();

await foreach (var documentId in EditSession.GetChangedDocumentsAsync(oldProject, newProject, cancellationToken).ConfigureAwait(false))
{
cancellationToken.ThrowIfCancellationRequested();
Expand Down

0 comments on commit be223bb

Please sign in to comment.