Skip to content

Commit

Permalink
GroovyEngine: tab completion requires min. one char to show candidates
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Jun 24, 2020
1 parent aafbf36 commit e30759c
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions groovy/src/main/java/org/jline/script/GroovyEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,7 @@ public static int statementBegin(String buffer, String wordbuffer, Brackets brac
, brackets.lastComma() - idx
, brackets.lastOpenCurly() - idx
, brackets.lastCloseCurly() - idx
, brackets.lastSemicolon() - idx
, brackets.lastBlanck() - idx);
, brackets.lastSemicolon() - idx);
}
return out;
}
Expand All @@ -539,10 +538,10 @@ public static int statementBegin(Brackets brackets) {
return statementBegin(brackets.lastDelim()
, brackets.lastOpenRound()
, brackets.lastComma()
, brackets.lastOpenCurly(), brackets.lastCloseCurly(), brackets.lastSemicolon(), brackets.lastBlanck());
, brackets.lastOpenCurly(), brackets.lastCloseCurly(), brackets.lastSemicolon());
}

private static int statementBegin(int lastDelim, int openRound, int comma, int openCurly, int closeCurly, int semicolon, int blanck) {
private static int statementBegin(int lastDelim, int openRound, int comma, int openCurly, int closeCurly, int semicolon) {
int out = lastDelim;
if (openRound > out) {
out = openRound;
Expand All @@ -559,9 +558,6 @@ private static int statementBegin(int lastDelim, int openRound, int comma, int o
if (semicolon > out) {
out = semicolon;
}
if (blanck > out) {
out = blanck;
}
return Math.max(out, -1);
}

Expand Down Expand Up @@ -655,14 +651,14 @@ public void complete(LineReader reader, ParsedLine commandLine, List<Candidate>
}
} else {
boolean addKeyWords = eqsep == brackets.lastSemicolon() || eqsep == brackets.lastOpenCurly();
boolean blancksep = eqsep == brackets.lastBlanck();
int varsep = wordbuffer.lastIndexOf('.');
eqsep = Helpers.statementBegin(buffer, wordbuffer, brackets);
String param = wordbuffer.substring(eqsep + 1);
if (varsep < 0 || varsep < eqsep) {
if (!blancksep || (commandLine.wordIndex() > 1
&& commandLine.words().get(commandLine.wordIndex() - 1).matches("\\w+"))) {
String curBuf = wordbuffer.substring(0, eqsep + 1);
String curBuf = wordbuffer.substring(0, eqsep + 1);
if (param.trim().length() == 0) {
Helpers.doCandidates(candidates, Arrays.asList("") , curBuf, param, CandidateType.OTHER);
} else {
if (addKeyWords) {
Helpers.doCandidates(candidates, KEY_WORDS, curBuf, param, CandidateType.METHOD);
}
Expand Down Expand Up @@ -781,8 +777,7 @@ private Set<String> retrieveClassesWithStaticMethods() {
}

private static class Inspector {
static final String REGEX_FOR_BODY = "\\((.*);.*;.*\\)";
static final Pattern PATTERN_FOR = Pattern.compile("^for\\s*" + REGEX_FOR_BODY + ".*");
static final Pattern PATTERN_FOR = Pattern.compile("^for\\s*\\((.*?);.*");
static final Pattern PATTERN_FUNCTION_BODY = Pattern.compile("^\\s*\\(([a-zA-Z0-9_ ,]*)\\)\\s*\\{(.*)?\\}(|\n)$"
, Pattern.DOTALL);
private GroovyShell shell;
Expand Down Expand Up @@ -1155,10 +1150,6 @@ public int numberOfRounds() {
return rounds;
}

public int numberOfCurlies() {
return curlies;
}

public int lastOpenRound() {
return !roundOpen.isEmpty() ? roundOpen.getLast() : -1;
}
Expand All @@ -1184,10 +1175,6 @@ public int lastSemicolon() {
return lastSemicolon;
}

public int lastBlanck() {
return lastBlanck;
}

public int lastDelim() {
return lastDelim;
}
Expand Down

0 comments on commit e30759c

Please sign in to comment.