@@ -181,6 +181,7 @@ protected CompletionList complete(final Document doc, final int caret) {
181181 if (member ) items .addAll (memberCompletions (ast , before , prefix ));
182182 else {
183183 items .addAll (variableCompletions (ast .variablesAtCaret (), prefix ));
184+ items .addAll (functionCompletions (ast , prefix ));
184185 items .addAll (keywordCompletions (prefix ));
185186 items .addAll (classCompletions (doc , prefix ));
186187 }
@@ -462,7 +463,7 @@ private List<CompletionItem> scriptClassMembers(
462463 .getName ()) != null ) continue ;
463464 out .add (field (f .getName (), f .getType ().toString (false )));
464465 }
465- for (final Overload m : scriptMethods (type , prefix , staticOnly , false )) {
466+ for (final Overload m : classMethods (type , prefix , staticOnly , false )) {
466467 out .add (m .toItem ());
467468 }
468469 final List <CompletionItem > sorted = sorted (out );
@@ -483,7 +484,7 @@ private static List<CompletionItem> members(final Class<?> c,
483484 }
484485
485486 /** Methods of a class defined in the script: by prefix, or exact name. */
486- private static List <Overload > scriptMethods (final ClassNode type ,
487+ private static List <Overload > classMethods (final ClassNode type ,
487488 final String name , final boolean staticOnly , final boolean exact )
488489 {
489490 final List <Overload > out = new ArrayList <>();
@@ -557,6 +558,20 @@ private static List<CompletionItem> variableCompletions(
557558 return out ;
558559 }
559560
561+ private static List <CompletionItem > functionCompletions (final TypedAST ast ,
562+ final String prefix )
563+ {
564+ final List <CompletionItem > out = new ArrayList <>();
565+ for (final MethodNode m : ast .scriptMethods ()) {
566+ if (!matches (m .getName (), prefix ) || m .getName ().equals (prefix )) {
567+ continue ;
568+ }
569+ out .add (methodNode (m .getName (), m ).detail (m .getTypeDescriptor ())
570+ .toItem ());
571+ }
572+ return sorted (out );
573+ }
574+
560575 /** Groovy's keywords */
561576 private static Set <String > keywords () {
562577 // NB: The lexer literals don't contain primitives - we add those ourselves
@@ -681,8 +696,8 @@ else if (type.isPrimaryClassNode()) {
681696 if (name == null ) return out ;
682697 if (e .isImplicitThis ()) {
683698 // A function defined in the script, or a GDK method such as println.
684- for (final MethodNode m : ast .scriptMethods (name )) {
685- out .add (methodNode (name , m ));
699+ for (final MethodNode m : ast .scriptMethods ()) {
700+ if ( m . getName (). equals ( name )) out .add (methodNode (name , m ));
686701 }
687702 out .addAll (named (gdkMethods (Object .class , name ), name ));
688703 return out ;
@@ -692,7 +707,7 @@ else if (type.isPrimaryClassNode()) {
692707 if (type == null ) return out ;
693708 final boolean staticOnly = receiver instanceof ClassExpression ;
694709 if (type .redirect ().isPrimaryClassNode ()) {
695- return scriptMethods (type .redirect (), name , staticOnly , true );
710+ return classMethods (type .redirect (), name , staticOnly , true );
696711 }
697712 final Class <?> c = Types .box (ast .toClass (type ));
698713 if (c == null ) return out ;
0 commit comments