@@ -4592,7 +4592,7 @@ internal static List<CompletionResult> CompleteVariable(CompletionContext contex
45924592 var wordToComplete = context . WordToComplete ;
45934593 var colon = wordToComplete . IndexOf ( ':' ) ;
45944594
4595- var lastAst = context . RelatedAsts . Last ( ) ;
4595+ var lastAst = context . RelatedAsts ? . Last ( ) ;
45964596 var variableAst = lastAst as VariableExpressionAst ;
45974597 var prefix = variableAst != null && variableAst . Splatted ? "@" : "$" ;
45984598
@@ -6009,19 +6009,22 @@ internal static List<CompletionResult> CompleteType(CompletionContext context, s
60096009 }
60106010
60116011 // this is a temporary fix. Only the type defined in the same script get complete. Need to use using Module when that is available.
6012- var scriptBlockAst = ( ScriptBlockAst ) context . RelatedAsts [ 0 ] ;
6013- var typeAsts = scriptBlockAst . FindAll ( ast => ast is TypeDefinitionAst , false ) . Cast < TypeDefinitionAst > ( ) ;
6014- foreach ( var typeAst in typeAsts . Where ( ast => pattern . IsMatch ( ast . Name ) ) )
6012+ if ( context . RelatedAsts != null && context . RelatedAsts . Count > 0 )
60156013 {
6016- string toolTipPrefix = string . Empty ;
6017- if ( typeAst . IsInterface )
6018- toolTipPrefix = "Interface " ;
6019- else if ( typeAst . IsClass )
6020- toolTipPrefix = "Class " ;
6021- else if ( typeAst . IsEnum )
6022- toolTipPrefix = "Enum " ;
6014+ var scriptBlockAst = ( ScriptBlockAst ) context . RelatedAsts [ 0 ] ;
6015+ var typeAsts = scriptBlockAst . FindAll ( ast => ast is TypeDefinitionAst , false ) . Cast < TypeDefinitionAst > ( ) ;
6016+ foreach ( var typeAst in typeAsts . Where ( ast => pattern . IsMatch ( ast . Name ) ) )
6017+ {
6018+ string toolTipPrefix = string . Empty ;
6019+ if ( typeAst . IsInterface )
6020+ toolTipPrefix = "Interface " ;
6021+ else if ( typeAst . IsClass )
6022+ toolTipPrefix = "Class " ;
6023+ else if ( typeAst . IsEnum )
6024+ toolTipPrefix = "Enum " ;
60236025
6024- results . Add ( new CompletionResult ( prefix + typeAst . Name + suffix , typeAst . Name , CompletionResultType . Type , toolTipPrefix + typeAst . Name ) ) ;
6026+ results . Add ( new CompletionResult ( prefix + typeAst . Name + suffix , typeAst . Name , CompletionResultType . Type , toolTipPrefix + typeAst . Name ) ) ;
6027+ }
60256028 }
60266029
60276030 results . Sort ( ( c1 , c2 ) => string . Compare ( c1 . ListItemText , c2 . ListItemText , StringComparison . OrdinalIgnoreCase ) ) ;
@@ -6030,7 +6033,10 @@ internal static List<CompletionResult> CompleteType(CompletionContext context, s
60306033
60316034 private static string GetNamespaceToRemove ( CompletionContext context , TypeCompletionBase completion )
60326035 {
6033- if ( completion is NamespaceCompletion ) { return null ; }
6036+ if ( completion is NamespaceCompletion || context . RelatedAsts == null || context . RelatedAsts . Count == 0 )
6037+ {
6038+ return null ;
6039+ }
60346040
60356041 var typeCompletion = completion as TypeCompletion ;
60366042 string typeNameSpace = typeCompletion != null
0 commit comments