提交 d0d71a79 编写于 作者: G Gen Lu

Add/remove todos

上级 86897dd0
......@@ -269,7 +269,12 @@ internal static partial class ExtensionMethodImportCompletionHelper
// Container of extension method (static class in C# and Module in VB) can't be generic or nested.
// Note that we might incorrectly ignore valid types, because, for example, calling `GetTypeByMetadataName`
// would return null if we have multiple definitions of a type even though only one is accessible from here
// (e.g. an internal type declared inside a shared document).
// (e.g. an internal type declared inside a shared document). In this case, we have to handle the conflicted
// types explicitly here.
//
// TODO:
// Alternatively, we can try to get symbols out of each assembly, instead of the compilation (which includes all references),
// to avoid such conflict. We should give this approach a try and see if any perf improvement can be archieved.
var containerSymbol = compilation.GetTypeByMetadataName(fullyQualifiedContainerName);
if (containerSymbol != null)
......
......@@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis;
......@@ -512,19 +513,14 @@ public override bool TryGetAliasesFromUsingDirective(SyntaxNode node, out Immuta
return false;
}
public override bool TryGetTargetTypeName(SyntaxNode node, out string targetTypeName)
public override string GetTargetTypeName(SyntaxNode node)
{
if (node is MethodDeclarationSyntax methodDeclaration && IsExtensionMethod(methodDeclaration))
{
var typeParameterNames = methodDeclaration.TypeParameterList?.Parameters.SelectAsArray(p => p.Identifier.Text);
TryGetSimpleTypeName(methodDeclaration.ParameterList.Parameters[0].Type, typeParameterNames, out targetTypeName);
// We always return true here, which indicates we have a valid taget type name. (which would be null for a complex type though).
return true;
}
var methodDeclaration = (MethodDeclarationSyntax)node;
Debug.Assert(IsExtensionMethod(methodDeclaration));
targetTypeName = null;
return false;
var typeParameterNames = methodDeclaration.TypeParameterList?.Parameters.SelectAsArray(p => p.Identifier.Text);
TryGetSimpleTypeName(methodDeclaration.ParameterList.Parameters[0].Type, typeParameterNames, out var targetTypeName);
return targetTypeName;
}
private static bool TryGetSimpleTypeName(SyntaxNode node, ImmutableArray<string>? typeParameterNames, out string simpleTypeName)
......
......@@ -23,7 +23,9 @@ internal interface IDeclaredSymbolInfoFactoryService : ILanguageService
// otherwise we would not be able to get correct data from syntax.
bool TryGetDeclaredSymbolInfo(StringTable stringTable, SyntaxNode node, string rootNamespace, out DeclaredSymbolInfo declaredSymbolInfo);
bool TryGetTargetTypeName(SyntaxNode node, out string instanceTypeName);
// Get the name of the target type of specified extension method declaration node.
// The returned value would be null for complex type.
string GetTargetTypeName(SyntaxNode node);
bool TryGetAliasesFromUsingDirective(SyntaxNode node, out ImmutableArray<(string aliasName, string name)> aliases);
......@@ -304,10 +306,7 @@ internal sealed partial class SyntaxTreeIndex
return;
}
if (!infoFactory.TryGetTargetTypeName(node, out var targetTypeName))
{
return;
}
var targetTypeName = infoFactory.GetTargetTypeName(node);
// complex method
if (targetTypeName == null)
......
......@@ -94,11 +94,12 @@ public static string GetMetadataAritySuffix(int arity)
public abstract bool TryGetDeclaredSymbolInfo(StringTable stringTable, SyntaxNode node, string rootNamespace, out DeclaredSymbolInfo declaredSymbolInfo);
/// <summary>
/// If <paramref name="node"/> is an extension method declaration, this will return true, otherwise it returns false.
/// If the return value is true and <paramref name="targetTypeName"/> is null, then it means this is a "complex" method
/// (as described at <see cref="SyntaxTreeIndex.ExtensionMethodInfo"/>).
/// Get the name of the target type of specified extension method declaration.
/// The node provided must be an extension method declaration, i.e. calling `TryGetDeclaredSymbolInfo()`
/// on `node` should return a `DeclaredSymbolInfo` of kind `ExtensionMethod`.
/// If the return value is null, then it means this is a "complex" method (as described at <see cref="SyntaxTreeIndex.ExtensionMethodInfo"/>).
/// </summary>
public abstract bool TryGetTargetTypeName(SyntaxNode node, out string targetTypeName);
public abstract string GetTargetTypeName(SyntaxNode node);
public abstract bool TryGetAliasesFromUsingDirective(SyntaxNode node, out ImmutableArray<(string aliasName, string name)> aliases);
......
......@@ -460,18 +460,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.FindSymbols
Next
End Sub
Public Overrides Function TryGetTargetTypeName(node As SyntaxNode, ByRef targetTypeName As String) As Boolean
Dim funcDecl = TryCast(node, MethodBlockSyntax)
'TODO: don't call `IsExtensionMethod` again
If funcDecl IsNot Nothing AndAlso IsExtensionMethod(funcDecl) Then
Public Overrides Function GetTargetTypeName(node As SyntaxNode) As String
Dim funcDecl = CType(node, MethodBlockSyntax)
Debug.Assert(IsExtensionMethod(funcDecl))
Dim typeParameterNames = funcDecl.SubOrFunctionStatement.TypeParameterList?.Parameters.SelectAsArray(Function(p) p.Identifier.Text)
TryGetSimpleTypeNameWorker(funcDecl.BlockStatement.ParameterList.Parameters(0).AsClause?.Type, typeParameterNames, targetTypeName)
Return True
End If
Dim typeParameterNames = funcDecl.SubOrFunctionStatement.TypeParameterList?.Parameters.SelectAsArray(Function(p) p.Identifier.Text)
Dim targetTypeName As String = Nothing
TryGetSimpleTypeNameWorker(funcDecl.BlockStatement.ParameterList.Parameters(0).AsClause?.Type, typeParameterNames, targetTypeName)
targetTypeName = Nothing
Return False
Return targetTypeName
End Function
Public Overrides Function TryGetAliasesFromUsingDirective(node As SyntaxNode, ByRef aliases As ImmutableArray(Of (aliasName As String, name As String))) As Boolean
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册