Skip to content

Commit

Permalink
Groovy REPL: improved var tab completion, restrictedCompletion=true
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Sep 11, 2020
1 parent db15475 commit 2894fa7
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions groovy/src/main/java/org/jline/script/GroovyEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -914,11 +914,9 @@ private String defineArgs(String[] args) {
}

public void loadStatementVars(String line) {
if (restrictedCompletion) {
return;
}
for (String s : line.split("\\r?\\n")) {
String statement = s.trim();
boolean constructedStatement = true;
try {
Matcher forEachMatcher = PATTERN_FOR_EACH.matcher(statement);
Matcher forMatcher = PATTERN_FOR.matcher(statement);
Expand Down Expand Up @@ -947,11 +945,18 @@ public void loadStatementVars(String line) {
statement = defineArgs(lambdaMatcher.group(1).split(","));
} else if (statement.contains("=")) {
statement = stripVarType(statement);
constructedStatement = false;
}
Brackets br = new Brackets(statement);
if (statement.contains("=") && !br.openRound() && !br.openCurly() && !br.openSquare()) {
String st = statement.substring(statement.indexOf('=') + 1).trim();
if (!st.isEmpty() && !st.equals("new")) {
int idx = statement.indexOf('=');
String st = "null";
if (restrictedCompletion && !constructedStatement && br.numberOfRounds() > 0) {
statement = statement.substring(0, idx + 1) + "null";
} else {
st = statement.substring(idx + 1).trim();
}
if (!st.isEmpty() && !st.equals("new") ) {
execute(statement);
}
}
Expand Down

0 comments on commit 2894fa7

Please sign in to comment.