Skip to content

Commit

Permalink
Merge pull request #18442 from CyrusNajmabadi/addImportOOPWork1
Browse files Browse the repository at this point in the history
Break types into their own files.
  • Loading branch information
CyrusNajmabadi authored Apr 4, 2017
2 parents 70fcc4a + 7d771b3 commit 414caf6
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 208 deletions.
207 changes: 0 additions & 207 deletions src/Features/Core/Portable/AddImport/SearchScope.cs

This file was deleted.

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);
}
}
}
}
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);
}
}
}
}
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);
}
}
}
}
Loading

0 comments on commit 414caf6

Please sign in to comment.