Skip to content

Add code completion for JSR223 scripts - #6860

Open
orimarko wants to merge 1 commit into
apache:masterfrom
orimarko:gh4540-jsr233-autocomplete
Open

orimarko wants to merge 1 commit into
apache:masterfrom
orimarko:gh4540-jsr233-autocomplete

Conversation

@orimarko

@orimarko orimarko commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds explicitly triggered code completion (Ctrl+Space) to JSR223 script editors, including common JMeter bindings, methods, and element-specific bindings. Completion is limited to JSR223 editors and does not affect BSF editors. Adds the AutoComplete dependency and its license metadata.

Motivation and Context

Makes JMeter-provided bindings and common script methods easier to discover while editing JSR223 scripts. Closes #4540.

How Has This Been Tested?

  • .\gradlew.bat --quiet :src:core:test --tests org.apache.jmeter.gui.util.JSR223CompletionTest - passed (15 tests)
  • .\gradlew.bat --quiet classes style - passed
  • git diff --check - passed

Known issue from GUI testing: Switching between JSR223 components in same hierarchy under sampler (i.e assertion and timer) can leave the entire editor panel displaying the previously selected component's values, even though the destination element retains its distinct saved script. This refresh regression is not fixed in this PR; verify/fix before merging. The isolated TestBeanGUI.configure() regression test passes but does not reproduce the full GUI selection behavior.

Screenshots (if appropriate):

Not applicable.

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly.

@milamberspace milamberspace 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.

Thanks for this, Ctrl+Space completion in the JSR223 editors will be welcome, and keeping it out of the BSF editors and off auto-activation is a good call. The dependency side also looks right: autocomplete is BSD-3-Clause (Category A), and the com.fifesoft signing key is already trusted in gradle/verification-metadata.xml.

A few things need to change before this can be merged:

  1. Rebase needed. src/dist/src/dist/expected_release_jars.csv was removed on master by #6846. It is replaced by src/dist/src/dist/expected_release_artifacts.txt, which lists group:artifact coordinates without versions. After the rebase, please drop the .csv change and add com.fifesoft:autocomplete to the new file (./gradlew -PupdateExpectedJars ... rewrites it). verifyReleaseDependencies now fails on -SNAPSHOT builds too.
  2. Bindings per element. The hasSampleResultBinding flag only covers SampleResult, but other elements expose bindings that are missing (see the inline comment).
  3. Documentation. The checklist says the docs were updated, but only changes.xml changed. Please mention Ctrl+Space in component_reference.xml, e.g. in the common JSR223 description or at the Script field, and add <pr>6860</pr> to the changes entry.

Smaller, optional points are in the inline comments. Two more:

  • On macOS, Ctrl+Space often switches the keyboard input source. Could you check which trigger key AutoComplete uses there by default, and whether it works in JMeter?
  • A short comment in JSR223TestElement.populateBindings pointing to JSR223Completion would help keep the two lists in sync when a binding is added.

Comment thread xdocs/changes.xml Resolved
@orimarko
orimarko force-pushed the gh4540-jsr233-autocomplete branch from fa50752 to 264827b Compare December 1, 2026 13:11
@orimarko

orimarko commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

The current Ctrl+Space completion is intentionally limited to the known JMeter bindings and the methods explicitly registered for them. It does not infer types for variables created in scripts or resolve chained expressions, so examples such as a = ctx.getThreadGroup(); a. and b = ctx.getVariables(); b. will not offer suggestions. These cases are not currently supported.

macOS GUI behavior has not been tested. AutoComplete uses Ctrl+Space by default, but macOS input-source switching may capture that shortcut before JMeter receives it.

@milamberspace milamberspace 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.

Thanks for the thorough update. Everything from my previous review is addressed: rebased onto expected_release_artifacts.txt, per-element bindings via JSR223Completion.Binding (Sampler: SampleResult; Assertion: SampleResult + AssertionResult; Listener: sampleEvent + sampleResult), vars.remove returning Object, the new TypeEditor constant at the end, the sync comment in populateBindings, and <pr>6860</pr> in changes.xml. I checked the completion list against JSR223TestElement.populateBindings and the element-specific bindings, and they match. The descriptor copy to keep binding metadata isolated between elements is a good catch, and nicely covered by elementBindingMetadataIsIsolated.

One thing to fix in the docs before merging, plus two nits inline.

@vlsi vlsi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • F19 remains open. The shortcut paragraph still interrupts the compilation introduction and list.
  • F20 remains open. The descriptor field can be initialized during superclass construction and still relies on having no initializer.
  • F21 remains open. The enum field still uses name for the text of the script binding.

Ctrl+Space can corrupt an existing expression (F1). BeanInfos compiled against JMeter 5.6.3 lose constructor linkage (F2), plugins lose their explicit script editors after recompilation (F3), and JavaBeans metadata loses indexed accessors (F4).

Recognize the full Groovy receiver and member selector when matching and inserting completions to address F7 and F8 together.

Reviewed at b6e8dd28.

@orimarko
orimarko force-pushed the gh4540-jsr233-autocomplete branch from db96ad7 to 908141c Compare December 5, 2026 13:27
Generated-by: GitHub Copilot
@orimarko
orimarko force-pushed the gh4540-jsr233-autocomplete branch 2 times, most recently from db7cec1 to 0ccf458 Compare December 5, 2026 14:35
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.

JSR223 Test Elements : Have code completion

3 participants