-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18442 from CyrusNajmabadi/addImportOOPWork1
Break types into their own files.
- Loading branch information
Showing
7 changed files
with
259 additions
and
208 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
src/Features/Core/Portable/AddImport/SearchScopes/AllSymbolsProjectSearchScope.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// 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.Collections.Immutable; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.FindSymbols; | ||
|
||
namespace Microsoft.CodeAnalysis.CodeFixes.AddImport | ||
{ | ||
internal abstract partial class AbstractAddImportCodeFixProvider<TSimpleNameSyntax> | ||
{ | ||
/// <summary> | ||
/// SearchScope used for searching *all* the symbols contained within a project/compilation. | ||
/// i.e. the symbols created from source *and* symbols from references (both project and | ||
/// metadata). | ||
/// </summary> | ||
private class AllSymbolsProjectSearchScope : ProjectSearchScope | ||
{ | ||
public AllSymbolsProjectSearchScope( | ||
AbstractAddImportCodeFixProvider<TSimpleNameSyntax> provider, | ||
Project project, | ||
bool exact, | ||
CancellationToken cancellationToken) | ||
: base(provider, project, exact, cancellationToken) | ||
{ | ||
} | ||
|
||
protected override Task<ImmutableArray<ISymbol>> FindDeclarationsAsync( | ||
string name, SymbolFilter filter, SearchQuery searchQuery) | ||
{ | ||
return SymbolFinder.FindDeclarationsAsync(_project, searchQuery, filter, CancellationToken); | ||
} | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/Features/Core/Portable/AddImport/SearchScopes/MetadataSymbolsSearchScope.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// 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.Collections.Immutable; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.FindSymbols; | ||
using Microsoft.CodeAnalysis.FindSymbols.SymbolTree; | ||
|
||
namespace Microsoft.CodeAnalysis.CodeFixes.AddImport | ||
{ | ||
internal abstract partial class AbstractAddImportCodeFixProvider<TSimpleNameSyntax> | ||
{ | ||
private class MetadataSymbolsSearchScope : SearchScope | ||
{ | ||
private readonly IAssemblySymbol _assembly; | ||
private readonly PortableExecutableReference _metadataReference; | ||
private readonly Solution _solution; | ||
|
||
public MetadataSymbolsSearchScope( | ||
AbstractAddImportCodeFixProvider<TSimpleNameSyntax> provider, | ||
Solution solution, | ||
IAssemblySymbol assembly, | ||
PortableExecutableReference metadataReference, | ||
bool exact, | ||
CancellationToken cancellationToken) | ||
: base(provider, exact, cancellationToken) | ||
{ | ||
_solution = solution; | ||
_assembly = assembly; | ||
_metadataReference = metadataReference; | ||
} | ||
|
||
public override SymbolReference CreateReference<T>(SymbolResult<T> searchResult) | ||
{ | ||
return new MetadataSymbolReference( | ||
provider, | ||
searchResult.WithSymbol<INamespaceOrTypeSymbol>(searchResult.Symbol), | ||
_metadataReference); | ||
} | ||
|
||
protected override async Task<ImmutableArray<ISymbol>> FindDeclarationsAsync( | ||
string name, SymbolFilter filter, SearchQuery searchQuery) | ||
{ | ||
var service = _solution.Workspace.Services.GetService<ISymbolTreeInfoCacheService>(); | ||
var info = await service.TryGetMetadataSymbolTreeInfoAsync(_solution, _metadataReference, CancellationToken).ConfigureAwait(false); | ||
if (info == null) | ||
{ | ||
return ImmutableArray<ISymbol>.Empty; | ||
} | ||
|
||
return await info.FindAsync(searchQuery, _assembly, filter, CancellationToken).ConfigureAwait(false); | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Features/Core/Portable/AddImport/SearchScopes/ProjectSearchScope.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 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.Threading; | ||
|
||
namespace Microsoft.CodeAnalysis.CodeFixes.AddImport | ||
{ | ||
internal abstract partial class AbstractAddImportCodeFixProvider<TSimpleNameSyntax> | ||
{ | ||
private abstract class ProjectSearchScope : SearchScope | ||
{ | ||
protected readonly Project _project; | ||
|
||
public ProjectSearchScope( | ||
AbstractAddImportCodeFixProvider<TSimpleNameSyntax> provider, | ||
Project project, | ||
bool exact, | ||
CancellationToken cancellationToken) | ||
: base(provider, exact, cancellationToken) | ||
{ | ||
_project = project; | ||
} | ||
|
||
public override SymbolReference CreateReference<T>(SymbolResult<T> symbol) | ||
{ | ||
return new ProjectSymbolReference( | ||
provider, symbol.WithSymbol<INamespaceOrTypeSymbol>(symbol.Symbol), _project); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.