Skip to content

Commit

Permalink
Groovy REPL: add widget to toggle candidate grouping and fix a bug in…
Browse files Browse the repository at this point in the history
… identifiers completion
  • Loading branch information
mattirn committed Sep 24, 2020
1 parent cda92e3 commit d386045
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
15 changes: 15 additions & 0 deletions demo/src/main/scripts/init.jline
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ def _docJline() {
def _docGroovy() {
:doc groovy
}
#
# widget function to toggle candidate grouping
#
def _toggleGroup(){
if (_reader.isSet(org.jline.reader.LineReader.Option.AUTO_GROUP)) {
:setopt no-group
:setopt no-auto-group
} else {
:unsetopt no-group
:unsetopt no-auto-group
}
}

#
# resolve function keys
#
Expand All @@ -148,9 +161,11 @@ widget -N _test-widget _testWidget
widget -N _tailtip-toggle _tailTipToggle
widget -N _doc-jline _docJline
widget -N _doc-groovy _docGroovy
widget -N _toggle-group _toggleGroup

keymap '^[^x' _test-widget
keymap '^[s' _tailtip-toggle
keymap '^[a' _toggle-group
if (_f1 && _f2) {
:keymap $_f1 _doc-jline
:keymap $_f2 _doc-groovy
Expand Down
11 changes: 8 additions & 3 deletions groovy/src/main/java/org/jline/script/GroovyEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -876,9 +876,14 @@ private void doMethodCandidates(List<Candidate> candidates, Class<?> clazz, Stri
Set<String> identifiers = new HashSet<>();
for (String m : methods) {
if (m.matches("get[A-Z].*")) {
char[] c = m.substring(3).toCharArray();
c[0] = Character.toLowerCase(c[0]);
identifiers.add(new String(c));
try {
clazz.getDeclaredMethod(m);
char[] c = m.substring(3).toCharArray();
c[0] = Character.toLowerCase(c[0]);
identifiers.add(new String(c));
} catch (NoSuchMethodException e) {
// ignore
}
}
}
Helpers.doCandidates(candidates, identifiers, curBuf, hint, CandidateType.IDENTIFIER);
Expand Down

0 comments on commit d386045

Please sign in to comment.