-
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
Add options to enable/disable nuget search. #11023
Changes from 22 commits
8d5c08d
a7a631f
f39fd52
fd19f45
5de5408
968a975
f14aa61
6f66b48
9993a3d
87d43bd
1132292
41a326f
70429d6
f58bc96
2d4291f
c10a2d7
0ce9b17
19e6663
3607ad9
b8c6ae3
d03df21
f99d4e3
0b8fe75
110bc76
2f00943
c5de602
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
using Microsoft.CodeAnalysis.CodeActions; | ||
using Microsoft.CodeAnalysis.Host; | ||
using Microsoft.CodeAnalysis.Packaging; | ||
using Microsoft.CodeAnalysis.SymbolSearch; | ||
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. Why is this needed here? 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. Types moved out of the packaging namespace into this new namespace. |
||
using Roslyn.Utilities; | ||
|
||
namespace Microsoft.CodeAnalysis.CodeFixes.AddImport | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
// 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.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
@@ -10,6 +9,8 @@ | |
using Microsoft.CodeAnalysis.Packaging; | ||
using Microsoft.CodeAnalysis.Shared.Extensions; | ||
using Roslyn.Utilities; | ||
using Microsoft.CodeAnalysis.Shared.Options; | ||
using Microsoft.CodeAnalysis.SymbolSearch; | ||
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. Sort usings 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. Fixed. |
||
|
||
namespace Microsoft.CodeAnalysis.CodeFixes.AddImport | ||
{ | ||
|
@@ -232,32 +233,41 @@ private async Task<IList<SymbolReference>> GetMatchingTypesAsync(SearchScope sea | |
{ | ||
var workspaceServices = _document.Project.Solution.Workspace.Services; | ||
|
||
var packageSearchService = _owner._packageSearchService ?? workspaceServices.GetService<IPackageSearchService>(); | ||
var referenceAssemblySearchService = _owner._referenceAssemblySearchService ?? workspaceServices.GetService<IReferenceAssemblySearchService>(); | ||
var symbolSearchService = _owner._symbolSearchService ?? workspaceServices.GetService<ISymbolSearchService>(); | ||
var installerService = _owner._packageInstallerService ?? workspaceServices.GetService<IPackageInstallerService>(); | ||
|
||
if (referenceAssemblySearchService != null) | ||
var language = _document.Project.Language; | ||
|
||
var options = workspaceServices.Workspace.Options; | ||
var searchReferenceAssemblies = options.GetOption( | ||
AddImportOptions.SuggestForTypesInReferenceAssemblies, language); | ||
var searchNugetPackages = options.GetOption( | ||
AddImportOptions.SuggestForTypesInNuGetPackages, language); | ||
|
||
if (symbolSearchService != null && | ||
searchReferenceAssemblies) | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
await FindReferenceAssemblyTypeReferencesAsync( | ||
referenceAssemblySearchService, allReferences, nameNode, name, arity, isAttributeSearch, cancellationToken).ConfigureAwait(false); | ||
symbolSearchService, allReferences, nameNode, name, arity, isAttributeSearch, cancellationToken).ConfigureAwait(false); | ||
} | ||
|
||
if (packageSearchService != null && | ||
if (symbolSearchService != null && | ||
searchNugetPackages && | ||
installerService.IsEnabled) | ||
{ | ||
foreach (var packageSource in installerService.PackageSources) | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
await FindNugetTypeReferencesAsync( | ||
packageSource, packageSearchService, installerService, allReferences, | ||
packageSource, symbolSearchService, installerService, allReferences, | ||
nameNode, name, arity, isAttributeSearch, cancellationToken).ConfigureAwait(false); | ||
} | ||
} | ||
} | ||
|
||
private async Task FindReferenceAssemblyTypeReferencesAsync( | ||
IReferenceAssemblySearchService searchService, | ||
ISymbolSearchService searchService, | ||
List<Reference> allReferences, | ||
TSimpleNameSyntax nameNode, | ||
string name, | ||
|
@@ -283,7 +293,7 @@ private async Task<IList<SymbolReference>> GetMatchingTypesAsync(SearchScope sea | |
|
||
private async Task FindNugetTypeReferencesAsync( | ||
PackageSource source, | ||
IPackageSearchService searchService, | ||
ISymbolSearchService searchService, | ||
IPackageInstallerService installerService, | ||
List<Reference> allReferences, | ||
TSimpleNameSyntax nameNode, | ||
|
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.
Nit: Why are these inside the namespace?
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.
I fixed.