提交 c5ac4849 编写于 作者: T Tomas Matousek

Do not report EnC diagnostics when EnC is disabled

上级 b8a5611e
......@@ -98,7 +98,7 @@
<MicrosoftVisualStudioComponentModelHostVersion>16.0.198-g52de9c2988</MicrosoftVisualStudioComponentModelHostVersion>
<MicrosoftVisualStudioCompositionVersion>15.5.23</MicrosoftVisualStudioCompositionVersion>
<MicrosoftVisualStudioCoreUtilityVersion>$(VisualStudioEditorPackagesVersion)</MicrosoftVisualStudioCoreUtilityVersion>
<MicrosoftVisualStudioDebuggerUIInterfacesVersion>16.0.29213.96</MicrosoftVisualStudioDebuggerUIInterfacesVersion>
<MicrosoftVisualStudioDebuggerUIInterfacesVersion>16.0.29431.108</MicrosoftVisualStudioDebuggerUIInterfacesVersion>
<MicrosoftVisualStudioDebuggerEngineimplementationVersion>16.4.1091102-preview</MicrosoftVisualStudioDebuggerEngineimplementationVersion>
<MicrosoftVisualStudioDebuggerMetadataimplementationVersion>16.4.1091102-preview</MicrosoftVisualStudioDebuggerMetadataimplementationVersion>
<MicrosoftVisualStudioDesignerInterfacesVersion>1.1.4322</MicrosoftVisualStudioDesignerInterfacesVersion>
......
......@@ -79,16 +79,13 @@ private string GetErrorTypeFromDiagnostic(DiagnosticData diagnostic)
private string GetErrorTypeFromDiagnosticTags(DiagnosticData diagnostic)
{
if (diagnostic.CustomTags.Count <= 1)
if (diagnostic.Severity == DiagnosticSeverity.Error &&
diagnostic.CustomTags.Contains(WellKnownDiagnosticTags.EditAndContinue))
{
return null;
return EditAndContinueErrorTypeDefinition.Name;
}
return diagnostic.CustomTags[0] switch
{
WellKnownDiagnosticTags.EditAndContinue => EditAndContinueErrorTypeDefinition.Name,
_ => null,
};
return null;
}
private static string GetErrorTypeFromDiagnosticSeverity(DiagnosticData diagnostic)
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Debugging;
using Microsoft.CodeAnalysis.EditAndContinue;
using Microsoft.VisualStudio.Debugger;
using Microsoft.VisualStudio.Debugger.Clr;
using Microsoft.VisualStudio.Debugger.ComponentInterfaces;
using Microsoft.VisualStudio.Debugger.UI.Interfaces;
using Roslyn.Utilities;
namespace Microsoft.VisualStudio.LanguageServices.EditAndContinue
{
[Export(typeof(IDebugStateChangeListener))]
internal sealed class VisualStudioDebugStateChangeListener : IDebugStateChangeListener
{
private readonly Workspace _workspace;
private readonly IDebuggingWorkspaceService _debuggingService;
private readonly IEditAndContinueWorkspaceService _encService;
private readonly VisualStudioDebuggeeModuleMetadataProvider _moduleMetadataProvider;
// EnC service or null if EnC is disabled for the debug session.
private IEditAndContinueWorkspaceService? _encService;
/// <summary>
/// Concord component. Singleton created on demand during debugging session and discarded as soon as the session ends.
/// </summary>
private sealed class DebuggerService : IDkmCustomMessageForwardReceiver, IDkmModuleInstanceLoadNotification, IDkmModuleInstanceUnloadNotification
{
private VisualStudioDebugStateChangeListener _listener;
private IEditAndContinueWorkspaceService? _encService;
/// <summary>
/// Message source id as specified in ManagedEditAndContinueService.vsdconfigxml.
/// </summary>
public static readonly Guid MessageSourceId = new Guid("730432E7-1B68-4B3A-BD6A-BD4C13E0566B");
DkmCustomMessage IDkmCustomMessageForwardReceiver.SendLower(DkmCustomMessage customMessage)
DkmCustomMessage? IDkmCustomMessageForwardReceiver.SendLower(DkmCustomMessage customMessage)
{
_listener = (VisualStudioDebugStateChangeListener)customMessage.Parameter1;
_encService = (IEditAndContinueWorkspaceService)customMessage.Parameter1;
return null;
}
......@@ -48,7 +54,8 @@ void IDkmModuleInstanceLoadNotification.OnModuleInstanceLoad(DkmModuleInstance m
{
if (moduleInstance is DkmClrModuleInstance clrModuleInstance)
{
_listener.OnManagedModuleInstanceLoaded(clrModuleInstance);
Contract.ThrowIfNull(_encService);
_encService.OnManagedModuleInstanceLoaded(clrModuleInstance.Mvid);
}
}
......@@ -58,67 +65,70 @@ void IDkmModuleInstanceLoadNotification.OnModuleInstanceLoad(DkmModuleInstance m
/// will be suspended and can be examined. ModuleInstanceUnload is sent when the monitor
/// detects that a module has unloaded from within the target process.
/// </summary>
public void OnModuleInstanceUnload(DkmModuleInstance moduleInstance, DkmWorkList workList, DkmEventDescriptor eventDescriptor)
void IDkmModuleInstanceUnloadNotification.OnModuleInstanceUnload(DkmModuleInstance moduleInstance, DkmWorkList workList, DkmEventDescriptor eventDescriptor)
{
if (moduleInstance is DkmClrModuleInstance clrModuleInstance)
{
_listener.OnManagedModuleInstanceUnloaded(clrModuleInstance);
Contract.ThrowIfNull(_encService);
_encService.OnManagedModuleInstanceUnloaded(clrModuleInstance.Mvid);
}
}
}
[ImportingConstructor]
public VisualStudioDebugStateChangeListener(VisualStudioWorkspace workspace, VisualStudioDebuggeeModuleMetadataProvider moduleMetadataProvider)
public VisualStudioDebugStateChangeListener(VisualStudioWorkspace workspace)
{
_moduleMetadataProvider = moduleMetadataProvider;
_workspace = workspace;
_debuggingService = workspace.Services.GetRequiredService<IDebuggingWorkspaceService>();
_encService = workspace.Services.GetRequiredService<IEditAndContinueWorkspaceService>();
}
public void StartDebugging()
/// <summary>
/// Called by the debugger when a debugging session starts and managed debugging is being used.
/// </summary>
public void StartDebugging(DebugSessionOptions options)
{
// hook up a callbacks (the call blocks until the message is processed):
using (DebuggerComponent.ManagedEditAndContinueService())
_debuggingService.OnBeforeDebuggingStateChanged(DebuggingState.Design, DebuggingState.Run);
if ((options & DebugSessionOptions.EditAndContinueDisabled) == 0)
{
DkmCustomMessage.Create(
Connection: null,
Process: null,
SourceId: DebuggerService.MessageSourceId,
MessageCode: 0,
Parameter1: this,
Parameter2: null).SendLower();
}
_encService = _workspace.Services.GetRequiredService<IEditAndContinueWorkspaceService>();
_debuggingService.OnBeforeDebuggingStateChanged(DebuggingState.Design, DebuggingState.Run);
// hook up a callbacks (the call blocks until the message is processed):
using (DebuggerComponent.ManagedEditAndContinueService())
{
DkmCustomMessage.Create(
Connection: null,
Process: null,
SourceId: DebuggerService.MessageSourceId,
MessageCode: 0,
Parameter1: _encService,
Parameter2: null).SendLower();
}
_encService.StartDebuggingSession();
_encService.StartDebuggingSession();
}
else
{
_encService = null;
}
}
public void EnterBreakState(BreakStateKind kind)
public void EnterBreakState()
{
// When stopped at exception - start an edit session as usual and report a rude edit for all changes we see.
bool stoppedAtException = kind == BreakStateKind.StoppedAtException;
_debuggingService.OnBeforeDebuggingStateChanged(DebuggingState.Run, DebuggingState.Break);
_encService.StartEditSession();
_encService?.StartEditSession();
}
public void ExitBreakState()
{
_debuggingService.OnBeforeDebuggingStateChanged(DebuggingState.Break, DebuggingState.Run);
_encService.EndEditSession();
_encService?.EndEditSession();
}
public void StopDebugging()
{
_debuggingService.OnBeforeDebuggingStateChanged(DebuggingState.Run, DebuggingState.Design);
_encService.EndDebuggingSession();
_encService?.EndDebuggingSession();
}
internal void OnManagedModuleInstanceLoaded(DkmClrModuleInstance moduleInstance)
=> _encService.OnManagedModuleInstanceLoaded(moduleInstance.Mvid);
internal void OnManagedModuleInstanceUnloaded(DkmClrModuleInstance moduleInstance)
=> _encService.OnManagedModuleInstanceUnloaded(moduleInstance.Mvid);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册