imagej / imagej-legacy

ImageJ+ImageJ2 compatibility layer
https://imagej.net/libs/imagej-legacy
BSD 2-Clause "Simplified" License
17 stars 25 forks source link

Autocomplete methods and functions #220

Closed haesleinhuepf closed 5 years ago

haesleinhuepf commented 5 years ago

Hey all, hey @imagejan, hey @ctrueden,

I'm testing the autocompletion of variable names and functions+comments for some time. Also users on the forum seemed to be pretty happy about it. https://forum.image.sc/t/auto-code-completion-for-ij-macro/11642/95

Do you see any issues? Shall we merge it? Thanks!

Cheers, Robert

ctrueden commented 5 years ago

Thanks, @haesleinhuepf. I'd like to dig in to the Travis CI failure. The issue is probably with explicit ImageJ1 class references. I am considering how best to deal with it. We could whitelist the class net.imagej.legacy.plugin.MacroAutoCompletionProvider, or we could tweak it not to use a direct reference to the IJ1 Interpreter. I am also considering whether it might be better to split the IJ1 macro language plugin to a separate component from the base imagej-legacy layer.

haesleinhuepf commented 5 years ago

Hey @ctrueden

are there any news regarding the CI?

I added some more updates and new content to the auto-completion. For example @imagejan may like this one: image

Thanks for your support!

Cheers, Robert

ctrueden commented 5 years ago

I force-pushed a change that I hope will fix it.

ctrueden commented 5 years ago

Here is the patch that I squashed in:

diff --git src/main/java/net/imagej/legacy/IJ1Helper.java src/main/java/net/imagej/legacy/IJ1Helper.java
index 41ee03b..4919c4e 100644
--- src/main/java/net/imagej/legacy/IJ1Helper.java
+++ src/main/java/net/imagej/legacy/IJ1Helper.java
@@ -598,6 +598,11 @@ public class IJ1Helper extends AbstractContextual {
                return Interpreter.getInstance();
        }

+       /** Gets the result of {@link Interpreter#getAdditionalFunctions()}. */
+       public static String getAdditionalMacroFunctions() {
+               return Interpreter.getAdditionalFunctions();
+       }
+
        /**
         * Gets the value of the specified variable, from the given macro
         * {@link Interpreter}.
diff --git src/main/java/net/imagej/legacy/plugin/MacroAutoCompletionProvider.java src/main/java/net/imagej/legacy/plugin/MacroAutoCompletionProvider.java
index 760d3c5..4ee4ff2 100644
--- src/main/java/net/imagej/legacy/plugin/MacroAutoCompletionProvider.java
+++ src/main/java/net/imagej/legacy/plugin/MacroAutoCompletionProvider.java
@@ -42,14 +42,14 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;

-import ij.macro.Interpreter;
+import net.imagej.legacy.IJ1Helper;
+
 import org.fife.ui.autocomplete.BasicCompletion;
 import org.fife.ui.autocomplete.Completion;
 import org.fife.ui.autocomplete.DefaultCompletionProvider;
 import org.fife.ui.autocomplete.SortByRelevanceComparator;
 import org.fife.ui.rtextarea.RTextArea;
 import org.fife.ui.rtextarea.ToolTipSupplier;
-
 import org.scijava.module.ModuleInfo;
 import org.scijava.module.ModuleService;

@@ -324,7 +324,7 @@ class MacroAutoCompletionProvider extends DefaultCompletionProvider implements
                        e.printStackTrace();
                        return;
                }
-               text = text + "\n" + Interpreter.getAdditionalFunctions();
+               text = text + "\n" + IJ1Helper.getAdditionalMacroFunctions();

                int linecount = 0;
                String[] textArray = text.split("\n");
ctrueden commented 5 years ago

The CI passed, so I merged it.

haesleinhuepf commented 5 years ago

Great, thanks @ctrueden ! 😍