@@ -35,7 +35,7 @@ public static CompletionResult GetCompletions(Node statement, ScopeStatement sco
3535 applicableSpan = new SourceSpan ( context . IndexToLocation ( span . Value . Start ) , context . IndexToLocation ( span . Value . End ) ) ;
3636 }
3737
38- var scope = context . Analysis . FindScope ( context . Location ) ;
38+ var scope = context . Analysis . FindScope ( context . Location ) ?? context . Analysis . GlobalScope ;
3939 IEnumerable < CompletionItem > items ;
4040 using ( eval . OpenScope ( scope ) ) {
4141 // Get variables declared in the module.
@@ -45,15 +45,18 @@ public static CompletionResult GetCompletions(Node statement, ScopeStatement sco
4545
4646 // Get builtins
4747 var builtins = context . Analysis . Document . Interpreter . ModuleResolution . BuiltinsModule ;
48- var builtinItems = builtins . GetMemberNames ( )
49- . Select ( n => {
50- var m = builtins . GetMember ( n ) ;
51- if ( ( options & CompletionListOptions . ExceptionsOnly ) == CompletionListOptions . ExceptionsOnly && ! IsExceptionType ( m . GetPythonType ( ) ) ) {
52- return null ;
53- }
54- return context . ItemSource . CreateCompletionItem ( n , m ) ;
55- } ) . ExcludeDefault ( ) ;
56- items = items . Concat ( builtinItems ) ;
48+ if ( builtins != null ) {
49+ var builtinItems = builtins . GetMemberNames ( )
50+ . Select ( n => {
51+ var m = builtins . GetMember ( n ) ;
52+ if ( ( options & CompletionListOptions . ExceptionsOnly ) == CompletionListOptions . ExceptionsOnly && ! IsExceptionType ( m . GetPythonType ( ) ) ) {
53+ return null ;
54+ }
55+
56+ return context . ItemSource . CreateCompletionItem ( n , m ) ;
57+ } ) . ExcludeDefault ( ) ;
58+ items = items . Concat ( builtinItems ) ;
59+ }
5760
5861 // Add possible function arguments.
5962 var finder = new ExpressionFinder ( context . Ast , new FindExpressionOptions { Calls = true } ) ;
0 commit comments