Skip to content

Commit 88384a4

Browse files
committed
REPL: Use tab instead of completion at beginning of line, complete on each word.
This commit enables tab usage in the graalpython REPL. For now in an otherwise empty line hitting the `key` inserts a tab instead of activating completion. This aligns with the behaviour of the CPython REPL and also makes writing Python code that needs indentation in the REPL more enjoyable. Additionally, completion now happens on a word / token basis, which allows to get completion on more than the first word in a line. E.g. completion on "for i in ra" will now offer completions for "ra" e.g. "range(". This also aligns with the CPython REPL behaviour. The implementation doesn't algin with CPython e.g. in not being able to add additional tabs after already written words in a line. This is due to the implementation with `JLine` functionality. To reach full compatability it might be interesting to investigate why the autocompletion with the completer from `rlcompleter.py` currently doesn't work completely e.g. for tab insertion.
1 parent 10b3cde commit 88384a4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/JLineConsoleHandler.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ public void setupReader(BooleanSupplier shouldRecord,
103103
builder.completer(new Completer() {
104104
@Override
105105
public void complete(LineReader r, ParsedLine pl, List<Candidate> candidates) {
106-
String line = pl.line();
107-
if (line != null) {
108-
List<String> l = completer.apply(line);
106+
String word = pl.word();
107+
if (word != null) {
108+
List<String> l = completer.apply(word);
109109
for (String value : l) {
110110
candidates.add(new Candidate(value, value, null, null, null, null, false));
111111
}
@@ -115,6 +115,7 @@ public void complete(LineReader r, ParsedLine pl, List<Candidate> candidates) {
115115
}
116116
reader = builder.build();
117117
reader.option(LineReader.Option.DISABLE_EVENT_EXPANSION, true);
118+
reader.option(LineReader.Option.INSERT_TAB, true);
118119
reader.setVariable(LineReader.COMMENT_BEGIN, "#");
119120

120121
// numpad bindings

0 commit comments

Comments
 (0)