Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Dependencies/PooledObjects/ArrayBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public void Sort()
_builder.Sort();
}

public void Sort(IComparer<T> comparer)
public void Sort(IComparer<T>? comparer)
{
_builder.Sort(comparer);
}
Expand Down Expand Up @@ -684,13 +684,15 @@ public void RemoveDuplicates()
set.Free();
}

public void SortAndRemoveDuplicates(IComparer<T> comparer)
public void SortAndRemoveDuplicates(IComparer<T>? comparer = null)
{
if (Count <= 1)
{
return;
}

comparer ??= Comparer<T>.Default;

Sort(comparer);

int j = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Diagnostics;
Expand Down Expand Up @@ -375,8 +376,12 @@ public async ValueTask<ManagedHotReloadUpdates> GetUpdatesAsync(ImmutableArray<s
using var _ = PooledHashSet<string>.GetInstance(out var runningProjectPaths);
runningProjectPaths.AddAll(runningProjects);

var runningProjectIds = solution.Projects.Where(p => p.FilePath != null && runningProjectPaths.Contains(p.FilePath)).Select(static p => p.Id).ToImmutableHashSet();
var result = await GetDebuggingSession().EmitSolutionUpdateAsync(solution, runningProjectIds, activeStatementSpanProvider, cancellationToken).ConfigureAwait(false);
// TODO: Update once implemented: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2449700
var runningProjectInfos = solution.Projects.Where(p => p.FilePath != null && runningProjectPaths.Contains(p.FilePath)).ToImmutableDictionary(
keySelector: static p => p.Id,
elementSelector: static p => new RunningProjectInfo { RestartWhenChangesHaveNoEffect = false, AllowPartialUpdate = false });

var result = await GetDebuggingSession().EmitSolutionUpdateAsync(solution, runningProjectInfos, activeStatementSpanProvider, cancellationToken).ConfigureAwait(false);

switch (result.ModuleUpdates.Status)
{
Expand All @@ -399,9 +404,9 @@ public async ValueTask<ManagedHotReloadUpdates> GetUpdatesAsync(ImmutableArray<s
result.ModuleUpdates.Updates.FromContract(),
result.GetAllDiagnostics().FromContract(),
GetProjectPaths(result.ProjectsToRebuild),
GetProjectPaths(result.ProjectsToRestart));
GetProjectPaths(result.ProjectsToRestart.Keys));

ImmutableArray<string> GetProjectPaths(ImmutableArray<ProjectId> ids)
=> ids.SelectAsArray(static (id, solution) => solution.GetRequiredProject(id).FilePath!, solution);
ImmutableArray<string> GetProjectPaths(IEnumerable<ProjectId> ids)
=> ids.SelectAsArray(id => solution.GetRequiredProject(id).FilePath!);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void EndDebuggingSession()

public async ValueTask<ManagedHotReloadUpdates> GetUpdatesAsync(Solution solution, CancellationToken cancellationToken)
{
var results = (await _encService.EmitSolutionUpdateAsync(GetSessionId(), solution, runningProjects: [], s_noActiveStatementSpanProvider, cancellationToken).ConfigureAwait(false)).Dehydrate();
var results = (await _encService.EmitSolutionUpdateAsync(GetSessionId(), solution, runningProjects: ImmutableDictionary<ProjectId, RunningProjectInfo>.Empty, s_noActiveStatementSpanProvider, cancellationToken).ConfigureAwait(false)).Dehydrate();
return new ManagedHotReloadUpdates(results.ModuleUpdates.Updates.FromContract(), results.GetAllDiagnostics().FromContract(), [], []);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#nullable disable

using System;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -115,11 +116,9 @@ public async Task Test(bool commitChanges)

var localService = localWorkspace.GetService<EditAndContinueLanguageService>();

DocumentId documentId;
await localWorkspace.ChangeSolutionAsync(localWorkspace.CurrentSolution
.AddTestProject("proj", out var projectId).Solution
.AddMetadataReferences(projectId, TargetFrameworkUtil.GetReferences(TargetFramework.Mscorlib40))
.AddDocument(documentId = DocumentId.CreateNewId(projectId), "test.cs", SourceText.From("class C { }", Encoding.UTF8), filePath: "test.cs"));
.AddTestProject("proj", out var projectId)
.AddTestDocument("test.cs", "class C { }", out var documentId).Project.Solution);

var solution = localWorkspace.CurrentSolution;
var project = solution.GetRequiredProject(projectId);
Expand Down Expand Up @@ -159,7 +158,7 @@ await localWorkspace.ChangeSolutionAsync(localWorkspace.CurrentSolution

var diagnosticDescriptor1 = EditAndContinueDiagnosticDescriptors.GetDescriptor(EditAndContinueErrorCode.ErrorReadingFile);

mockEncService.EmitSolutionUpdateImpl = (solution, runningProjects, _) =>
mockEncService.EmitSolutionUpdateImpl = (solution, _, _) =>
{
var syntaxTree = solution.GetRequiredDocument(documentId).GetSyntaxTreeSynchronously(CancellationToken.None)!;

Expand All @@ -176,7 +175,7 @@ await localWorkspace.ChangeSolutionAsync(localWorkspace.CurrentSolution
RudeEdits = [new ProjectDiagnostics(project.Id, [rudeEditDiagnostic])],
SyntaxError = syntaxError,
ProjectsToRebuild = [project.Id],
ProjectsToRestart = [project.Id]
ProjectsToRestart = ImmutableDictionary<ProjectId, ImmutableArray<ProjectId>>.Empty.Add(project.Id, [])
};
};

Expand All @@ -186,16 +185,16 @@ await localWorkspace.ChangeSolutionAsync(localWorkspace.CurrentSolution

AssertEx.Equal(
[
$"Error ENC1001: test.cs(0, 1, 0, 2): {string.Format(FeaturesResources.ErrorReadingFile, "doc", "error 1")}",
$"Error ENC1001: proj.csproj(0, 0, 0, 0): {string.Format(FeaturesResources.ErrorReadingFile, "proj", "error 2")}"
$"Error ENC1001: {document.FilePath}(0, 1, 0, 2): {string.Format(FeaturesResources.ErrorReadingFile, "doc", "error 1")}",
$"Error ENC1001: {project.FilePath}(0, 0, 0, 0): {string.Format(FeaturesResources.ErrorReadingFile, "proj", "error 2")}"
], sessionState.ApplyChangesDiagnostics.Select(Inspect));

AssertEx.Equal(
[
$"Error ENC1001: test.cs(0, 1, 0, 2): {string.Format(FeaturesResources.ErrorReadingFile, "doc", "error 1")}",
$"Error ENC1001: proj.csproj(0, 0, 0, 0): {string.Format(FeaturesResources.ErrorReadingFile, "proj", "error 2")}",
$"Error ENC1001: test.cs(0, 1, 0, 2): {string.Format(FeaturesResources.ErrorReadingFile, "doc", "syntax error 3")}",
$"RestartRequired ENC0033: test.cs(0, 2, 0, 3): {string.Format(FeaturesResources.Deleting_0_requires_restarting_the_application, "x")}"
$"Error ENC1001: {document.FilePath}(0, 1, 0, 2): {string.Format(FeaturesResources.ErrorReadingFile, "doc", "error 1")}",
$"Error ENC1001: {project.FilePath}(0, 0, 0, 0): {string.Format(FeaturesResources.ErrorReadingFile, "proj", "error 2")}",
$"Error ENC1001: {document.FilePath}(0, 1, 0, 2): {string.Format(FeaturesResources.ErrorReadingFile, "doc", "syntax error 3")}",
$"RestartRequired ENC0033: {document.FilePath}(0, 2, 0, 3): {string.Format(FeaturesResources.Deleting_0_requires_restarting_the_application, "x")}"
], updates.Diagnostics.Select(Inspect));

Assert.True(sessionState.IsSessionActive);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ CommittedSolution.DocumentState.Indeterminate or

public async ValueTask<EmitSolutionUpdateResults> EmitSolutionUpdateAsync(
Solution solution,
IImmutableSet<ProjectId> runningProjects,
ImmutableDictionary<ProjectId, RunningProjectInfo> runningProjects,
ActiveStatementSpanProvider activeStatementSpanProvider,
CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -553,7 +553,7 @@ public async ValueTask<EmitSolutionUpdateResults> EmitSolutionUpdateAsync(
}

using var _ = ArrayBuilder<ProjectDiagnostics>.GetInstance(out var rudeEditDiagnostics);
foreach (var (projectId, projectRudeEdits) in solutionUpdate.DocumentsWithRudeEdits.GroupBy(static e => e.DocumentId.ProjectId))
foreach (var (projectId, projectRudeEdits) in solutionUpdate.DocumentsWithRudeEdits.GroupBy(static e => e.DocumentId.ProjectId).OrderBy(static id => id))
{
foreach (var (documentId, rudeEdits) in projectRudeEdits)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

#nullable disable

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Contracts.EditAndContinue;
using Microsoft.CodeAnalysis.Diagnostics;

namespace Microsoft.CodeAnalysis.EditAndContinue;

Expand Down Expand Up @@ -45,7 +46,7 @@ void add(int index, int id, string resourceName, LocalizableResourceString title
}

builder[index] = new DiagnosticDescriptor(
$"ENC{id:D4}",
GetDiagnosticId(id),
title,
messageFormat: new LocalizableResourceString(resourceName, FeaturesResources.ResourceManager, typeof(FeaturesResources)),
DiagnosticCategory.EditAndContinue,
Expand Down Expand Up @@ -210,4 +211,10 @@ private static int GetDescriptorIndex(RudeEditKind kind)

private static int GetDescriptorIndex(EditAndContinueErrorCode errorCode)
=> s_diagnosticBaseIndex + (int)errorCode;

private static string GetDiagnosticId(int id)
=> $"ENC{id:D4}";

public static RudeEditKind GetRudeEditKind(string diagnosticId)
=> diagnosticId.StartsWith("ENC", StringComparison.Ordinal) && int.TryParse(diagnosticId[3..], out var id) ? (RudeEditKind)id : RudeEditKind.None;
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public ValueTask<ImmutableArray<Diagnostic>> GetDocumentDiagnosticsAsync(Documen
public ValueTask<EmitSolutionUpdateResults> EmitSolutionUpdateAsync(
DebuggingSessionId sessionId,
Solution solution,
IImmutableSet<ProjectId> runningProjects,
ImmutableDictionary<ProjectId, RunningProjectInfo> runningProjects,
ActiveStatementSpanProvider activeStatementSpanProvider,
CancellationToken cancellationToken)
{
Expand Down
Loading
Loading