提交 77fc5f01 编写于 作者: H HeeJae Chang

addressing more feedbacks.

上级 8a4b29be
......@@ -31,8 +31,7 @@ internal class TodoCommentIncrementalAnalyzerProvider : IIncrementalAnalyzerProv
[ImportMany]IEnumerable<Lazy<IEventListener, EventListenerMetadata>> eventListeners)
{
_todoCommentTokens = todoCommentTokens;
_eventListenerTracker = new EventListenerTracker<ITodoListProvider>(
eventListeners.Where(l => l.Metadata.Service == WellKnownEventListeners.TodoListProvider));
_eventListenerTracker = new EventListenerTracker<ITodoListProvider>(eventListeners, WellKnownEventListeners.TodoListProvider);
}
public IIncrementalAnalyzer CreateIncrementalAnalyzer(Workspace workspace)
......
......@@ -47,8 +47,7 @@ internal partial class DiagnosticService : IDiagnosticService
_gate = new object();
_map = new Dictionary<IDiagnosticUpdateSource, Dictionary<Workspace, Dictionary<object, Data>>>();
_eventListenerTracker = new EventListenerTracker<IDiagnosticService>(
eventListeners.Where(l => l.Metadata.Service == WellKnownEventListeners.DiagnosticService));
_eventListenerTracker = new EventListenerTracker<IDiagnosticService>(eventListeners, WellKnownEventListeners.DiagnosticService);
}
public event EventHandler<DiagnosticsUpdatedArgs> DiagnosticsUpdated
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Composition;
using Microsoft.CodeAnalysis.Host;
......@@ -9,13 +8,13 @@ namespace Microsoft.CodeAnalysis.SolutionCrawler
[ExportEventListener(WellKnownEventListeners.Workspace, WorkspaceKind.Host), Shared]
internal class HostSolutionCrawlerWorkspaceEventListener : IEventListener<object>, IEventListenerStoppable
{
public void Listen(Workspace workspace, object serviceOpt)
public void StartListening(Workspace workspace, object serviceOpt)
{
var registration = workspace.Services.GetService<ISolutionCrawlerRegistrationService>();
registration.Register(workspace);
}
public void Stop(Workspace workspace)
public void StopListening(Workspace workspace)
{
// we do this so that we can stop solution crawler faster and fire some telemetry.
// this is to reduce a case where we keep going even when VS is shutting down since we don't know about that
......@@ -23,20 +22,4 @@ public void Stop(Workspace workspace)
registration.Unregister(workspace, blockingShutdown: true);
}
}
[ExportEventListener(WellKnownEventListeners.Workspace, WorkspaceKind.MiscellaneousFiles), Shared]
internal class MiscSolutionCrawlerWorkspaceEventListener : IEventListener<object>, IEventListenerStoppable
{
public void Listen(Workspace workspace, object serviceOpt)
{
// misc workspace will enable syntax errors and semantic errors for script files for
// all participating projects in the workspace
DiagnosticProvider.Enable(workspace, DiagnosticProvider.Options.Syntax | DiagnosticProvider.Options.ScriptSemantic);
}
public void Stop(Workspace workspace)
{
DiagnosticProvider.Disable(workspace);
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Composition;
using Microsoft.CodeAnalysis.Host;
namespace Microsoft.CodeAnalysis.SolutionCrawler
{
[ExportEventListener(WellKnownEventListeners.Workspace, WorkspaceKind.MiscellaneousFiles), Shared]
internal class MiscSolutionCrawlerWorkspaceEventListener : IEventListener<object>, IEventListenerStoppable
{
public void StartListening(Workspace workspace, object serviceOpt)
{
// misc workspace will enable syntax errors and semantic errors for script files for
// all participating projects in the workspace
DiagnosticProvider.Enable(workspace, DiagnosticProvider.Options.Syntax | DiagnosticProvider.Options.ScriptSemantic);
}
public void StopListening(Workspace workspace)
{
DiagnosticProvider.Disable(workspace);
}
}
}
......@@ -50,16 +50,17 @@ public void Register(Workspace workspace)
/// <summary>
/// make sure solution cralwer is registered for the given workspace.
///
/// we need this until https://github.com/dotnet/roslyn/issues/35514 is fixed.
///
/// basically, solution crawler is currently not initialized until a file is opened (package is loaded)
/// this force solution crawler to be initialized.
///
/// initializeLazily should be removed once the issue above is fixed.
/// </summary>
/// <param name="workspace"></param>
internal void EnsureRegistration(Workspace workspace, bool initializeLazily)
/// <param name="workspace"><see cref="Workspace"/> this solution crawler runs for</param>
/// <param name="initializeLazily">
/// when true, solution crawler will be initialized when there is the first workspace event fired.
/// otherwise, it will be initialized when workspace is registered right away.
/// something like "Build" will use initializeLazily:false to make sure diagnostic analyzer engine (incremental analyzer)
/// is initialized. otherwise, if build is called before workspace is fully populated, we will think some errors from build
/// doesn't belong to us since diagnostic analyzer engine is not there yet and
/// let project system to take care of these unknown errors.
/// </param>
public void EnsureRegistration(Workspace workspace, bool initializeLazily)
{
var correlationId = LogAggregator.GetNextId();
......
......@@ -13,7 +13,7 @@ internal partial class RemoteHostClientServiceFactory : IWorkspaceServiceFactory
[ExportEventListener(WellKnownEventListeners.Workspace, WorkspaceKind.Host), Shared]
private sealed class RemoteHostWorkspaceEventListener : IEventListener<object>
{
public void Listen(Workspace workspace, object serviceOpt)
public void StartListening(Workspace workspace, object serviceOpt)
{
var service = (RemoteHostClientService)workspace.Services.GetService<IRemoteHostClientService>();
service.Enable();
......
......@@ -22,7 +22,7 @@ public MiscellaneousDiagnosticListTableWorkspaceEventListener(ITableManagerProvi
_tableManagerProvider = tableManagerProvider;
}
public void Listen(Workspace workspace, IDiagnosticService diagnosticService)
public void StartListening(Workspace workspace, IDiagnosticService diagnosticService)
{
new MiscellaneousDiagnosticListTable(workspace, diagnosticService, _tableManagerProvider);
}
......
......@@ -21,7 +21,7 @@ public MiscellaneousTodoListTableWorkspaceEventListener(ITableManagerProvider ta
_tableManagerProvider = tableManagerProvider;
}
public void Listen(Workspace workspace, ITodoListProvider service)
public void StartListening(Workspace workspace, ITodoListProvider service)
{
new MiscellaneousTodoListTable(workspace, service, _tableManagerProvider);
}
......
......@@ -38,7 +38,7 @@ internal partial class VisualStudioDiagnosticListTableWorkspaceEventListener : I
_tableManagerProvider = tableManagerProvider;
}
public void Listen(Workspace workspace, IDiagnosticService diagnosticService)
public void StartListening(Workspace workspace, IDiagnosticService diagnosticService)
{
var errorList = _threadingContext.JoinableTaskFactory.Run(async () =>
{
......
......@@ -21,7 +21,7 @@ public VisualStudioTodoListTableWorkspaceEventListener(ITableManagerProvider tab
_tableManagerProvider = tableManagerProvider;
}
public void Listen(Workspace workspace, ITodoListProvider service)
public void StartListening(Workspace workspace, ITodoListProvider service)
{
new VisualStudioTodoListTable(workspace, service, _tableManagerProvider);
}
......
......@@ -28,7 +28,7 @@ internal class EventListenerMetadata : WorkspaceKindMetadata
throw new ArgumentException(nameof(workspaceKinds));
}
this.Service = service ?? throw new ArgumentException("service");
this.Service = service ?? throw new ArgumentException(nameof(service));
}
}
}
......@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
namespace Microsoft.CodeAnalysis.Host
......@@ -18,12 +19,18 @@ internal class EventListenerTracker<TService>
/// Workspace kind this event listener is initialized for
/// </summary>
private readonly HashSet<string> _eventListenerInitialized;
private readonly IEnumerable<Lazy<IEventListener, EventListenerMetadata>> _eventListeners;
private readonly ImmutableArray<Lazy<IEventListener, EventListenerMetadata>> _eventListeners;
public EventListenerTracker(
IEnumerable<Lazy<IEventListener, EventListenerMetadata>> eventListeners, string kind) :
this(eventListeners.Where(el => el.Metadata.Service == kind))
{
}
public EventListenerTracker(IEnumerable<Lazy<IEventListener, EventListenerMetadata>> eventListeners)
{
_eventListenerInitialized = new HashSet<string>();
_eventListeners = eventListeners;
_eventListeners = eventListeners.ToImmutableArray();
}
public void EnsureEventListener(Workspace workspace, TService serviceOpt)
......@@ -38,7 +45,7 @@ public void EnsureEventListener(Workspace workspace, TService serviceOpt)
foreach (var listener in GetListeners(workspace, _eventListeners))
{
listener.Listen(workspace, serviceOpt);
listener.StartListening(workspace, serviceOpt);
}
}
}
......
......@@ -28,7 +28,7 @@ public ExportEventListenerAttribute(string service, params string[] workspaceKin
throw new ArgumentException(nameof(workspaceKinds));
}
this.Service = service ?? throw new ArgumentException("service");
this.Service = service ?? throw new ArgumentException(nameof(service));
this.WorkspaceKinds = workspaceKinds;
}
}
......
......@@ -19,6 +19,6 @@ internal interface IEventListener
/// </summary>
internal interface IEventListenerStoppable
{
void Stop(Workspace workspace);
void StopListening(Workspace workspace);
}
}
......@@ -9,6 +9,6 @@ namespace Microsoft.CodeAnalysis.Host
/// </summary>
internal interface IEventListener<TService> : IEventListener
{
void Listen(Workspace workspace, TService serviceOpt);
void StartListening(Workspace workspace, TService serviceOpt);
}
}
......@@ -9,7 +9,7 @@
namespace Microsoft.CodeAnalysis.Host
{
/// <summary>
/// Ensure <see cref="IEventListener{TService}.Listen(Workspace, TService)"/> is called for the workspace
/// Ensure <see cref="IEventListener{TService}.StartListening(Workspace, TService)"/> is called for the workspace
/// </summary>
internal interface IWorkspaceEventListenerService : IWorkspaceService
{
......@@ -68,7 +68,7 @@ public void EnsureListeners()
foreach (var listener in _eventListeners)
{
listener.Listen(_workspace, serviceOpt: null);
listener.StartListening(_workspace, serviceOpt: null);
}
}
}
......@@ -85,7 +85,7 @@ public void Stop()
foreach (var listener in _eventListeners.OfType<IEventListenerStoppable>())
{
listener.Stop(_workspace);
listener.StopListening(_workspace);
}
}
}
......
......@@ -14,7 +14,7 @@ internal class WorkspaceKindMetadata
public WorkspaceKindMetadata(IDictionary<string, object> data)
{
this.WorkspaceKinds = (string[])data.GetValueOrDefault("WorkspaceKinds");
this.WorkspaceKinds = (string[])data.GetValueOrDefault(nameof(WorkspaceKinds));
}
public WorkspaceKindMetadata(params string[] workspaceKinds)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册