Skip to content

Conversation

@hadim
Copy link
Contributor

@hadim hadim commented Apr 18, 2017

Add a framework for an autocompletion framework. Each scripting language is free to implement an AutoCompleter to provide autocompletion.

If they don't the default AdaptedAutoCompleter will just return no results when an autocompletion is asked.

@hadim
Copy link
Contributor Author

hadim commented Apr 18, 2017

@ctrueden let me know what do you think. Even if autocompletion is not implemented yet in the scripting languages, it's fine since all the changes are backward compatible.

@hadim hadim force-pushed the add-autocompletion-framework branch from 7b900a5 to 1e3ba36 Compare April 18, 2017 03:18
@ctrueden
Copy link
Member

Great, this is something I've been wanting to add to the SciJava script framework. (The other major missing thing is a "script recorder" type feature, which given a SciJava module execution, generates the line of code needed to reproduce it in that script language.)

I will try to find time to review the details later this week. Ping me again if I'm holding you up.

@hadim
Copy link
Contributor Author

hadim commented Apr 18, 2017

I don't think I'll have time to implement autocompletion for scripting languages any time soon (need at least another free weekend :-)) but as I said this PR should hold the main foundation of autocompletion.

So feel free to merge after reviewing it.

I'll ping you here at the end of this weekend :-)

@hadim
Copy link
Contributor Author

hadim commented Apr 18, 2017

Also once it's done that work could be used in the Scijava TextEditor :-D

@imagejan
Copy link
Member

Just for reference: Icy has a nice auto-completion here:
https://github.com/tprovoost/Script-Editor/tree/master/javascripter/src/plugins/tprovoost/scripteditor/completion

It was discussed shortly at NEUBIAS2017 and suggested by @ctrueden that this could be ported into https://github.com/scijava/script-editor

It didn't look deep into this code, but maybe we could still profit from their implementations for JS and Python...

@hadim hadim force-pushed the add-autocompletion-framework branch 2 times, most recently from 7b82a48 to c099152 Compare April 19, 2017 01:18
@hadim
Copy link
Contributor Author

hadim commented Apr 19, 2017

Well, I am surprised to see how easy it was to implement a first "naive" working autocompletion !

That implementation should provide autocompletion for all the scripting languages.

I am pretty happy with that for now. The framework should provide an easy way to extend autocompletion being language specific or not.

About the architecture, I am sure it can be improved (I did my best but IJ coding standard are pretty high ! (which is a good thing)). So I am waiting for @ctrueden comments about that :-)


@Override
public AutoCompleter getAutoCompleter(ScriptEngine scriptEngine) {
return new DefaultAutoCompleter(this, scriptEngine);
Copy link
Member

Choose a reason for hiding this comment

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

This override is unnecessary, no? Because AbstractScriptLanguage already defines this same logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Netbeans does not agree with you (only a warning). Should I just remove it ?

Copy link
Member

@ctrueden ctrueden Apr 20, 2017

Choose a reason for hiding this comment

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

Weird. What is the warning? The whole point of having methods implemented in the abstract base class is so that you don't have to implement them that same way in the subclass. NetBeans warning about that does not make sense...

Copy link
Contributor Author

@hadim hadim Apr 20, 2017

Choose a reason for hiding this comment

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

It's saying Add @Override Annotation. Note that the other methods above have @Override

Copy link
Member

Choose a reason for hiding this comment

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

IIUC, @ctrueden means you can leave away the whole method, not just the annotation, no?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, just delete the whole overridden method. Lines 291 through 294.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh ok !


@Override
public AutoCompleter getAutoCompleter(ScriptEngine scriptEngine) {
return new DefaultAutoCompleter(this, scriptEngine);
Copy link
Member

Choose a reason for hiding this comment

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

This override is unnecessary, no? Because AbstractScriptLanguage already defines this same logic?


@Override
public AutoCompleter getAutoCompleter(ScriptEngine scriptEngine) {
return new DefaultAutoCompleter(this, scriptEngine);
Copy link
Member

Choose a reason for hiding this comment

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

This override is unnecessary, no? Because AbstractScriptLanguage already defines this same logic?

@Test
public void testMenuCreation() {
menuService.getMenu();
//menuService.getMenu();
Copy link
Member

Choose a reason for hiding this comment

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

???

Copy link
Member

Choose a reason for hiding this comment

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

This needs more explanation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know why this test was failing. This is not the case anymore. I'll fix that.


@Override
public ScriptLanguage getScriptLanguage() {
return this.scriptLanguage;
Copy link
Member

Choose a reason for hiding this comment

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

Nothing actually uses this field in the base layer... do you use it in downstream implementations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope. I'll remove it.


@Override
public ScriptEngine getScriptEngine() {
return this.scriptEngine;
Copy link
Member

@ctrueden ctrueden Apr 20, 2017

Choose a reason for hiding this comment

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

Alternately, the autocompleter could be kept stateless, with the ScriptEngine instance being passed as another argument to the autocomplete methods. Which do you like better? (I don't feel super strongly; just pointing it out.)

Copy link
Contributor Author

@hadim hadim Apr 20, 2017

Choose a reason for hiding this comment

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

Good point here and I like the idea. That will make the class less complicated.


@Override
public AutoCompleter getAutoCompleter(ScriptEngine scriptEngine) {
return new DefaultAutoCompleter(this, scriptEngine);
Copy link
Member

Choose a reason for hiding this comment

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

Now that we have Java 8, this could be a default method of ScriptLanguage interface itself, rather than in the abstract base class. That would potentially be "more backwards compatible", just in case anyone out there has implemented the ScriptLanguage interface directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll do that.

@ctrueden
Copy link
Member

I made some comments. The only real concern I have is that failing test... otherwise, all looks great. We should decide once and for all if Autocompleter will be stateless, or will wrap a ScriptEngine instance the way you have now. Once we decide that, I'll merge it, and do some minor subsequent cleanup.

@ctrueden
Copy link
Member

ctrueden commented Apr 20, 2017

Relating to @imagejan's comments about Icy's autocompletion: one thing that Icy does is that it gives special priority to the Icy-specific classes. So you end up getting completions that are relevant to the context of Icy plugin development.

The current framework is very general, which is good, but I'm wondering what the best way forward is to make it possible to give contextual hints like that, but in an extensible way. (Icy just hardcodes everything.) One option would be to have some kind of new plugin type that identifies high-priority completions. It would be nice if it were not language-specific either, but rather a layer which operates sort of orthogonally with the actual completion strings. Maybe something as simple as "with such-and-such prefix, which classes make sense to autocomplete?" That will be the same across all script languages, and it will allow components to highlight "completion-friendly" classes. All of these thoughts are half-baked, of course, but wanted to jot this down before it's out of my head again.

@hadim hadim force-pushed the add-autocompletion-framework branch from 6d541e5 to e6cb31f Compare April 20, 2017 22:46
@hadim
Copy link
Contributor Author

hadim commented Apr 20, 2017

All the comments have been addressed. Feel free to merge this one and we can still extend it later. I think it's good enough to start with.

About Icy code, I had a look but I didn't find useful things to steal so I just started from scratch.

The framework is simple for now but I definitely want to make something extensible. For example, we could have AutoCompleterPlugin discovered at runtime and used by AutoCompleter.

My last commit implements autocompletion by inspecting attributes/methods of an object (detected if the string ends by .). That work pretty well but it's not perfect. And of course reflection does not work with Jython (didn't try very hard).

@hadim
Copy link
Contributor Author

hadim commented Apr 20, 2017

Thank you both for your comments.

@hadim
Copy link
Contributor Author

hadim commented Apr 21, 2017

Once this has been merged, I'll cut a new release of the kernel, build conda packages and make an announcement on the forum (I'll also need a new scijava-common release).

@ctrueden
Copy link
Member

Do you need a new pom-scijava, or is a new scijava-common sufficient?

I am currently reworking how status.imagej.net works (actually, it will become status.scijava.org), since the switch to Travis CI broke the old way of generating that page.

@hadim
Copy link
Contributor Author

hadim commented Apr 21, 2017

Well, I just need the last scijava-common version (to get this PR). But I guess you need to edit the version in the pom ?

@ctrueden
Copy link
Member

Eventually we need to update the pom-scijava bill of materials to reference the new SciJava Common version. But in the meantime, you can likely override the scijava-common.version property to point to the forthcoming release.

I just asked because I can merge and release a new SJC soon (will try this weekend if I have time), but getting all my ducks in a row to do the full suite of releases and update pom-scijava to match is a larger endeavor which will take a few more days at least.

@hadim
Copy link
Contributor Author

hadim commented Apr 21, 2017

Oh, I see. So if you just cut a new release of scijava-common, it's fine. I'll override the version property.

@ctrueden
Copy link
Member

ctrueden commented May 4, 2017

Just a note that I haven't forgotten about this. I am planning to clean up and merge this branch soon (within a few days). I have to sort out how to make releases to OSS Sonatype though, now that our Jenkins configuration is hosed up. I want to instead do it from the CLI, without needing Jenkins anymore. Once I have that sorted, I'll try to get this merged, and then cut a new scijava-common release.

@hadim
Copy link
Contributor Author

hadim commented May 4, 2017

Thanks @ctrueden .

If you also have time to look at #265 , that would be nice ! Both PRs carry the final features before having a pretty stable scijava kernel.

Releasing from CLI is definitely the way to go. Good luck with that.

@ctrueden ctrueden closed this in 5768490 May 6, 2017
@ctrueden
Copy link
Member

ctrueden commented May 6, 2017

Cleaned up, fleshed out and merged!

@hadim hadim deleted the add-autocompletion-framework branch May 6, 2017 03:47
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.

3 participants