@@ -4,7 +4,7 @@ import { CompletionItemKind } from 'vscode-languageserver';
44import chalk from 'chalk' ;
55import type { DiagnosticInfo } from './DiagnosticMessages' ;
66import { DiagnosticMessages } from './DiagnosticMessages' ;
7- import type { CallableContainer , BsDiagnostic , FileReference , BscFile , CallableContainerMap , FileLink } from './interfaces' ;
7+ import type { CallableContainer , BsDiagnostic , FileReference , BscFile , CallableContainerMap , FileLink , Callable } from './interfaces' ;
88import type { Program } from './Program' ;
99import { BsClassValidator } from './validators/ClassValidator' ;
1010import type { NamespaceStatement , FunctionStatement , ClassStatement , EnumStatement , InterfaceStatement , EnumMemberStatement , ConstStatement } from './parser/Statement' ;
@@ -488,15 +488,25 @@ export class Scope {
488488 * If there are overridden callables with the same name, the closest callable to this scope is returned
489489 */
490490 public getCallableByName ( name : string ) {
491- let lowerName = name . toLowerCase ( ) ;
492- let callables = this . getAllCallables ( ) ;
493- for ( let callable of callables ) {
494- const callableName = callable . callable . getName ( ParseMode . BrighterScript ) ;
495- // Split by `.` and check the last term to consider namespaces.
496- if ( callableName . toLowerCase ( ) === lowerName || callableName . split ( '.' ) . pop ( ) ?. toLowerCase ( ) === lowerName ) {
497- return callable . callable ;
491+ return this . getCallableMap ( ) . get (
492+ name . toLowerCase ( )
493+ ) ;
494+ }
495+
496+ public getCallableMap ( ) {
497+ return this . cache . getOrAdd ( 'callableMap' , ( ) => {
498+ const result = new Map < string , Callable > ( ) ;
499+ for ( let callable of this . getAllCallables ( ) ) {
500+ const callableName = callable . callable . getName ( ParseMode . BrighterScript ) ?. toLowerCase ( ) ;
501+ result . set ( callableName , callable . callable ) ;
502+ result . set (
503+ // Split by `.` and check the last term to consider namespaces.
504+ callableName . split ( '.' ) . pop ( ) ?. toLowerCase ( ) ,
505+ callable . callable
506+ ) ;
498507 }
499- }
508+ return result ;
509+ } ) ;
500510 }
501511
502512 /**
0 commit comments