private static ImmutableArray <CodeAction> CreateNestedActions( IPackageInstallerService installerService, string source, string packageName, bool includePrerelease, Document document) { // Determine what versions of this package are already installed in some project // in this solution. We'll offer to add those specific versions to this project, // followed by an option to "Find and install latest version." var installedVersions = installerService.GetInstalledVersions(packageName); var codeActions = ArrayBuilder <CodeAction> .GetInstance(); // First add the actions to install a specific version. codeActions.AddRange(installedVersions.Select(v => CreateCodeAction( installerService, source, packageName, document, versionOpt: v, includePrerelease: includePrerelease, isLocal: true))); // Now add the action to install the specific version. codeActions.Add(CreateCodeAction( installerService, source, packageName, document, versionOpt: null, includePrerelease: includePrerelease, isLocal: false)); // And finally the action to show the package manager dialog. codeActions.Add(new InstallWithPackageManagerCodeAction(installerService, packageName)); return(codeActions.ToImmutableAndFree()); }
public InstallWithPackageManagerCodeActionOperation( IPackageInstallerService installerService, string packageName) { _installerService = installerService; _packageName = packageName; }
/// <summary> /// Values for these parameters can be provided (during testing) for mocking purposes. /// </summary> protected AbstractAddPackageCodeFixProvider( IPackageInstallerService packageInstallerService, ISymbolSearchService symbolSearchService) { _packageInstallerService = packageInstallerService; _symbolSearchService = symbolSearchService; }
/// <summary> /// For testing purposes only. /// </summary> internal SymbolSearchService( Workspace workspace, IPackageInstallerService installerService, IRemoteControlService remoteControlService, ILogService logService, IDelayService delayService, IIOService ioService, IPatchService patchService, IDatabaseFactoryService databaseFactoryService, string localSettingsDirectory, Func<Exception, bool> reportAndSwallowException, CancellationTokenSource cancellationTokenSource) { if (remoteControlService == null) { // If we can't access the file update service, then there's nothing we can do. return; } _workspace = workspace; _installerService = installerService; _delayService = delayService; _ioService = ioService; _logService = logService; _remoteControlService = remoteControlService; _patchService = patchService; _databaseFactoryService = databaseFactoryService; _localSettingsDirectory = localSettingsDirectory; _reportAndSwallowException = reportAndSwallowException; _cancellationTokenSource = cancellationTokenSource; _cancellationToken = _cancellationTokenSource.Token; }
/// <summary> /// For testing purposes only. /// </summary> internal PackageSearchService( IPackageInstallerService installerService, IPackageSearchRemoteControlService remoteControlService, IPackageSearchLogService logService, IPackageSearchDelayService delayService, IPackageSearchIOService ioService, IPackageSearchPatchService patchService, IPackageSearchDatabaseFactoryService databaseFactoryService, string localSettingsDirectory, Func<Exception, bool> reportAndSwallowException, CancellationTokenSource cancellationTokenSource) { if (remoteControlService == null) { // If we can't access the file update service, then there's nothing we can do. return; } _installerService = installerService; _delayService = delayService; _ioService = ioService; _logService = logService; _remoteControlService = remoteControlService; _patchService = patchService; _databaseFactoryService = databaseFactoryService; _reportAndSwallowException = reportAndSwallowException; _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; }
public InstallPackageDirectlyCodeActionOperation( IPackageInstallerService installerService, Document document, string source, string packageName, string versionOpt, bool isLocal) { _installerService = installerService; _document = document; _source = source; _packageName = packageName; _versionOpt = versionOpt; _isLocal = isLocal; if (versionOpt != null) { const int projectsToShow = 5; var otherProjects = installerService.GetProjectsWithInstalledPackage( _document.Project.Solution, packageName, versionOpt).ToList(); _projectsWithMatchingVersion = otherProjects.Take(projectsToShow).Select(p => p.Name).ToList(); if (otherProjects.Count > projectsToShow) { _projectsWithMatchingVersion.Add("..."); } } }
private async Task FindNugetTypeReferencesAsync( PackageSource source, ISymbolSearchService searchService, IPackageInstallerService installerService, List <Reference> allReferences, TSimpleNameSyntax nameNode, string name, int arity, bool isAttributeSearch, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var results = await searchService.FindPackagesWithTypeAsync( source.Name, name, arity, cancellationToken).ConfigureAwait(false); if (results.IsDefault) { return; } var project = _document.Project; var projectId = project.Id; var workspace = project.Solution.Workspace; foreach (var result in results) { cancellationToken.ThrowIfCancellationRequested(); await HandleNugetReferenceAsync( source.Source, installerService, allReferences, nameNode, project, isAttributeSearch, result, weight : allReferences.Count).ConfigureAwait(false); } }
private static ImmutableArray<CodeAction> CreateNestedActions( IPackageInstallerService installerService, string source, string packageName, bool includePrerelease, Document document) { // Determine what versions of this package are already installed in some project // in this solution. We'll offer to add those specific versions to this project, // followed by an option to "Find and install latest version." var installedVersions = installerService.GetInstalledVersions(packageName); var codeActions = ArrayBuilder<CodeAction>.GetInstance(); // First add the actions to install a specific version. codeActions.AddRange(installedVersions.Select(v => CreateCodeAction( installerService, source, packageName, document, versionOpt: v, includePrerelease: includePrerelease, isLocal: true))); // Now add the action to install the specific version. codeActions.Add(CreateCodeAction( installerService, source, packageName, document, versionOpt: null, includePrerelease: includePrerelease, isLocal: false)); // And finally the action to show the package manager dialog. codeActions.Add(new InstallWithPackageManagerCodeAction(installerService, packageName)); return codeActions.ToImmutableAndFree(); }
protected AbstractAddImportCodeFixProvider( IPackageInstallerService packageInstallerService = null, ISymbolSearchService symbolSearchService = null) { _packageInstallerService = packageInstallerService; _symbolSearchService = symbolSearchService; }
public InstallNugetPackageOperation( IPackageInstallerService installerService, Document document, string source, string packageName, string versionOpt, bool isLocal) { _installerService = installerService; _document = document; _source = source; _packageName = packageName; _versionOpt = versionOpt; _isLocal = isLocal; if (versionOpt != null) { const int projectsToShow = 5; var otherProjects = installerService.GetProjectsWithInstalledPackage( _document.Project.Solution, packageName, versionOpt).ToList(); _projectsWithMatchingVersion = otherProjects.Take(projectsToShow).Select(p => p.Name).ToList(); if (otherProjects.Count > projectsToShow) { _projectsWithMatchingVersion.Add("..."); } } }
private static ImmutableArray <CodeAction> CreateNestedActions( Document document, AddImportFixData fixData, IPackageInstallerService installerService) { // Determine what versions of this package are already installed in some project // in this solution. We'll offer to add those specific versions to this project, // followed by an option to "Find and install latest version." var installedVersions = installerService.GetInstalledVersions(fixData.PackageName).NullToEmpty(); using var _ = ArrayBuilder <CodeAction> .GetInstance(out var codeActions); // First add the actions to install a specific version. codeActions.AddRange(installedVersions.Select( v => CreateCodeAction( document, fixData, installerService, versionOpt: v, isLocal: true))); // Now add the action to install the specific version. var preferredVersion = fixData.PackageVersionOpt; if (preferredVersion == null || !installedVersions.Contains(preferredVersion)) { codeActions.Add(CreateCodeAction( document, fixData, installerService, preferredVersion, isLocal: false)); } // And finally the action to show the package manager dialog. codeActions.Add(new InstallWithPackageManagerCodeAction(installerService, fixData.PackageName)); return(codeActions.ToImmutable()); }
public AssemblyReference( AbstractAddImportCodeFixProvider <TSimpleNameSyntax> provider, IPackageInstallerService installerService, SearchResult searchResult, PackageWithTypeResult packageWithType) : base(provider, searchResult) { _packageWithType = packageWithType; }
/// <summary> /// Even though we have child actions, we mark ourselves as explicitly non-inlinable. /// We want to the experience of having the top level item the user has to see and /// navigate through, and we don't want our child items confusingly being added to the /// top level light-bulb where it's not clear what effect they would have if invoked. /// </summary> public ParentInstallPackageCodeAction( Document document, AddImportFixData fixData, IPackageInstallerService installerService) : base(string.Format(FeaturesResources.Install_package_0, fixData.PackageName), CreateNestedActions(document, fixData, installerService), isInlinable: false) { Contract.ThrowIfFalse(fixData.Kind == AddImportFixKind.PackageSymbol); }
private static CodeAction CreateCodeAction( IPackageInstallerService installerService, string source, string packageName, Document document, string versionOpt, bool isLocal) { return new InstallPackageDirectlyCodeAction( installerService, document, source, packageName, versionOpt, isLocal); }
public ParentInstallPackageCodeAction( Document document, AddImportFixData fixData, IPackageInstallerService installerService) : base(string.Format(FeaturesResources.Install_package_0, fixData.PackageName), CreateNestedActions(document, fixData, installerService), isInlinable: false, priority: CodeActionPriority.Low) // Adding a nuget reference is lower priority than other fixes.. { Contract.ThrowIfFalse(fixData.Kind == AddImportFixKind.PackageSymbol); }
public InstallPackageParentCodeAction( IPackageInstallerService installerService, string source, string packageName, bool includePrerelease, Document document) : base(string.Format(FeaturesResources.Install_package_0, packageName), CreateNestedActions(installerService, source, packageName, includePrerelease, document), isInlinable: false) { }
private static CodeAction CreateCodeAction( IPackageInstallerService installerService, string source, string packageName, Document document, string versionOpt, bool isLocal) { return(new InstallPackageDirectlyCodeAction( installerService, document, source, packageName, versionOpt, isLocal)); }
/// <summary> /// Even though we have child actions, we mark ourselves as explicitly non-inlinable. /// We want to the experience of having the top level item the user has to see and /// navigate through, and we don't want our child items confusingly being added to the /// top level light-bulb where it's not clear what effect they would have if invoked. /// </summary> public InstallPackageParentCodeAction( IPackageInstallerService installerService, string source, string packageName, Document document) : base(string.Format(FeaturesResources.Install_package_0, packageName), CreateNestedActions(installerService, source, packageName, document), isInlinable: false) { _installerService = installerService; _source = source; _packageName = packageName; }
public FxCopAnalyzersSuggestedActionCallback( IThreadingContext threadingContext, VisualStudioWorkspace workspace, SVsServiceProvider serviceProvider) : base(threadingContext) { _workspace = workspace; _serviceProvider = serviceProvider; _documentTrackingService = workspace.Services.GetService <IDocumentTrackingService>(); _packageInstallerService = workspace.Services.GetService <IPackageInstallerService>(); _workspace.WorkspaceChanged += OnWorkspaceChanged; }
public VisualStudioSymbolSearchService( VisualStudioWorkspaceImpl workspace, VSShell.SVsServiceProvider serviceProvider) : base(workspace, SymbolSearchOptions.Enabled, SymbolSearchOptions.SuggestForTypesInReferenceAssemblies, SymbolSearchOptions.SuggestForTypesInNuGetPackages) { _workspace = workspace; _installerService = workspace.Services.GetService<IPackageInstallerService>(); _localSettingsDirectory = new ShellSettingsManager(serviceProvider).GetApplicationDataFolder(ApplicationDataFolder.LocalSettings); _logService = new LogService((IVsActivityLog)serviceProvider.GetService(typeof(SVsActivityLog))); }
public VisualStudioSymbolSearchService( VisualStudioWorkspaceImpl workspace, VSShell.SVsServiceProvider serviceProvider) : base(workspace, SymbolSearchOptions.Enabled, SymbolSearchOptions.SuggestForTypesInReferenceAssemblies, SymbolSearchOptions.SuggestForTypesInNuGetPackages) { _workspace = workspace; _installerService = workspace.Services.GetService <IPackageInstallerService>(); _localSettingsDirectory = new ShellSettingsManager(serviceProvider).GetApplicationDataFolder(ApplicationDataFolder.LocalSettings); _logService = new LogService((IVsActivityLog)serviceProvider.GetService(typeof(SVsActivityLog))); }
public PackageReference( AbstractAddImportCodeFixProvider <TSimpleNameSyntax> provider, IPackageInstallerService installerService, SearchResult searchResult, string source, string packageName, string versionOpt) : base(provider, searchResult) { _installerService = installerService; _source = source; _packageName = packageName; _versionOpt = versionOpt; }
public PackageSearchService(VSShell.SVsServiceProvider serviceProvider, IPackageInstallerService installerService) : this(installerService, CreateRemoteControlService(serviceProvider), new LogService((IVsActivityLog)serviceProvider.GetService(typeof(SVsActivityLog))), new DelayService(), new IOService(), new PatchService(), new DatabaseFactoryService(), new ShellSettingsManager(serviceProvider).GetApplicationDataFolder(ApplicationDataFolder.LocalSettings), // Report all exceptions we encounter, but don't crash on them. FatalError.ReportWithoutCrash, new CancellationTokenSource()) { installerService.PackageSourcesChanged += OnPackageSourcesChanged; OnPackageSourcesChanged(this, EventArgs.Empty); }
public InstallPackageDirectlyCodeAction( IPackageInstallerService installerService, Document document, string source, string packageName, string versionOpt, bool isLocal) { Title = versionOpt == null ? FeaturesResources.Find_and_install_latest_version : isLocal ? string.Format(FeaturesResources.Use_local_version_0, versionOpt) : string.Format(FeaturesResources.Install_version_0, versionOpt); _installPackageOperation = new InstallPackageDirectlyCodeActionOperation( installerService, document, source, packageName, versionOpt, isLocal); }
public ImmutableArray <CodeAction> GetCodeActionsForFixes( Document document, ImmutableArray <AddImportFixData> fixes, IPackageInstallerService installerService, int maxResults) { var codeActionsBuilder = ArrayBuilder <CodeAction> .GetInstance(); foreach (var fix in fixes) { var codeAction = TryCreateCodeAction(document, fix, installerService); codeActionsBuilder.AddIfNotNull(codeAction); if (codeActionsBuilder.Count >= maxResults) { break; } } return(codeActionsBuilder.ToImmutableAndFree()); }
private Task HandleNugetReferenceAsync( string source, IPackageInstallerService installerService, List <Reference> allReferences, TSimpleNameSyntax nameNode, Project project, bool isAttributeSearch, PackageWithTypeResult result, int weight) { if (!installerService.IsInstalled(project.Solution.Workspace, project.Id, result.PackageName)) { var desiredName = GetDesiredName(isAttributeSearch, result.TypeName); allReferences.Add(new PackageReference(_owner, installerService, new SearchResult(desiredName, nameNode, result.ContainingNamespaceNames, weight), source, result.PackageName, result.Version)); } return(SpecializedTasks.EmptyTask); }
private static CodeAction CreateCodeAction( Document document, AddImportFixData fixData, IPackageInstallerService installerService, string versionOpt, bool isLocal) { var title = versionOpt == null ? FeaturesResources.Find_and_install_latest_version : isLocal ? string.Format(FeaturesResources.Use_local_version_0, versionOpt) : string.Format(FeaturesResources.Install_version_0, versionOpt); var installOperation = new InstallPackageDirectlyCodeActionOperation( installerService, document, fixData.PackageSource, fixData.PackageName, versionOpt, includePrerelease: false, isLocal: isLocal); // Nuget hits should always come after other results. return(new InstallPackageAndAddImportCodeAction( document, fixData, title, installOperation)); }
private async Task FindNugetOrReferenceAssemblyTypeReferencesAsync( PackageSource source, IPackageSearchService searchService, IPackageInstallerService installerService, List <Reference> allReferences, TSimpleNameSyntax nameNode, string name, int arity, bool isAttributeSearch, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var results = searchService.FindPackagesWithType(source.Name, name, arity, cancellationToken); var project = _document.Project; var projectId = project.Id; var workspace = project.Solution.Workspace; int weight = 0; foreach (var result in results) { cancellationToken.ThrowIfCancellationRequested(); if (result.IsDesktopFramework) { await HandleReferenceAssemblyReferenceAsync( installerService, allReferences, nameNode, project, isAttributeSearch, result, weight, cancellationToken).ConfigureAwait(false); } else { await HandleNugetReferenceAsync( source.Source, installerService, allReferences, nameNode, project, isAttributeSearch, result, weight).ConfigureAwait(false); } weight++; } }
private async Task <ImmutableArray <PackageWithAssemblyResult> > FindMatchingPackagesAsync( PackageSource source, ISymbolSearchService searchService, IPackageInstallerService installerService, ISet <string> assemblyNames, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var result = new HashSet <PackageWithAssemblyResult>(); foreach (var assemblyName in assemblyNames) { var packagesWithAssembly = await searchService.FindPackagesWithAssemblyAsync( source.Name, assemblyName, cancellationToken).ConfigureAwait(false); result.AddRange(packagesWithAssembly); } // Ensure the packages are sorted by rank. var sortedPackages = result.ToImmutableArray().Sort(); return(sortedPackages); }
private async Task<ImmutableArray<PackageWithAssemblyResult>> FindMatchingPackagesAsync( PackageSource source, ISymbolSearchService searchService, IPackageInstallerService installerService, ISet<string> assemblyNames, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var result = new HashSet<PackageWithAssemblyResult>(); foreach (var assemblyName in assemblyNames) { var packagesWithAssembly = await searchService.FindPackagesWithAssemblyAsync( source.Name, assemblyName, cancellationToken).ConfigureAwait(false); result.AddRange(packagesWithAssembly); } // Ensure the packages are sorted by rank. var sortedPackages = result.ToImmutableArray().Sort(); return sortedPackages; }
/// <summary> /// For testing purposes only. /// </summary> internal SymbolSearchService( Workspace workspace, IPackageInstallerService installerService, IRemoteControlService remoteControlService, ILogService logService, IDelayService delayService, IIOService ioService, IPatchService patchService, IDatabaseFactoryService databaseFactoryService, string localSettingsDirectory, Func <Exception, bool> reportAndSwallowException, CancellationTokenSource cancellationTokenSource) : base(workspace, ServiceComponentOnOffOptions.SymbolSearch, AddImportOptions.SuggestForTypesInReferenceAssemblies, AddImportOptions.SuggestForTypesInNuGetPackages) { if (remoteControlService == null) { // If we can't access the file update service, then there's nothing we can do. return; } _workspace = workspace; _installerService = installerService; _delayService = delayService; _ioService = ioService; _logService = logService; _remoteControlService = remoteControlService; _patchService = patchService; _databaseFactoryService = databaseFactoryService; _localSettingsDirectory = localSettingsDirectory; _reportAndSwallowException = reportAndSwallowException; _cancellationTokenSource = cancellationTokenSource; _cancellationToken = _cancellationTokenSource.Token; }
/// <summary> /// For testing purposes only. /// </summary> internal SymbolSearchService( Workspace workspace, IPackageInstallerService installerService, IRemoteControlService remoteControlService, ILogService logService, IDelayService delayService, IIOService ioService, IPatchService patchService, IDatabaseFactoryService databaseFactoryService, string localSettingsDirectory, Func <Exception, bool> reportAndSwallowException, CancellationTokenSource cancellationTokenSource) { if (remoteControlService == null) { // If we can't access the file update service, then there's nothing we can do. return; } _workspace = workspace; _installerService = installerService; _delayService = delayService; _ioService = ioService; _logService = logService; _remoteControlService = remoteControlService; _patchService = patchService; _databaseFactoryService = databaseFactoryService; _reportAndSwallowException = reportAndSwallowException; _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; }
/// <summary> /// Values for these parameters can be provided (during testing) for mocking purposes. /// </summary> protected AbstractAddSpecificPackageCodeFixProvider( IPackageInstallerService packageInstallerService = null, ISymbolSearchService symbolSearchService = null) : base(packageInstallerService, symbolSearchService) { }
/// <summary> /// Values for these parameters can be provided (during testing) for mocking purposes. /// </summary> protected AbstractAddMissingReferenceCodeFixProvider( IPackageInstallerService packageInstallerService = null, ISymbolSearchService symbolSearchService = null) : base(packageInstallerService, symbolSearchService) { }
/// <summary>For testing purposes only (so that tests can pass in mock values)</summary> internal CSharpAddMissingReferenceCodeFixProvider( IPackageInstallerService installerService, ISymbolSearchService symbolSearchService) : base(installerService, symbolSearchService) { }
/// <summary>For testing purposes only (so that tests can pass in mock values)</summary> internal CSharpAddImportCodeFixProvider( IPackageInstallerService installerService, IPackageSearchService packageSearchService) : base(installerService, packageSearchService) { }
private CodeAction TryCreateCodeAction(Document document, AddImportFixData fixData, IPackageInstallerService installerService) { switch (fixData.Kind) { case AddImportFixKind.ProjectSymbol: return(new ProjectSymbolReferenceCodeAction(document, fixData)); case AddImportFixKind.MetadataSymbol: return(new MetadataSymbolReferenceCodeAction(document, fixData)); case AddImportFixKind.ReferenceAssemblySymbol: return(new AssemblyReferenceCodeAction(document, fixData)); case AddImportFixKind.PackageSymbol: return(!installerService.IsInstalled(document.Project.Solution.Workspace, document.Project.Id, fixData.PackageName) ? new ParentInstallPackageCodeAction(document, fixData, installerService) : null); } throw ExceptionUtilities.Unreachable; }
internal CSharpAddImportCodeFixProvider( IPackageInstallerService installerService, ISymbolSearchService symbolSearchService) : base(installerService, symbolSearchService) { }
public InstallWithPackageManagerCodeAction( IPackageInstallerService installerService, string packageName) { _installerService = installerService; _packageName = packageName; }