Skip to content

function completion from groovy language server - #298

Open
gselzer wants to merge 4 commits into
mainfrom
scijava-lsp-groovy/function-completion
Open

gselzer wants to merge 4 commits into
mainfrom
scijava-lsp-groovy/function-completion

Conversation

@gselzer

@gselzer gselzer commented Nov 19, 2026

Copy link
Copy Markdown
Member

Unsure how this feature wasn't in the original release

gselzer and others added 2 commits November 19, 2026 15:16
Note that currently functions declared after the carat will not be given in completion requests. This could be enabled later, but it requires more changes
A script's functions are methods of its class, so Groovy can call them
from anywhere in the script, including above their declaration. Offer
them by analyzing the whole script, with the caret marked; if that
doesn't parse (e.g. the caret's line is unfinished), fall back to the
functions before the caret.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Function completions incorrectly include out-of-scope script methods inside declared classes and exclude exact-name matches, preventing access to callable snippets and overload details.

2 open issues
What changed in this PR

Adds script-function completion to the Groovy language server, reusing existing callable snippets and signature details.

Changes:

  • Discovers functions across the script, including later declarations, with a fallback to source before the caret when parsing fails.
  • Enumerates script-declared methods separately from generated methods such as run and main.
  • Adds tests for declaration order, recursive calls, incomplete syntax, and generated-method exclusion.
File Description
scijava-lsp-groovy/​src/​test/​java/​org/​scijava/​lsp/​groovy/​GroovyLanguageServerTest.java Adds function-completion tests and helpers for explicit caret positions.
scijava-lsp-groovy/​src/​main/​java/​org/​scijava/​lsp/​groovy/​TypedAST.java Exposes all script-declared methods through the module AST.
scijava-lsp-groovy/​src/​main/​java/​org/​scijava/​lsp/​groovy/​GroovyLanguageServer.java Adds function discovery and completion, adapts signature lookup, and renames the class-method helper.

Review effort: Balanced

gselzer and others added 2 commits November 20, 2026 15:46
A script's functions are methods of the script class, so the classes it
declares cannot call them. Rather than offering them everywhere, offer
the methods callable without a receiver at the caret: those of the class
whose code contains it, of the classes it is nested in, and those they
inherit from their superclasses (declared in the script or compiled,
Object and groovy.lang.Script included). The methods Groovy generates
for the script class (run, main) are still left out.

Member completion and signature help on instances of classes defined in
the script now include inherited members too, however far up.

Also, offer nothing for a name being declared (after def, class,
interface, enum, trait, record or @interface).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Typing a function's complete name (e.g. "foo") filtered it out of the
completions, though its snippet still adds the call's parentheses and
arguments (e.g. "foo(${1:n})"). Keep exact matches, as member-method
completion already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants