提交 100234ca 编写于 作者: C Cyrus Najmabadi

We should never match with a namespace if the user has provided generic type args.

上级 1665ebc0
......@@ -159,9 +159,16 @@ NewLines("Imports System.Collections.Generic \n Class Foo \n Function F() As Lis
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsAddImport)>
Public Async Function TestGenericWithWrongArgs() As Task
Public Async Function TestGenericWithWrongArgs1() As Task
Await TestMissingAsync(
NewLines("Class Foo \n Function F() As [|List(Of Integer, String)|] \n End Function \n End Class"))
NewLines("Class Foo \n Function F() As [|List(Of Integer, String, Boolean)|] \n End Function \n End Class"))
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsAddImport)>
Public Async Function TestGenericWithWrongArgs2() As Task
Await TestAsync(
NewLines("Class Foo \n Function F() As [|List(Of Integer, String)|] \n End Function \n End Class"),
NewLines("Imports System.Collections.Generic \n Class Foo \n Function F() As SortedList(Of Integer, String) \n End Function \n End Class"))
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsAddImport)>
......
......@@ -508,6 +508,11 @@ private async Task<IList<SymbolReference>> GetNamespacesForMatchingNamespacesAsy
int arity;
_syntaxFacts.GetNameAndArityOfSimpleName(_node, out name, out arity);
if (arity > 0)
{
return null;
}
if (ExpressionBinds(checkForExtensionMethods: false))
{
return null;
......
......@@ -293,13 +293,28 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.AddImport
placeSystemNamespaceFirst As Boolean,
cancellationToken As CancellationToken) As Task(Of Document)
Dim originalDocument = document
Dim originalContextNode = contextNode
Dim originalRoot = DirectCast(contextNode.SyntaxTree.GetRoot(cancellationToken), CompilationUnitSyntax)
Dim root = originalRoot
If Not String.IsNullOrEmpty(desiredName) Then
Dim firstToken = contextNode.GetFirstToken()
If firstToken.IsKind(SyntaxKind.IdentifierToken) AndAlso firstToken.ValueText <> desiredName Then
Dim annotation = New SyntaxAnnotation()
root = root.ReplaceToken(firstToken, SyntaxFactory.Identifier(desiredName).WithTriviaFrom(firstToken).WithAdditionalAnnotations(annotation))
document = document.WithSyntaxRoot(root)
contextNode = root.GetAnnotatedTokens(annotation).First().Parent
End If
End If
Dim memberImportsClause =
SyntaxFactory.SimpleImportsClause(name:=DirectCast(symbol.GenerateTypeSyntax(addGlobal:=False), NameSyntax).WithAdditionalAnnotations(Simplifier.Annotation))
Dim newImport = SyntaxFactory.ImportsStatement(
importsClauses:=SyntaxFactory.SingletonSeparatedList(Of ImportsClauseSyntax)(memberImportsClause))
Dim syntaxTree = contextNode.SyntaxTree
Dim root = DirectCast(syntaxTree.GetRoot(cancellationToken), CompilationUnitSyntax)
Return Task.FromResult(
document.WithSyntaxRoot(
root.AddImportsStatement(newImport, placeSystemNamespaceFirst,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册