Trouble with Script Editor in ScriptRunner v7.3.0 in Data Center v8.21.1

As titled, I have Jira Data Center v8.21.1 with ScriptRunner v7.3.0 installed.

Problem 1: Static type check error on one method but not another
In Script Editor, I created a package (say, “mycompany”), then added scripts under its folder.

I have one script file providing a class with 2 static methods:

package mycompany

public class Util {
    public static void method1(Issue issue) {...}
    public static void method2(MutableIssue issue, boolean update) {...}
}

Then in another script, when I tried to call Util class, the second method will be displayed as static type check error. It will say “cannot find matching method”.

The second script runs properly regardless of that error, and there is no static type check error with method 1.

Problem 2: Context help does not work well

  1. Create a new script file inside folder “mycompany”. It will start with “package mycompany”.
  2. Type “import com.”, then Ctrl-space.
  3. Nothing is suggested.
  4. Alternatively, type “ComponentAcc”, then Ctrl-space. After loading a while, “No suggestions”.
  5. It never works until I manually add the import statement. Then I can auto-complete for “ComponentAccessor”.
  6. It only works if I type less… “Com” then Ctrl-space, and context help works.
  7. But it will add the import statement above the package statement, breaking the script. Context-help will be completely disabled (always no suggestions) until I realize the misplaced import statment and fix that.
  8. Any error in the script will break context-help. If I try to context-help inside an incomplete if() statement, no suggestions. Comment out the incomplete if and go one line above, context-help works again.

Hey,

First of all thanks for the feedback, I love seeing it.

For the STC problem, I just did a quick test and I do not get STC errors for this code:

import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import mycompany.Util

Issue issue
MutableIssue mutableIssue

Util.method1(issue)
Util.method2(mutableIssue, true)

If you try to call method2 with Issue that would be a type checking error because MutableIssue extends Issue. If you have determined that your object is an instance of MutableIssue you can cast inline e.g Utils.method2(issue as MutableIssue, true)

It is possible I’m not fully understanding your problem, if you could provide an example that fails STC that would be very helpful. Groovy is a dynamic language and STC can fail for code that will execute properly at runtime, to get green STC you usually will need to help the compiler out by providing more information about your types.

  1. Type “import com.”, then Ctrl-space.
  2. Nothing is suggested.

We don’t yet have support completions of import statements, I think this is generally because our team members usually reference the class in the script and then use the auto import quick fix. We are aware that others manually type imports though.

We have discussed adding the import statement completions, I’m sure we will add it in the mid term.

Alternatively, type “ComponentAcc”, then Ctrl-space. After loading a while, “No suggestions”.

I cannot reproduce this, it’s possible I am doing something wrong

But it will add the import statement above the package statement, breaking the script.

This is a nasty bug, I recall having test coverage for this and am surprised to see such a regression, I will ask somebody to fix this in the next release cycle.

Any error in the script will break context-help.

This is a very tricky problem, STC errors in general shouldn’t completely break code completions, but syntax errors can.

Ultimately the code completions require the Groovy compiler to be able to parse the code, we have various “hacks” to make incomplete source code parse, for example if you type Foo. this is invalid syntax, but you should still see code completions for methods on the class.

In ScriptRunner 7.2.0 we tweaked the Groovy parser to not fail on the first syntax error https://productsupport.adaptavist.com/browse/SRPLAT-2055, this improves things more e.g if (|) should get completions now, although I have spotted some cases where it does not, there is no perfect solution here.

If you could provide minimal code snippets that break code completions I would really appreciate it, I cannot guarantee we will be able to fix them easily, but we are heavily investing into the editing experience within the app.

The in app editing experience is drastically improved from where we were last year, and we are constantly tweaking and fixing bugs, we’re never going to be IntelliJ, but we continue to innovate based on user feedback.

In some cases the in app experience is superior to an IDE, for example we can provide inline completions for custom field names/IDs because the code completion backend runs within Jira, there is a lot more stuff like this on the roadmap :wink:

I hope I’ve given you more context on your valuable feedback, happy to discuss the points in more detail, I will be transparent that the code completion support is not perfect, but we can improve with help from customers.

Cheers!

Reece

Tracking import completions being inserted above package at https://productsupport.adaptavist.com/browse/SRPLAT-2106

What I described happened on a client’s server… it’s deep behind layers of remote access and without internet connection, so I won’t be able to retrieve the code or log easily.

I’ll see if I can reproduce them in my local site and provide an example.

I am having a seriously problem. The script editors in Beahviours tab only sees an outdated version of a script in a package in Script Editor tab.

I added new public static methods in a script in a package in Script Editor. Added a main() method to this script, and call those new methods. I can run this script in Console successfully, the new methods work.

Then in a Behaviour tab, in the script editors there I added the import statement. Context help only shows old methods from the script.

Tried reloading the browser tab for Behaviours, no effect. Tried running clear Groovy/Java cache multiple times, no effect.

How can I force ScriptRunner to refresh everything short of restarting the server?

In Script Editor tab, I have this method, previously only taking MutableIssue, now with an additional boolean parameter:


This script has a main method that can be executed successfully in Console.

In Behaviour tab, context help shows me this:


updateTimeline method is out-dated, not to mention a whole bunch of new methods are missing too.
It does work at runtime if I use the two-parameter version.

I think I have a better idea of what triggered the suggestion issue now.

  1. Have a script in a subfolder.
  2. Add package statement at the top of the script.
  3. Declare a class in the script
  4. Have no error in the class, else context help will give no suggestions.
  5. Type “Com” inside the class. Ctrl-space and no suggestions.
  6. Type “Com” outside the class. Ctrl-space and I get suggestions.
  7. Type “Compon” outside the class. Ctrl-space gives me no suggestions.
  8. Type “Com” outside the class. Ctrl-space and I get suggestions. Keep typing correctly and yet the suggestions disappear.