提交 5bca3990 编写于 作者: J Jason Malinowski

Move code out of VisualStudioWorkspaceImpl only used for error reporting

This didn't need anything other than the service provider, so
we can easily decouple that.
上级 468d844e
......@@ -718,28 +718,6 @@ public override void CloseAdditionalDocument(DocumentId documentId)
CloseDocumentCore(documentId);
}
public bool TryGetInfoBarData(out IVsWindowFrame frame, out IVsInfoBarUIFactory factory)
{
frame = null;
factory = null;
var monitorSelectionService = ServiceProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;
object value = null;
// We want to get whichever window is currently in focus (including toolbars) as we could have had an exception thrown from the error list or interactive window
if (monitorSelectionService != null &&
ErrorHandler.Succeeded(monitorSelectionService.GetCurrentElementValue((uint)VSConstants.VSSELELEMID.SEID_WindowFrame, out value)))
{
frame = value as IVsWindowFrame;
}
else
{
return false;
}
factory = ServiceProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory;
return frame != null && factory != null;
}
public void OpenDocumentCore(DocumentId documentId, bool activate = true)
{
if (documentId == null)
......
......@@ -19,14 +19,14 @@ internal partial class VisualStudioErrorReportingService : IErrorReportingServic
private readonly static InfoBarButton s_enableItem = new InfoBarButton(ServicesVSResources.Enable);
private readonly static InfoBarButton s_enableAndIgnoreItem = new InfoBarButton(ServicesVSResources.Enable_and_ignore_future_errors);
private readonly VisualStudioWorkspaceImpl _workspace;
private readonly IServiceProvider _serviceProvider;
private readonly IForegroundNotificationService _foregroundNotificationService;
private readonly IAsynchronousOperationListener _listener;
public VisualStudioErrorReportingService(
VisualStudioWorkspaceImpl workspace, IForegroundNotificationService foregroundNotificationService, IAsynchronousOperationListener listener)
SVsServiceProvider serviceProvider, IForegroundNotificationService foregroundNotificationService, IAsynchronousOperationListener listener)
{
_workspace = workspace;
_serviceProvider = serviceProvider;
_foregroundNotificationService = foregroundNotificationService;
_listener = listener;
}
......@@ -38,13 +38,35 @@ public void ShowErrorInfo(string message, params ErrorReportingUI[] items)
{
IVsWindowFrame frame;
IVsInfoBarUIFactory factory;
if (_workspace.TryGetInfoBarData(out frame, out factory))
if (TryGetInfoBarData(out frame, out factory))
{
CreateInfoBar(factory, frame, message, items);
}
}, _listener.BeginAsyncOperation("Show InfoBar"));
}
private bool TryGetInfoBarData(out IVsWindowFrame frame, out IVsInfoBarUIFactory factory)
{
frame = null;
factory = null;
var monitorSelectionService = _serviceProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;
object value = null;
// We want to get whichever window is currently in focus (including toolbars) as we could have had an exception thrown from the error list or interactive window
if (monitorSelectionService != null &&
ErrorHandler.Succeeded(monitorSelectionService.GetCurrentElementValue((uint)VSConstants.VSSELELEMID.SEID_WindowFrame, out value)))
{
frame = value as IVsWindowFrame;
}
else
{
return false;
}
factory = _serviceProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory;
return frame != null && factory != null;
}
private void CreateInfoBar(IVsInfoBarUIFactory factory, IVsWindowFrame frame, string message, ErrorReportingUI[] items)
{
object unknown;
......
......@@ -9,6 +9,7 @@
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;
using Microsoft.VisualStudio.Shell;
namespace Microsoft.VisualStudio.LanguageServices.Implementation
{
......@@ -19,11 +20,11 @@ internal sealed class VisualStudioErrorReportingServiceFactory : IWorkspaceServi
[ImportingConstructor]
public VisualStudioErrorReportingServiceFactory(
VisualStudioWorkspaceImpl workspace,
SVsServiceProvider serviceProvider,
IForegroundNotificationService foregroundNotificationService,
[ImportMany] IEnumerable<Lazy<IAsynchronousOperationListener, FeatureMetadata>> asyncListeners)
{
_singleton = new VisualStudioErrorReportingService(workspace, foregroundNotificationService, new AggregateAsynchronousOperationListener(asyncListeners, FeatureAttribute.InfoBar));
_singleton = new VisualStudioErrorReportingService(serviceProvider, foregroundNotificationService, new AggregateAsynchronousOperationListener(asyncListeners, FeatureAttribute.InfoBar));
}
public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册