提交 649f3b63 编写于 作者: G Gen Lu

Don't show non attribute import completion items in attribute context

上级 fa73aa94
......@@ -915,6 +915,7 @@ public async Task AttributeTypeInAttributeNameContext()
namespace Foo
{
public class MyAttribute : System.Attribute { }
public class MyClass { }
}";
var file2 = @"
......@@ -927,6 +928,7 @@ class Program { }
await VerifyTypeImportItemExistsAsync(markup, "My", glyph: (int)Glyph.ClassPublic, inlineDescription: "Foo", expectedDescriptionOrNull: "class Foo.MyAttribute");
await VerifyTypeImportItemIsAbsentAsync(markup, "MyAttribute", inlineDescription: "Foo");
await VerifyTypeImportItemIsAbsentAsync(markup, "MyClass", inlineDescription: "Foo");
}
[InlineData(SourceCodeKind.Regular)]
......@@ -969,6 +971,7 @@ public async Task AttributeTypeInNonAttributeNameContext()
namespace Foo
{
public class MyAttribute : System.Attribute { }
public class MyClass { }
}";
var file2 = @"
......@@ -983,6 +986,7 @@ class Program
await VerifyTypeImportItemExistsAsync(markup, "MyAttribute", glyph: (int)Glyph.ClassPublic, inlineDescription: "Foo", expectedDescriptionOrNull: "class Foo.MyAttribute");
await VerifyTypeImportItemIsAbsentAsync(markup, "My", inlineDescription: "Foo");
await VerifyTypeImportItemExistsAsync(markup, "MyClass", glyph: (int)Glyph.ClassPublic, inlineDescription: "Foo", expectedDescriptionOrNull: "class Foo.MyClass");
}
[InlineData(SourceCodeKind.Regular)]
......@@ -1028,6 +1032,7 @@ public async Task AttributeTypeWithoutSuffixInAttributeNameContext()
namespace Foo
{
public class Myattribute : System.Attribute { }
public class MyClass { }
}";
var file2 = @"
......@@ -1040,6 +1045,7 @@ class Program { }
await VerifyTypeImportItemExistsAsync(markup, "Myattribute", glyph: (int)Glyph.ClassPublic, inlineDescription: "Foo", expectedDescriptionOrNull: "class Foo.Myattribute");
await VerifyTypeImportItemIsAbsentAsync(markup, "My", inlineDescription: "Foo");
await VerifyTypeImportItemIsAbsentAsync(markup, "MyClass", inlineDescription: "Foo");
}
[InlineData(SourceCodeKind.Regular)]
......@@ -1082,6 +1088,7 @@ public async Task AttributeTypeWithoutSuffixInNonAttributeNameContext()
namespace Foo
{
public class Myattribute : System.Attribute { }
public class MyClass { }
}";
var file2 = @"
......@@ -1096,6 +1103,7 @@ class Program
await VerifyTypeImportItemExistsAsync(markup, "Myattribute", glyph: (int)Glyph.ClassPublic, inlineDescription: "Foo", expectedDescriptionOrNull: "class Foo.Myattribute");
await VerifyTypeImportItemIsAbsentAsync(markup, "My", inlineDescription: "Foo");
await VerifyTypeImportItemExistsAsync(markup, "MyClass", glyph: (int)Glyph.ClassPublic, inlineDescription: "Foo", expectedDescriptionOrNull: "class Foo.MyClass");
}
[InlineData(SourceCodeKind.Regular)]
......@@ -1142,6 +1150,8 @@ Namespace Foo
Public Class Myattribute
Inherits System.Attribute
End Class
Public Class MyVBClass
End Class
End Namespace";
var file2 = @"
......@@ -1157,6 +1167,7 @@ class Program
await VerifyTypeImportItemExistsAsync(markup, "Myattribute", glyph: (int)Glyph.ClassPublic, inlineDescription: "Foo", expectedDescriptionOrNull: "class Foo.Myattribute");
await VerifyTypeImportItemIsAbsentAsync(markup, "My", inlineDescription: "Foo");
await VerifyTypeImportItemIsAbsentAsync(markup, "MyVBClass", inlineDescription: "Foo");
}
......
......@@ -41,6 +41,8 @@ Namespace Foo
Public Class MyAttribute
Inherits System.Attribute
End Class
Public Class MyVBClass
End Class
End Namespace</Text>.Value
Dim file2 = <Text><![CDATA[
......@@ -54,6 +56,33 @@ End Class]]></Text>.Value
Dim markup = CreateMarkupForSingleProject(file2, file1, LanguageNames.VisualBasic)
Await VerifyItemExistsAsync(markup, "My", glyph:=Glyph.ClassPublic, inlineDescription:="Foo", expectedDescriptionOrNull:="Class Foo.MyAttribute")
Await VerifyItemIsAbsentAsync(markup, "MyAttribute", inlineDescription:="Foo")
Await VerifyItemIsAbsentAsync(markup, "MyVBClass", inlineDescription:="Foo")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.Completion)>
<WorkItem(35540, "https://github.com/dotnet/roslyn/issues/35540")>
Public Async Function AttributeTypeInNonAttributeNameContext() As Task
Dim file1 = <Text>
Namespace Foo
Public Class MyAttribute
Inherits System.Attribute
End Class
Public Class MyVBClass
End Class
End Namespace</Text>.Value
Dim file2 = <Text><![CDATA[
Public Class Bar
Sub Main()
Dim x As $$
End Sub
End Class]]></Text>.Value
Dim markup = CreateMarkupForSingleProject(file2, file1, LanguageNames.VisualBasic)
Await VerifyItemExistsAsync(markup, "MyAttribute", glyph:=Glyph.ClassPublic, inlineDescription:="Foo", expectedDescriptionOrNull:="Class Foo.MyAttribute")
Await VerifyItemExistsAsync(markup, "MyVBClass", glyph:=Glyph.ClassPublic, inlineDescription:="Foo", expectedDescriptionOrNull:="Class Foo.MyVBClass")
Await VerifyItemIsAbsentAsync(markup, "My", inlineDescription:="Foo")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.Completion)>
......
......@@ -212,14 +212,17 @@ static string GetReferenceKey(PortableExecutableReference reference)
cache[key] = cacheEntry;
}
foreach (var item in cacheEntry.CommonItems)
if (!syntaxContext.IsAttributeNameContext)
{
handleItem(item);
}
foreach (var item in cacheEntry.CommonItems)
{
handleItem(item);
}
foreach (var item in cacheEntry.GetGenericItems(isCSharp))
{
handleItem(item);
foreach (var item in cacheEntry.GetGenericItems(isCSharp))
{
handleItem(item);
}
}
foreach (var item in cacheEntry.GetAttributeItems(isCSharp, syntaxContext.IsAttributeNameContext))
......@@ -375,6 +378,7 @@ public void AddItem(INamedTypeSymbol symbol, string containingNamespace, bool is
{
ArrayBuilder<TypeImportCompletionItemInfo> correspondingBuilder;
// Attribute type can't be generic
if (symbol.Arity > 0)
{
correspondingBuilder = _genericItemsBuilder;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册