@@ -656,22 +656,30 @@ public IScriptExtent GetScriptExtentForFunctionName(FunctionDefinitionAst functi
656656 if ( null == functionDefinitionAst )
657657 {
658658 return null ;
659- }
660-
661- // Obtain the index where the function name is in Tokens
662- int funcTokenIndex = Tokens . Select ( ( s , index ) => new { s , index } )
663- . Where ( x => x . s . Extent . StartOffset == functionDefinitionAst . Extent . StartOffset )
664- . Select ( x => x . index ) . FirstOrDefault ( ) ;
659+ }
660+ var funcNameTokens = Tokens . Where (
661+ token =>
662+ ContainsExtent ( functionDefinitionAst . Extent , token . Extent )
663+ && token . Text . Equals ( functionDefinitionAst . Name ) ) ;
664+ var funcNameToken = funcNameTokens . FirstOrDefault ( ) ;
665+ return funcNameToken == null ? null : funcNameToken . Extent ;
666+ }
665667
666- if ( funcTokenIndex > 0 && funcTokenIndex < Helper . Instance . Tokens . Count ( ) )
668+ /// <summary>
669+ /// Return true if subset is contained in set
670+ /// </summary>
671+ /// <param name="set"></param>
672+ /// <param name="subset"></param>
673+ /// <returns>True or False</returns>
674+ private bool ContainsExtent ( IScriptExtent set , IScriptExtent subset )
675+ {
676+ if ( set == null || subset == null )
667677 {
668- // return the extent of the next token - this is the extent for the function name
669- return Tokens [ ++ funcTokenIndex ] . Extent ;
678+ return false ;
670679 }
671-
672- return null ;
680+ return set . StartOffset <= subset . StartOffset
681+ && set . EndOffset >= subset . EndOffset ;
673682 }
674-
675683 private void FindClosingParenthesis ( string keyword )
676684 {
677685 if ( Tokens == null || Tokens . Length == 0 )
0 commit comments