提交 accff1e2 编写于 作者: L lorcanmooney 提交者: Sam Harwell

Add typeparamref completion element for containing elements

Fixes #17872
上级 803b5a60
......@@ -327,13 +327,16 @@ public class goo
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task MethodParamTypeParam()
{
await VerifyItemsExistAsync(@"
public class goo<T>
var text = @"
public class goo<TGoo>
{
/// $$
public int bar<T>(T green) { }
}", "typeparam name=\"T\"", "param name=\"green\"");
public int bar<TBar>(TBar green) { }
}";
await VerifyItemsExistAsync(text, "typeparam name=\"TBar\"", "param name=\"green\"");
await VerifyItemsAbsentAsync(text, "typeparam name=\"TGoo\"");
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
......@@ -348,18 +351,27 @@ public class goo<T>
}", "param name=\"green\"");
}
[WorkItem(17872, "https://github.com/dotnet/roslyn/issues/17872")]
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task MethodParamRefName()
{
await VerifyItemsExistAsync(@"
public class goo<T>
var text = @"
public class Outer<TOuter>
{
/// <summary>
/// $$
/// </summary>
public int bar<T>(T green) { }
}", "typeparamref name=\"T\"", "paramref name=\"green\"");
public class Inner<TInner>
{
/// <summary>
/// $$
/// </summary>
public int Method<TMethod>(T green) { }
}
}";
await VerifyItemsExistAsync(
text,
"typeparamref name=\"TOuter\"",
"typeparamref name=\"TInner\"",
"typeparamref name=\"TMethod\"",
"paramref name=\"green\"");
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
......@@ -1172,28 +1184,42 @@ static void Goo(string str)
", "str");
}
[WorkItem(17872, "https://github.com/dotnet/roslyn/issues/17872")]
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task TypeParamRefNames()
{
await VerifyItemExistsAsync(@"
/// <summary>
/// <typeparamref name=""$$""/>
/// </summary>
static void Goo<T>()
var text = @"
public class Outer<TOuter>
{
}
", "T");
public class Inner<TInner>
{
/// <summary>
/// <typeparamref name=""$$""/>
/// </summary>
public int Method<TMethod>(T green) { }
}
}";
await VerifyItemsExistAsync(text, "TOuter", "TInner", "TMethod");
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task TypeParamNames()
{
await VerifyItemExistsAsync(@"
/// <typeparam name=""$$""/>
static void Goo<T>()
var text = @"
public class Outer<TOuter>
{
}
", "T");
public class Inner<TInner>
{
/// <summary>
/// <typeparam name=""$$""/>
/// </summary>
public int Method<TMethod>(T green) { }
}
}";
await VerifyItemsExistAsync(text, "TMethod");
await VerifyItemsAbsentAsync(text, "TOuter", "TInner");
}
[WorkItem(8322, "https://github.com/dotnet/roslyn/issues/8322")]
......
......@@ -112,19 +112,27 @@ End Class
Await VerifyItemsExistAsync(text, "code", "list", "para")
End Function
<WorkItem(17872, "https://github.com/dotnet/roslyn/issues/17872")>
<Fact, Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function TestRepeatableNestedParamRefAndTypeParamRefTagsOnMethod() As Task
Dim text = "
Class C
''' <summary>
''' <$$
''' </summary>
Sub Goo(Of T)(i as Integer)
End Sub
Class Outer(Of TOuter)
Class Inner(Of TInner)
''' <summary>
''' $$
''' </summary>
Sub Goo(Of TMethod)(i as Integer)
End Sub
End Class
End Class
"
Await VerifyItemsExistAsync(text, "paramref name=""i""", "typeparamref name=""T""")
Await VerifyItemsExistAsync(
text,
"paramref name=""i""",
"typeparamref name=""TOuter""",
"typeparamref name=""TInner""",
"typeparamref name=""TMethod""")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.Completion)>
......@@ -239,14 +247,15 @@ End Class
<Fact, Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function TestMethodParamTypeParam() As Task
Dim text = "
Class C(Of T)
Class C(Of TClass)
''' <$$
Sub Goo(Of T)(bar as T)
Sub Goo(Of TMethod)(bar as TMethod)
End Sub
End Class
"
Await VerifyItemsExistAsync(text, "param name=""bar""", "typeparam name=""T""")
Await VerifyItemsExistAsync(text, "param name=""bar""", "typeparam name=""TMethod""")
Await VerifyItemsAbsentAsync(text, "typeparam name=""TClass""")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.Completion)>
......@@ -799,28 +808,31 @@ End Class
<Fact, Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function TestTypeParamNames() As Task
Dim text = "
Class C
Class C(Of TClass)
''' <typeparam name=""$$""
Sub Goo(Of T)(i as Integer)
Sub Goo(Of TMethod)(i as TMethod)
End Sub
End Class
"
Await VerifyItemsExistAsync(text, "T")
Await VerifyItemsAbsentAsync(text, "i")
Await VerifyItemsExistAsync(text, "TMethod")
Await VerifyItemsAbsentAsync(text, "TClass", "i")
End Function
<WorkItem(17872, "https://github.com/dotnet/roslyn/issues/17872")>
<Fact, Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function TestTypeParamRefNames() As Task
Dim text = "
Class C
''' <summary>
''' <typeparamref name=""$$""
''' </summary>
Sub Goo(Of T)(i as Integer)
End Sub
Class Outer(Of TOuter)
Class Inner(Of TInner)
''' <summary>
''' <typeparamref name=""$$""
''' </summary>
Sub Goo(Of TMethod)(i as Integer)
End Sub
End Class
End Class
"
Await VerifyItemsExistAsync(text, "T")
Await VerifyItemsExistAsync(text, "TOuter", "TInner", "TMethod")
Await VerifyItemsAbsentAsync(text, "i")
End Function
......
......@@ -149,7 +149,7 @@ private IEnumerable<CompletionItem> GetParamRefItems(ISymbol symbol)
private IEnumerable<CompletionItem> GetTypeParamRefItems(ISymbol symbol)
{
var names = symbol.GetTypeParameters().Select(t => t.Name);
var names = symbol.GetAllTypeParameters().Select(t => t.Name);
return names.Select(t => CreateCompletionItem(
displayText: FormatParameter(TypeParameterReferenceElementName, t),
......@@ -166,11 +166,16 @@ protected IEnumerable<CompletionItem> GetAttributeValueItems(ISymbol symbol, str
return symbol.GetParameters()
.Select(parameter => CreateCompletionItem(parameter.Name));
}
else if (tagName == TypeParameterElementName || tagName == TypeParameterReferenceElementName)
else if (tagName == TypeParameterElementName)
{
return symbol.GetTypeParameters()
.Select(typeParameter => CreateCompletionItem(typeParameter.Name));
}
else if (tagName == TypeParameterReferenceElementName)
{
return symbol.GetAllTypeParameters()
.Select(typeParameter => CreateCompletionItem(typeParameter.Name));
}
}
else if (attributeName == LangwordAttributeName && tagName == SeeElementName)
{
......
......@@ -425,6 +425,19 @@ public static ImmutableArray<ITypeParameterSymbol> GetTypeParameters(this ISymbo
}
}
public static ImmutableArray<ITypeParameterSymbol> GetAllTypeParameters(this ISymbol symbol)
{
var results = ArrayBuilder<ITypeParameterSymbol>.GetInstance();
while (symbol != null)
{
results.AddRange(symbol.GetTypeParameters());
symbol = symbol.ContainingType;
}
return results.ToImmutableAndFree();
}
public static ImmutableArray<ITypeSymbol> GetTypeArguments(this ISymbol symbol)
{
switch (symbol)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册