Skip to content

Commit

Permalink
Enc logging (#76042)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat authored Jan 23, 2025
1 parent 9739676 commit d5cf1ea
Show file tree
Hide file tree
Showing 32 changed files with 338 additions and 375 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.BrokeredServices;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Debugger.Contracts.HotReload;
using Roslyn.Utilities;

Expand All @@ -31,13 +29,12 @@ namespace Microsoft.CodeAnalysis.EditAndContinue;
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal sealed class EditAndContinueLanguageService(
IServiceBrokerProvider serviceBrokerProvider,
EditAndContinueSessionState sessionState,
Lazy<IHostWorkspaceProvider> workspaceProvider,
Lazy<IManagedHotReloadService> debuggerService,
PdbMatchingSourceTextProvider sourceTextProvider,
IDiagnosticsRefresher diagnosticRefresher,
IAsynchronousOperationListenerProvider listenerProvider) : IManagedHotReloadLanguageService2, IEditAndContinueSolutionProvider
IEditAndContinueLogReporter logReporter,
IDiagnosticsRefresher diagnosticRefresher) : IManagedHotReloadLanguageService2, IEditAndContinueSolutionProvider
{
private sealed class NoSessionException : InvalidOperationException
{
Expand All @@ -49,9 +46,6 @@ public NoSessionException()
}
}

private readonly IAsynchronousOperationListener _asyncListener = listenerProvider.GetListener(FeatureAttribute.EditAndContinue);
private readonly HotReloadLoggerProxy _logger = new(serviceBrokerProvider.ServiceBroker);

private bool _disabled;
private RemoteDebuggingSessionProxy? _debuggingSession;

Expand Down Expand Up @@ -94,11 +88,7 @@ private IActiveStatementTrackingService GetActiveStatementTrackingService()
internal void Disable(Exception e)
{
_disabled = true;

var token = _asyncListener.BeginAsyncOperation(nameof(EditAndContinueLanguageService) + ".LogToOutput");

_ = _logger.LogAsync(new HotReloadLogMessage(HotReloadVerbosity.Diagnostic, e.ToString(), errorLevel: HotReloadDiagnosticErrorLevel.Error), CancellationToken.None).AsTask()
.ReportNonFatalErrorAsync().CompletesAsyncOperation(token);
logReporter.Report(e.ToString(), LogMessageSeverity.Error);
}

private void UpdateApplyChangesDiagnostics(ImmutableArray<DiagnosticData> diagnostics)
Expand Down Expand Up @@ -265,7 +255,7 @@ public async ValueTask UpdateBaselinesAsync(ImmutableArray<string> projectPaths,
}

_committedDesignTimeSolution = currentDesignTimeSolution;
var projectIds = await GetProjectIdsAsync(projectPaths, currentCompileTimeSolution, cancellationToken).ConfigureAwait(false);
var projectIds = GetProjectIds(projectPaths, currentCompileTimeSolution);

try
{
Expand All @@ -281,7 +271,7 @@ public async ValueTask UpdateBaselinesAsync(ImmutableArray<string> projectPaths,
}
}

private async ValueTask<ImmutableArray<ProjectId>> GetProjectIdsAsync(ImmutableArray<string> projectPaths, Solution solution, CancellationToken cancellationToken)
private ImmutableArray<ProjectId> GetProjectIds(ImmutableArray<string> projectPaths, Solution solution)
{
using var _ = ArrayBuilder<ProjectId>.GetInstance(out var projectIds);
foreach (var path in projectPaths)
Expand All @@ -293,11 +283,7 @@ private async ValueTask<ImmutableArray<ProjectId>> GetProjectIdsAsync(ImmutableA
}
else
{
await _logger.LogAsync(new HotReloadLogMessage(
HotReloadVerbosity.Diagnostic,
$"Project with path '{path}' not found in the current solution.",
errorLevel: HotReloadDiagnosticErrorLevel.Warning),
cancellationToken).ConfigureAwait(false);
logReporter.Report($"Project with path '{path}' not found in the current solution.", LogMessageSeverity.Info);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
<ItemGroup>
<Compile Include="..\..\Compilers\Core\Portable\InternalUtilities\IsExternalInit.cs" Link="Utilities\IsExternalInit.cs" />
<Compile Include="..\..\LanguageServer\Microsoft.CodeAnalysis.LanguageServer\BrokeredServices\ServiceBrokerProvider.cs" Link="BrokeredServices\ServiceBrokerProvider.cs" />
<Compile Include="..\..\Workspaces\Remote\ServiceHub\Services\EditAndContinue\EditAndContinueLogReporter.cs" Link="EditAndContinue\EditAndContinueLogReporter.cs" />
<Compile Include="..\..\Workspaces\Remote\ServiceHub\Services\EditAndContinue\HotReloadLoggerProxy.cs" Link="EditAndContinue\HotReloadLoggerProxy.cs" />
</ItemGroup>
<ItemGroup>
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" Key="$(MoqPublicKey)" LoadsWithinVisualStudio="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Differencing;
using Microsoft.CodeAnalysis.EditAndContinue;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Collections;
Expand All @@ -26,17 +24,11 @@

namespace Microsoft.CodeAnalysis.CSharp.EditAndContinue;

internal sealed class CSharpEditAndContinueAnalyzer(Action<SyntaxNode>? testFaultInjector = null) : AbstractEditAndContinueAnalyzer(testFaultInjector)
[ExportLanguageService(typeof(IEditAndContinueAnalyzer), LanguageNames.CSharp), Shared]
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal sealed class CSharpEditAndContinueAnalyzer() : AbstractEditAndContinueAnalyzer
{
[ExportLanguageServiceFactory(typeof(IEditAndContinueAnalyzer), LanguageNames.CSharp), Shared]
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal sealed class Factory() : ILanguageServiceFactory
{
public ILanguageService CreateLanguageService(HostLanguageServices languageServices)
=> new CSharpEditAndContinueAnalyzer(testFaultInjector: null);
}

#region Syntax Analysis

private enum BlockPart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ private static async Task<DocumentAnalysisResults> AnalyzeDocumentAsync(
EditAndContinueCapabilities capabilities = EditAndContinueTestVerifier.Net5RuntimeCapabilities,
ImmutableArray<ActiveStatementLineSpan> newActiveStatementSpans = default)
{
var analyzer = new CSharpEditAndContinueAnalyzer();
var analyzer = oldProject.Services.GetRequiredService<IEditAndContinueAnalyzer>();
var baseActiveStatements = AsyncLazy.Create(activeStatementMap ?? ActiveStatementsMap.Empty);
var lazyCapabilities = AsyncLazy.Create(capabilities);
return await analyzer.AnalyzeDocumentAsync(oldProject, baseActiveStatements, newDocument, newActiveStatementSpans.NullToEmpty(), lazyCapabilities, CancellationToken.None);
var log = new TraceLog("Test");
return await analyzer.AnalyzeDocumentAsync(oldProject, baseActiveStatements, newDocument, newActiveStatementSpans.NullToEmpty(), lazyCapabilities, log, CancellationToken.None);
}

#endregion
Expand Down Expand Up @@ -749,15 +750,17 @@ public async Task AnalyzeDocumentAsync_InternalError(bool outOfMemory)
var baseActiveStatements = AsyncLazy.Create(ActiveStatementsMap.Empty);
var capabilities = AsyncLazy.Create(EditAndContinueTestVerifier.Net5RuntimeCapabilities);

var analyzer = new CSharpEditAndContinueAnalyzer(node =>
var analyzer = Assert.IsType<CSharpEditAndContinueAnalyzer>(oldProject.Services.GetRequiredService<IEditAndContinueAnalyzer>());
analyzer.GetTestAccessor().FaultInjector = node =>
{
if (node is CompilationUnitSyntax)
{
throw outOfMemory ? new OutOfMemoryException() : new NullReferenceException("NullRef!");
}
});
};

var result = await analyzer.AnalyzeDocumentAsync(oldProject, baseActiveStatements, newDocument, [], capabilities, CancellationToken.None);
var log = new TraceLog("Test");
var result = await analyzer.AnalyzeDocumentAsync(oldProject, baseActiveStatements, newDocument, [], capabilities, log, CancellationToken.None);

var expectedDiagnostic = outOfMemory
? $"ENC0089: {string.Format(FeaturesResources.Modifying_source_file_0_requires_restarting_the_application_because_the_file_is_too_big, filePath)}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.Differencing;
using Microsoft.CodeAnalysis.EditAndContinue;
using Microsoft.CodeAnalysis.EditAndContinue.UnitTests;
using Xunit;

namespace Microsoft.CodeAnalysis.CSharp.EditAndContinue.UnitTests;

internal sealed class CSharpEditAndContinueTestVerifier(Action<SyntaxNode>? faultInjector = null) : EditAndContinueTestVerifier
internal sealed class CSharpEditAndContinueTestVerifier(Action<SyntaxNode>? faultInjector = null) : EditAndContinueTestVerifier(faultInjector)
{
private readonly CSharpEditAndContinueAnalyzer _analyzer = new(faultInjector);

public override AbstractEditAndContinueAnalyzer Analyzer => _analyzer;
public override string LanguageName => LanguageNames.CSharp;
public override string ProjectFileExtension => ".csproj";
public override TreeComparer<SyntaxNode> TopSyntaxComparer => SyntaxComparer.TopLevel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.CodeAnalysis.Differencing;
using Microsoft.CodeAnalysis.EditAndContinue;
using Microsoft.CodeAnalysis.Contracts.EditAndContinue;
using Microsoft.CodeAnalysis.EditAndContinue;
using Microsoft.CodeAnalysis.EditAndContinue.UnitTests;
using Roslyn.Test.Utilities;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.CodeAnalysis.Contracts.EditAndContinue;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.CSharp.UnitTests;
using Microsoft.CodeAnalysis.Differencing;
using Microsoft.CodeAnalysis.EditAndContinue;
using Microsoft.CodeAnalysis.Contracts.EditAndContinue;
using Microsoft.CodeAnalysis.EditAndContinue.UnitTests;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
Expand All @@ -27,11 +29,6 @@ public abstract class EditingTestBase : CSharpTestBase
namespace System.Runtime.CompilerServices { class CreateNewOnMetadataUpdateAttribute : Attribute {} }
";

internal static CSharpEditAndContinueAnalyzer CreateAnalyzer()
{
return new CSharpEditAndContinueAnalyzer(testFaultInjector: null);
}

internal enum MethodKind
{
Regular,
Expand Down Expand Up @@ -184,7 +181,8 @@ internal static Match<SyntaxNode> GetMethodMatch(string src1, string src2, Metho
internal static IEnumerable<KeyValuePair<SyntaxNode, SyntaxNode>> GetMethodMatches(string src1, string src2, MethodKind kind = MethodKind.Regular)
{
var methodMatch = GetMethodMatch(src1, src2, kind);
return EditAndContinueTestVerifier.GetMethodMatches(CreateAnalyzer(), methodMatch);
var analyzer = EditAndContinueTestVerifier.CreateAnalyzer(faultInjector: null, LanguageNames.CSharp);
return EditAndContinueTestVerifier.GetMethodMatches(analyzer, methodMatch);
}

public static MatchingPairs ToMatchingPairs(Match<SyntaxNode> match)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
using System.Collections.Generic;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.EditAndContinue.UnitTests;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.CSharp.EditAndContinue.UnitTests;

[UseExportProvider]
public class StatementMatchingTests : EditingTestBase
{
#region Known Matches
Expand Down
Loading

0 comments on commit d5cf1ea

Please sign in to comment.