imagej / imagej-ui-swing

ImageJ UI for Java Swing.
BSD 2-Clause "Simplified" License
10 stars 20 forks source link

Scripteditor codeassist and code completion #54

Closed Squareys closed 9 years ago

Squareys commented 9 years ago

Hello everybody!

This adds codecompletion/-assist to the script editor using fifesoft Autocomplete and RSTALanguageSupport. This branch is based on #51, which is needed to be merged first.

Support for Autocompletion can be extend by extending the LanguageSupportPlugin. The repository RSTALanguageSupport also implements outline trees for java for example, which one could take into consideration for the script editor. (Not implemented in this PR!)

For this pullrequest, code assist is implemented for Java and JavaScript.

Have a nice day, Squareys.

Squareys commented 9 years ago

I will do a quick rebase onto master to make sure, then this can be merged, too.

Squareys commented 9 years ago

Ah, much better :) You may have a look at this, it's ready from my side.

hinerm commented 9 years ago

@Squareys this is really cool stuff.

I think how the API is actually being used needs a bit of tweaking though:

As a side note - is it possible to install the language support on the tab instead of the pane..? Does switching tabs cause setLanguage to be called? (just can't remember offhand) If not sure it matters.. just wondering.

Squareys commented 9 years ago

@hinerm:

You don't need to call initialize on the service. It's called at context startup.

The Service is not added to the context. (Or is it... automatically?)

The LanguageSupportService should just be a (non-static) @Parameter

Well, see above.

You shouldn't need to cache the LanguageSupport instance.

Alright, your suggestion makes sense, will do so tomorrow (German time, therefore in 12-14 hrs)

is it possible to install the language support on the tab instead of the pane

You mean install it on the pane but from the outside? Theoretically yes.

Does switching tabs cause setLanguage to be called?

I do not believe so. It should at least only be called, when:

  1. Set by the user manually
  2. A file is opened/reloaded/saved.
ctrueden commented 9 years ago

The Service is not added to the context. (Or is it... automatically?)

Yes, it is. You wrote @Plugin(type = Service.class) so when a full-blown Context is created during ImageJ startup, it will instantiate and initialize a LanguageSupportService which is part of that context. You should never call new on it directly, or initialize for that matter.

Squareys commented 9 years ago

Yes, it is.

Awesome! I will change the code respectively.

Best to have a single version property for the com.fifesoft stuff that is set to 2.5.7 and reuse it in all relevant deps.

Alright, will do.

Squareys commented 9 years ago

@ctrueden Alright, I think I addressed all the issues mentioned above.

Squareys commented 9 years ago

Well, for some reason, AutoCompletion is not working anymore. I will need to investigate that first, before this can be merged.

Squareys commented 9 years ago

Alright, done! This may be merged.

hinerm commented 9 years ago

Hi @Squareys . This is looking really good.

The main problem I'm finding is that it seems like an uncaught exception is thrown by code completion parser when there's a compilation error. It's redundant because the error is already displayed in the editor.. so we don't want the stack trace to pop up in the console window. Is there a way to suppress these IOExceptions?

You can see this easily by dropping this into Fiji and opening any Java template. It currently is inserting .java into the class names which causes compilation errors. (I'm looking into fixing the .java error)

hinerm commented 9 years ago

OK, fixed the .java class name: https://github.com/imagej/imagej-ui-swing/commit/5ba7bf8b3b406355ac153413fd619de8830b7e97

hinerm commented 9 years ago

bleh.. so there is a catch block guarding these exceptions, it's being caught earlier here and printed.

hinerm commented 9 years ago

see: https://github.com/bobbylight/RSTALanguageSupport/issues/26

hinerm commented 9 years ago

Alright @Squareys ... I just commented out the Java language plugin for now, until the stacktrace printing is resolved upstream. Everything on your end looked good so I merged. Thanks again for your work on this!

Squareys commented 9 years ago

@hinerm You're welcome, thank you, too! :)