提交 5a6090eb 编写于 作者: R Ravi Chande

Merge pull request #418 from rchande/ProjectReloadPerf

Global notification when adding/removing projects
......@@ -10,6 +10,7 @@
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.SolutionCrawler;
using Microsoft.CodeAnalysis.Text;
......@@ -1037,7 +1038,10 @@ void IVisualStudioWorkspaceHost.OnDocumentClosed(DocumentId documentId, ITextBuf
// a crash. Until this is fixed, we will leak a HierarchyEventsSink every time a
// Mercury shared document is closed.
// UnsubscribeFromSharedHierarchyEvents(documentId);
_workspace.OnDocumentClosed(documentId, loader, updateActiveContext);
using (_workspace.Services.GetService<IGlobalOperationNotificationService>().Start("Document Closed"))
{
_workspace.OnDocumentClosed(documentId, loader, updateActiveContext);
}
}
void IVisualStudioWorkspaceHost.OnDocumentOpened(DocumentId documentId, ITextBuffer textBuffer, bool currentContext)
......@@ -1143,7 +1147,10 @@ void IVisualStudioWorkspaceHost.OnMetadataReferenceRemoved(ProjectId projectId,
void IVisualStudioWorkspaceHost.OnProjectAdded(ProjectInfo projectInfo)
{
_workspace.OnProjectAdded(projectInfo);
using (_workspace.Services.GetService<IGlobalOperationNotificationService>()?.Start("Add Project"))
{
_workspace.OnProjectAdded(projectInfo);
}
}
void IVisualStudioWorkspaceHost.OnProjectReferenceAdded(ProjectId projectId, ProjectReference projectReference)
......@@ -1158,7 +1165,10 @@ void IVisualStudioWorkspaceHost.OnProjectReferenceRemoved(ProjectId projectId, P
void IVisualStudioWorkspaceHost.OnProjectRemoved(ProjectId projectId)
{
_workspace.OnProjectRemoved(projectId);
using (_workspace.Services.GetService<IGlobalOperationNotificationService>()?.Start("Remove Project"))
{
_workspace.OnProjectRemoved(projectId);
}
}
void IVisualStudioWorkspaceHost.OnSolutionAdded(SolutionInfo solutionInfo)
......
......@@ -58,7 +58,7 @@
<Compile Include="Implementation\Watson\WatsonErrorReport.cs" />
<Compile Include="Implementation\Watson\WatsonReporter.cs" />
<Compile Include="Implementation\Workspace\Esent\EsentLogger.cs" />
<Compile Include="SolutionBuildMonitor.cs" />
<Compile Include="SolutionEventMonitor.cs" />
<Compile Include="Utilities\VSCodeAnalysisColors.cs" />
<Compile Include="Implementation\WorkspaceCacheService.cs" />
</ItemGroup>
......@@ -186,7 +186,7 @@
<Reference Include="..\..\..\..\packages\System.Collections.Immutable.1.1.33-beta\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll" />
<Reference Include="Microsoft.VisualStudio.CallHierarchy.Package.Definitions.dll">
<HintPath>$(DevEnvDir)\Microsoft.VisualStudio.CallHierarchy.Package.Definitions.dll</HintPath>
</Reference>
</Reference>
<Reference Include="Microsoft.VisualStudio.TextManager.Interop.11.0, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
......@@ -719,4 +719,4 @@
<Import Project="..\..\..\..\build\VSL.Imports.Closed.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
</ImportGroup>
</Project>
</Project>
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// 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.Collections.Generic;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.VisualStudio.Shell;
namespace Microsoft.VisualStudio.LanguageServices
{
/// <summary>
/// Monitors Visual Studio's UIContext for SolutionBuilding and notifies the GlobalOperationService.
/// The intent is to suspend analysis of non-essential files for the duration of a build.
/// </summary>
internal sealed class SolutionBuildMonitor : IDisposable
internal sealed class SolutionEventMonitor : IDisposable
{
private GlobalOperationNotificationService _notificationService;
private GlobalOperationRegistration _operation;
private Dictionary<string, GlobalOperationRegistration> _operations = new Dictionary<string, GlobalOperationRegistration>();
public SolutionBuildMonitor(VisualStudioWorkspace workspace)
public SolutionEventMonitor(VisualStudioWorkspace workspace)
{
var notificationService = workspace.Services.GetService<IGlobalOperationNotificationService>() as GlobalOperationNotificationService;
if (notificationService != null)
{
_notificationService = notificationService;
KnownUIContexts.SolutionBuildingContext.UIContextChanged += SolutionBuildingContextChanged;
KnownUIContexts.SolutionOpeningContext.UIContextChanged += SolutionOpeningContextChanged;
}
}
public void Dispose()
{
if (_operation != null)
foreach (var globalOperation in _operations.Values)
{
_operation.Dispose();
_operation = null;
globalOperation.Dispose();
}
_operations.Clear();
if (_notificationService != null)
{
_notificationService = null;
KnownUIContexts.SolutionBuildingContext.UIContextChanged -= SolutionBuildingContextChanged;
KnownUIContexts.SolutionOpeningContext.UIContextChanged -= SolutionOpeningContextChanged;
}
}
private void SolutionBuildingContextChanged(object sender, UIContextChangedEventArgs e)
{
ContextChangedWorker(e, "Solution Building");
}
private void SolutionOpeningContextChanged(object sender, UIContextChangedEventArgs e)
{
ContextChangedWorker(e, "Solution Opening");
}
private void ContextChangedWorker(UIContextChangedEventArgs e, string operation)
{
if (_notificationService != null)
{
var globalOperation = _operations[operation];
if (e.Activated)
{
if (_operation != null)
if (globalOperation != null)
{
_operation.Dispose();
globalOperation.Dispose();
}
_operation = _notificationService.Start("Solution Building");
_operations[operation] = _notificationService.Start(operation);
}
else if (_operation != null)
else if (globalOperation != null)
{
_operation.Done();
_operation.Dispose();
_operation = null;
globalOperation.Done();
globalOperation.Dispose();
globalOperation = null;
}
}
}
......
......@@ -35,7 +35,7 @@ public class RoslynPackage : Package
private WorkspaceFailureOutputPane _outputPane;
private IComponentModel _componentModel;
private AnalyzerItemsTracker _analyzerTracker;
private IDisposable _solutionBuildMonitor;
private IDisposable _solutionEventMonitor;
protected override void Initialize()
{
......@@ -70,7 +70,7 @@ protected override void Initialize()
// load some services that have to be loaded in UI thread
LoadComponentsInUIContext();
_solutionBuildMonitor = new SolutionBuildMonitor(_workspace);
_solutionEventMonitor = new SolutionEventMonitor(_workspace);
}
private void InitializeColors()
......@@ -163,10 +163,10 @@ protected override void Dispose(bool disposing)
ReportSessionWideTelemetry();
if (_solutionBuildMonitor != null)
if (_solutionEventMonitor != null)
{
_solutionBuildMonitor.Dispose();
_solutionBuildMonitor = null;
_solutionEventMonitor.Dispose();
_solutionEventMonitor = null;
}
base.Dispose(disposing);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册