-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wait until solution load before we kick off all our nuget work. #9663
Changes from 2 commits
fb6d55b
24a0874
8b2b4d6
b9b9aa4
8f3ffeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,17 +3,20 @@ | |
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Composition; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.Editor.Shared.Utilities; | ||
using Microsoft.CodeAnalysis.Elfie.Model; | ||
using Microsoft.CodeAnalysis.Elfie.Model.Structures; | ||
using Microsoft.CodeAnalysis.Elfie.Model.Tree; | ||
using Microsoft.CodeAnalysis.ErrorReporting; | ||
using Microsoft.CodeAnalysis.Host.Mef; | ||
using Microsoft.CodeAnalysis.Packaging; | ||
using Microsoft.CodeAnalysis.Shared.Options; | ||
using Microsoft.Internal.VisualStudio.Shell.Interop; | ||
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem; | ||
using Microsoft.VisualStudio.Settings; | ||
using Microsoft.VisualStudio.Shell.Interop; | ||
using Microsoft.VisualStudio.Shell.Settings; | ||
|
@@ -29,12 +32,19 @@ namespace Microsoft.VisualStudio.LanguageServices.Packaging | |
/// This implementation also spawns a task which will attempt to keep that database up to | ||
/// date by downloading patches on a daily basis. | ||
/// </summary> | ||
internal partial class PackageSearchService : ForegroundThreadAffinitizedObject, IPackageSearchService, IDisposable | ||
[ExportWorkspaceService(typeof(IPackageSearchService)), Shared] | ||
internal partial class PackageSearchService : ForegroundThreadAffinitizedObject, IPackageSearchService | ||
{ | ||
private ConcurrentDictionary<string, AddReferenceDatabase> _sourceToDatabase = new ConcurrentDictionary<string, AddReferenceDatabase>(); | ||
private readonly VisualStudioWorkspaceImpl _workspace; | ||
private readonly ConcurrentDictionary<string, AddReferenceDatabase> _sourceToDatabase = new ConcurrentDictionary<string, AddReferenceDatabase>(); | ||
|
||
public PackageSearchService(VSShell.SVsServiceProvider serviceProvider, IPackageInstallerService installerService) | ||
: this(installerService, | ||
private bool _started; | ||
|
||
[ImportingConstructor] | ||
public PackageSearchService( | ||
VisualStudioWorkspaceImpl workspace, | ||
VSShell.SVsServiceProvider serviceProvider) | ||
: this(workspace.Services.GetService<IPackageInstallerService>(), | ||
CreateRemoteControlService(serviceProvider), | ||
new LogService((IVsActivityLog)serviceProvider.GetService(typeof(SVsActivityLog))), | ||
new DelayService(), | ||
|
@@ -46,20 +56,7 @@ public PackageSearchService(VSShell.SVsServiceProvider serviceProvider, IPackage | |
FatalError.ReportWithoutCrash, | ||
new CancellationTokenSource()) | ||
{ | ||
installerService.PackageSourcesChanged += OnPackageSourcesChanged; | ||
OnPackageSourcesChanged(this, EventArgs.Empty); | ||
} | ||
|
||
private static IPackageSearchRemoteControlService CreateRemoteControlService(VSShell.SVsServiceProvider serviceProvider) | ||
{ | ||
var vsService = serviceProvider.GetService(typeof(SVsRemoteControlService)); | ||
if (vsService == null) | ||
{ | ||
// If we can't access the file update service, then there's nothing we can do. | ||
return null; | ||
} | ||
|
||
return new RemoteControlService(vsService); | ||
_workspace = workspace; | ||
} | ||
|
||
/// <summary> | ||
|
@@ -94,12 +91,49 @@ internal PackageSearchService( | |
|
||
_cacheDirectoryInfo = new DirectoryInfo(Path.Combine( | ||
localSettingsDirectory, "PackageCache", string.Format(Invariant($"Format{_dataFormatVersion}")))); | ||
// _databaseFileInfo = new FileInfo(Path.Combine(_cacheDirectoryInfo.FullName, "NuGetCache.txt")); | ||
|
||
_cancellationTokenSource = cancellationTokenSource; | ||
_cancellationToken = _cancellationTokenSource.Token; | ||
} | ||
|
||
internal void Start() | ||
{ | ||
var options = _workspace.Options; | ||
if (!options.GetOption(ServiceComponentOnOffOptions.PackageSearch)) | ||
{ | ||
return; | ||
} | ||
|
||
// Start the whole process once we're connected | ||
_installerService.PackageSourcesChanged += OnPackageSourcesChanged; | ||
OnPackageSourcesChanged(this, EventArgs.Empty); | ||
_started = true; | ||
} | ||
|
||
internal void Stop() | ||
{ | ||
if (!_started) | ||
{ | ||
return; | ||
} | ||
|
||
_installerService.PackageSourcesChanged -= OnPackageSourcesChanged; | ||
// Cancel any existing work. | ||
_cancellationTokenSource.Cancel(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should _started be reset to false? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. This type is a single "start -> stop" type. It's not restartable. _started coudl be renamed to "hasStartBeenCalled" to better convey that it's just to let us know if we're stopping after the initial start was called. |
||
} | ||
|
||
private static IPackageSearchRemoteControlService CreateRemoteControlService(VSShell.SVsServiceProvider serviceProvider) | ||
{ | ||
var vsService = serviceProvider.GetService(typeof(SVsRemoteControlService)); | ||
if (vsService == null) | ||
{ | ||
// If we can't access the file update service, then there's nothing we can do. | ||
return null; | ||
} | ||
|
||
return new RemoteControlService(vsService); | ||
} | ||
|
||
public IEnumerable<PackageWithTypeResult> FindPackagesWithType( | ||
string source, string name, int arity, CancellationToken cancellationToken) | ||
{ | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ | |
using Task = System.Threading.Tasks.Task; | ||
using Microsoft.VisualStudio.LanguageServices.Implementation.Interactive; | ||
using static Microsoft.CodeAnalysis.Utilities.ForegroundThreadDataKind; | ||
using Microsoft.CodeAnalysis.Packaging; | ||
using Microsoft.VisualStudio.LanguageServices.Packaging; | ||
|
||
namespace Microsoft.VisualStudio.LanguageServices.Setup | ||
{ | ||
|
@@ -40,6 +42,9 @@ internal class RoslynPackage : Package | |
private RuleSetEventHandler _ruleSetEventHandler; | ||
private IDisposable _solutionEventMonitor; | ||
|
||
private PackageInstallerService _packageInstallerService; | ||
private PackageSearchService _packageSearchService; | ||
|
||
protected override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
@@ -161,6 +166,14 @@ private void LoadComponents() | |
|
||
LoadAnalyzerNodeComponents(); | ||
|
||
// Ensure the nuget package services are initialized after we've loaded | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new MEF import will be also perf impacting thing for solution open. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, sorry, git collapsed region and it looked like code belong to initialize. if possible, importing and running from background thread will be even better. |
||
// the solution. | ||
_packageInstallerService = _workspace.Services.GetService<IPackageInstallerService>() as PackageInstallerService; | ||
_packageSearchService = _workspace.Services.GetService<IPackageSearchService>() as PackageSearchService; | ||
|
||
_packageInstallerService?.Start(); | ||
_packageSearchService?.Start(); | ||
|
||
Task.Run(() => LoadComponentsBackground()); | ||
} | ||
|
||
|
@@ -202,6 +215,9 @@ internal IComponentModel ComponentModel | |
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
_packageInstallerService?.Stop(); | ||
_packageSearchService?.Stop(); | ||
|
||
UnregisterFindResultsLibraryManager(); | ||
|
||
DisposeVisualStudioDocumentTrackingService(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this happen before the call to
OnPackageSourcesChanged
in case anything in that method looks at it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, i just realized this isn't even necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. Scratch that. Still necessary.
This boolean is just so we know if we've actually done the event hookup. That way we know if we should disconnect on 'Stop' down below. Where it comes here shouldn't really matter.