Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<license.copyrightOwners>Hadrien Mary</license.copyrightOwners>
<netbeans.hint.license>apache20</netbeans.hint.license>
<commons-lang3.version>3.5</commons-lang3.version>
<scijava-common.version>2.63.0-SNAPSHOT</scijava-common.version>
</properties>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.scijava.Context;
import org.scijava.log.LogService;
import org.scijava.plugin.Parameter;
import org.scijava.script.AutoCompleter;
import org.scijava.script.AutoCompletionResult;
import org.scijava.script.ScriptLanguage;
import org.scijava.script.ScriptService;
import org.scijava.thread.ThreadService;
Expand All @@ -64,6 +66,7 @@ public class ScijavaEvaluator implements Evaluator {

private final Map<String, ScriptEngine> scriptEngines;
private final Map<String, ScriptLanguage> scriptLanguages;
private final Map<String, AutoCompleter> completers;
private String languageName;

protected String shellId;
Expand All @@ -77,6 +80,8 @@ public ScijavaEvaluator(Context context, String shellId, String sessionId) {

this.scriptEngines = new HashMap<>();
this.scriptLanguages = new HashMap<>();

this.completers = new HashMap<>();

this.languageName = DEFAULT_LANGUAGE;
}
Expand All @@ -87,12 +92,19 @@ public void setShellOptions(KernelParameters kp) throws IOException {
}

@Override
public AutocompleteResult autocomplete(String code, int i) {
List<String> matches = new ArrayList<>();
matches.add("Autocompletion does not work yet.");
int startIndex = 0;
AutocompleteResult ac = new AutocompleteResult(matches, startIndex);
return ac;
public AutocompleteResult autocomplete(String code, int index) {

// TODO: we need to find a way the language related to the current cell.
// For now, we are just using the last used language.
AutoCompleter completer = this.completers.get(this.languageName);
ScriptEngine scriptEngine = this.scriptEngines.get(this.languageName);

AutoCompletionResult result = completer.autocomplete(code, index, scriptEngine);

List<String> matches = (List<String>) result.getMatches();
int startIndex = (int) result.getStartIndex();

return new AutocompleteResult(matches, startIndex);
}

@Override
Expand Down Expand Up @@ -145,6 +157,9 @@ private void addLanguage(String langName) {

ScriptEngine engine = this.scriptLanguages.get(langName).getScriptEngine();
this.scriptEngines.put(langName, engine);

AutoCompleter completer = scriptLanguage.getAutoCompleter();
this.completers.put(languageName, completer);

// Not implemented yet
//engine.setBindings(this.bindings, ScriptContext.ENGINE_SCOPE);
Expand Down