提交 cd5481da 编写于 作者: C Cyrus Najmabadi

When renaming a VB form, cascade to the synthesized compiler "My" property for...

When renaming a VB form, cascade to the synthesized compiler "My" property for the instance of the form.
上级 1c7d9dcd
......@@ -84,6 +84,5 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Sub
End Class
End Class
End Namespace
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
namespace Microsoft.CodeAnalysis.FindSymbols.Finders
{
internal interface ILanguageServiceReferenceFinder : ILanguageService
{
Task<IEnumerable<ISymbol>> DetermineCascadedSymbolsAsync(INamedTypeSymbol symbol, Project project, CancellationToken cancellationToken);
}
}
\ No newline at end of file
// 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.Generic;
using System.Collections.Immutable;
using System.Linq;
......@@ -19,26 +20,54 @@ protected override bool CanFind(INamedTypeSymbol symbol)
return symbol.TypeKind != TypeKind.Error;
}
protected override Task<IEnumerable<ISymbol>> DetermineCascadedSymbolsAsync(
protected override async Task<IEnumerable<ISymbol>> DetermineCascadedSymbolsAsync(
INamedTypeSymbol symbol,
Solution solution,
IImmutableSet<Project> projects,
CancellationToken cancellationToken)
{
IEnumerable<ISymbol> result = SpecializedCollections.EmptyEnumerable<ISymbol>();
List<ISymbol> result = null;
if (symbol.AssociatedSymbol != null)
{
result = result.Concat(SpecializedCollections.SingletonEnumerable(symbol.AssociatedSymbol));
result = Add(result, SpecializedCollections.SingletonEnumerable(symbol.AssociatedSymbol));
}
// cascade to constructors
result = result.Concat(symbol.Constructors);
result = Add(result, symbol.Constructors);
// cascade to destructor
result = result.Concat(symbol.GetMembers(WellKnownMemberNames.DestructorName));
result = Add(result, symbol.GetMembers(WellKnownMemberNames.DestructorName));
return Task.FromResult(result);
result = Add(result, await DetermineLanguageCascadedSymbolsAsync(symbol, solution, cancellationToken).ConfigureAwait(false));
return result ?? SpecializedCollections.EmptyList<ISymbol>();
}
private async Task<IEnumerable<ISymbol>> DetermineLanguageCascadedSymbolsAsync(INamedTypeSymbol symbol, Solution solution, CancellationToken cancellationToken)
{
var definitionProject = solution.GetProject(symbol.ContainingAssembly, cancellationToken);
if (definitionProject != null)
{
var referenceFinder = definitionProject.LanguageServices.GetService<ILanguageServiceReferenceFinder>();
if (referenceFinder != null)
{
return await referenceFinder.DetermineCascadedSymbolsAsync(symbol, definitionProject, cancellationToken).ConfigureAwait(false);
}
}
return null;
}
private List<ISymbol> Add(List<ISymbol> result, IEnumerable<ISymbol> enumerable)
{
if (enumerable != null)
{
result = result ?? new List<ISymbol>();
result.AddRange(enumerable);
}
return result;
}
protected override async Task<IEnumerable<Document>> DetermineDocumentsToSearchAsync(
......
......@@ -373,6 +373,7 @@
<Compile Include="Differencing\SequenceEdit.cs" />
<Compile Include="ExtensionManager\IErrorReportingService.cs" />
<Compile Include="FindSymbols\DeclaredSymbolInfo.cs" />
<Compile Include="FindSymbols\FindReferences\Finders\ILanguageServiceReferenceFinder.cs" />
<Compile Include="FindSymbols\SyntaxTree\AbstractSyntaxTreeInfo.cs" />
<Compile Include="FindSymbols\SyntaxTree\SyntaxTreeDeclarationInfo.cs" />
<Compile Include="Formatting\FormattingOptionsProvider.cs" />
......
......@@ -151,6 +151,7 @@
<Compile Include="Extensions\TypeBlockSyntaxExtensions.vb" />
<Compile Include="Extensions\TypeSyntaxGeneratorVisitor.vb" />
<Compile Include="Extensions\VariableDeclaratorSyntaxExtensions.vb" />
<Compile Include="FindSymbols\VisualBasicReferenceFinder.vb" />
<Compile Include="Formatting\DefaultOperationProvider.vb" />
<Compile Include="Formatting\Engine\AggregatedFormattingResult.vb" />
<Compile Include="Formatting\Engine\FormattingResult.vb" />
......
Imports System.Composition
Imports System.Threading
Imports System.Threading.Tasks
Imports Microsoft.CodeAnalysis.FindSymbols.Finders
Imports Microsoft.CodeAnalysis.Host.Mef
Namespace Microsoft.CodeAnalysis.FindSymbols
<ExportLanguageService(GetType(ILanguageServiceReferenceFinder), LanguageNames.VisualBasic), [Shared]>
Friend Class VisualBasicReferenceFinder
Implements ILanguageServiceReferenceFinder
Public Async Function DetermineCascadedSymbolsAsync(namedType As INamedTypeSymbol, project As Project, cancellationToken As CancellationToken) As Task(Of IEnumerable(Of ISymbol)) Implements ILanguageServiceReferenceFinder.DetermineCascadedSymbolsAsync
If namedType.Language = LanguageNames.VisualBasic AndAlso project.Language = LanguageNames.VisualBasic Then
Dim compilation = Await project.GetCompilationAsync(cancellationToken).ConfigureAwait(False)
' If this is a WinForms project, then the VB 'my' feature may have synthesized
' a property that would return an instance of the main Form type for the project.
' Search for such properties and cascade to them as well.
Dim myPropertySymbols = GetMatchingMyPropertySymbols(namedType, DirectCast(compilation, VisualBasicCompilation), cancellationToken).Distinct().ToList()
If myPropertySymbols.Count > 0 Then
Return myPropertySymbols
End If
End If
Return Nothing
End Function
Private Function GetMatchingMyPropertySymbols(symbol As INamedTypeSymbol, compilation As VisualBasicCompilation, cancellationToken As CancellationToken) As IEnumerable(Of IPropertySymbol)
Return GetMatchingMyPropertySymbols(symbol, compilation, compilation.GlobalNamespace, cancellationToken).Concat(
GetMatchingMyPropertySymbols(symbol, compilation, compilation.RootNamespace, cancellationToken))
End Function
Private Function GetMatchingMyPropertySymbols(namedType As INamedTypeSymbol,
compilation As VisualBasicCompilation,
[namespace] As INamespaceSymbol,
cancellationToken As CancellationToken) As IEnumerable(Of IPropertySymbol)
Return From childNamespace In [namespace].GetNamespaceMembers()
Where childNamespace.IsMyNamespace(compilation)
From type In childNamespace.GetAllTypes(cancellationToken)
Where type.Name = "MyForms"
From childProperty In type.GetMembers().OfType(Of IPropertySymbol)
Where childProperty.IsImplicitlyDeclared AndAlso childProperty.Type.Equals(namedType)
Select childProperty
End Function
End Class
End Namespace
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册