Skip to content

Commit 26138ad

Browse files
committed
Scope.findStartsWith2: return a map of var name vs classname if any, or null for builtins.
Enables creating constructor autocompletions.
1 parent a6a5104 commit 26138ad

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

  • src/main/java/org/scijava/plugins/scripteditor/jython

‎src/main/java/org/scijava/plugins/scripteditor/jython/Scope.java‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,31 @@ public List<String> findStartsWith(final String name) {
196196
return completions;
197197
}
198198

199+
/** Return a table of names vs classnames, with classnames being null for python builtins.
200+
*
201+
* @param name
202+
* @return
203+
*/
204+
public Map<String, String> findStartsWith2(final String name) {
205+
final Map<String, String> completions = new HashMap<>();
206+
Scope scope = this;
207+
while (null != scope) {
208+
for (final Map.Entry<String, DotAutocompletions> e: scope.vars.entrySet()) {
209+
if (e.getKey().startsWith(name)) completions.put(e.getKey(), e.getValue().getClassname());
210+
}
211+
for (final Map.Entry<String, DotAutocompletions> e: scope.imports.entrySet()) {
212+
if (e.getKey().startsWith(name)) completions.put(e.getKey(), e.getValue().getClassname());
213+
}
214+
for (String builtinName: indexer.getBindings().keySet()) {
215+
if (builtinName.startsWith("__builtin__."))
216+
builtinName = builtinName.substring(12); // without the "__builtin__." prefix
217+
if (builtinName.startsWith(name)) completions.put(builtinName, null);
218+
}
219+
scope = scope.parent;
220+
}
221+
return completions;
222+
}
223+
199224

200225
/** Find vars by type, recursively upstream the nested scopes, listing first those of the innermost scope.
201226
*

0 commit comments

Comments
 (0)