scijava / script-editor

Script Editor and Interpreter for SciJava script languages
http://imagej.net/Script_Editor
BSD 2-Clause "Simplified" License
12 stars 12 forks source link

Extend Jython auto-completion to instantiated classes #51

Closed tferr closed 2 years ago

tferr commented 3 years ago

@acardona , @haesleinhuepf , This implements the following changes by extending Albert's recent work:

imagesc-bot commented 3 years ago

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/auto-code-completion-for-python-and-groovy-in-imagej-fiji/20515/22

tferr commented 3 years ago

@acardona , there are still two things that are missing in this PR:

  1. Import with parenthesis are not recognized. E.g. in from ij import (ImagePlus, ImageProcessor), neither ImagePlus nor ImageProcessor get recognized as being imported
  2. the description of the auto-completion is missing the URL for the class's Javadoc. This would be straightforward to include the a tag here. I think ClassUtil, has already all that information cached?
  3. Another issue: currently completion works only with instantiated classes. It does not work with instances retrieved from static calls. I.e.: this works well:
    from ij import ImagePlus
    imp = ImagePlus()

    But no completions are retrieved if you use:

    from ij import IJ
    imp = IJ.getImage()

    The latter would be the most important issue. I will wait for your feedback on this.

imagesc-bot commented 3 years ago

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/auto-code-completion-for-python-and-groovy-in-imagej-fiji/20515/25

acardona commented 3 years ago

Thanks a lot @tferr, this is great.

On from ij import (ImagePlus, ImageProcessor): are these even valid? If so, I had no idea. In python, one can use multi-imports like:

from ij import ImagePlus, ImageProcessor

or even:

from ij import ImagePlus,\
                 ImageProcessor
acardona commented 3 years ago

On this use case:

from ij import IJ
imp = IJ.getImage()

If it's from a static method, the object class can be retrieved from the return type of the static method.

If it's from a function, like:

from ij import IJ
def getImage():
  return IJ.getImage()

imp = getImage()

... then no cookie: it's the perennial problem in non-strongly typed languages. Python is fixing this with annotations, which seem to be a part of the language in 3.8. There is currently an effort to bring jython to python 3+, but it's very understaffed (one very part-time developer).

tferr commented 3 years ago

For clarity, here is what this PR implements:

Here are some snapshots:

Field: image

Fuzzy string search (methods): image

Invalid import: image

I have to say, I find it quite functional even at this stage. NB:

acardona commented 3 years ago

Hi @tferr, the code may have changed significantly. Would appreciate if you could revise your commits and see which can be applied. The branch I pushed forward is "fix-autocompletion-listener".

And @haesleinhuepf: notice I've had to change the AutoCompletionListener interface significantly. Please have a look, should be straightforward to adapt for CLIJ to insert expansions for commonly used variable names.

tferr commented 3 years ago

@acardona, to include JavaDoc URLs and list types in the completions, I would have to modify DotAutoCompletions#get() to return both the completion String and the completion description (also a String). Are you OK with it?

acardona commented 3 years ago

Hi @tferr, sounds good, should then return a new object that has both as fields rather than just a String.

acardona commented 3 years ago

By the way @tferr, when done, after review/test, I'd appreciate very much if you could release it all: the jython-autocompletion and the script-editor, so that it all appears in the Fiji updater.

tferr commented 3 years ago

@acardona, sincere apologies for the delay. 'Real work' got in the way. I think I have it working, but still need to test it more seriously. Hyperlinks seem to be working, and the completion lists the type for both fields and methods. If there are no major issues I will push and release tonight.

There are still some (minor) issues like the .acess$000 entry below, but we can always tackle this at a later time point), otherwise it will never be ready image

acardona commented 3 years ago

Sounds great! On the subclasses: a one-liner filtering for dollar signs '$', indicative of subclasses, would do, at the level of the returned stream or list of autocompletions.

tferr commented 3 years ago

@acardona, I don't seem to have write access to this repository. Could you please merge this AND release version 5.0.10 of the script editor? Otherwise, give me write permissions and I will do so. Thanks!