Repository navigation
Conversation
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>
Contributor
There was a problem hiding this comment.
🟡 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
runandmain. - 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
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Unsure how this feature wasn't in the original release