@@ -34,51 +34,21 @@ protected override bool IsAvailable(CSharpCodeCompletionContext context)
3434
3535 protected override bool AddLookupItems ( CSharpCodeCompletionContext context , IItemsCollector collector )
3636 {
37- var candidateExistingElements = new List < ISymbolInfo > ( ) ;
38- var table = GetSymbolTable ( context ) ;
39-
40- table ? . ForAllSymbolInfos ( info =>
41- {
42- var declaredElement = info . GetDeclaredElement ( ) ;
43- var type = declaredElement . Type ( ) ;
44-
45- if ( type != null )
46- {
47- if ( type . GetClassType ( ) . ConvertToString ( ) == "Class:Moq.Mock`1" )
48- {
49- IType typeParameter = TypesUtil . GetTypeArgumentValue ( type , 0 ) ;
50- if ( typeParameter != null && context . ExpectedTypesContext != null && context . ExpectedTypesContext . ExpectedITypes != null && context . ExpectedTypesContext . ExpectedITypes . Select ( x => x . Type ) . Where ( x => x != null ) . Any ( x => typeParameter . IsExplicitlyConvertibleTo ( x , ClrPredefinedTypeConversionRule . INSTANCE ) ) )
51- {
52- candidateExistingElements . Add ( info ) ;
53- }
54- }
55- }
56- } ) ;
57-
58- foreach ( var candidateExistingElement in candidateExistingElements )
59- {
60- var proposedCompletion = candidateExistingElement . ShortName + ".Object" ;
61- var lookupItem = GetLookupItem ( context , proposedCompletion ) ;
62- collector . Add ( lookupItem ) ;
63- }
37+ if ( context . ExpectedTypesContext == null )
38+ return false ;
6439
65- if ( context . ExpectedTypesContext != null )
40+ foreach ( var expectedType in context . ExpectedTypesContext . ExpectedITypes )
6641 {
67- foreach ( var expectedType in context . ExpectedTypesContext . ExpectedITypes )
42+ if ( expectedType . Type . IsInterfaceType ( ) )
6843 {
69- if ( expectedType . Type == null )
70- continue ;
71-
72- if ( expectedType . Type . IsInterfaceType ( ) )
73- {
74- string typeName = expectedType . Type . GetPresentableName ( CSharpLanguage . Instance ) ;
75- var proposedCompletion = "new Mock<" + typeName + ">().Object" ;
76- var lookupItem = GetLookupItem ( context , proposedCompletion ) ;
77- collector . Add ( lookupItem ) ;
78- }
44+ var typeName = expectedType . Type . GetPresentableName ( CSharpLanguage . Instance ) ;
45+ var newMock = GetLookupItem ( context , "new Mock<" + typeName + ">().Object" ) ;
46+ var mockOf = GetLookupItem ( context , $ "Mock.Of<{ typeName } >()") ;
47+ collector . Add ( newMock ) ;
48+ collector . Add ( mockOf ) ;
7949 }
8050 }
81- return true ;
51+ return context . ExpectedTypesContext . ExpectedITypes . Count > 0 ;
8252 }
8353
8454 private static ILookupItem GetLookupItem ( CSharpCodeCompletionContext context , string proposedCompletion )
0 commit comments