From ebc87b0aae9fcc7839d660dbd88bd0abee400623 Mon Sep 17 00:00:00 2001 From: Robert Gaggl Date: Sat, 25 Sep 2021 11:38:53 +0200 Subject: [PATCH 1/2] fix: repl autocompletion now continues to suggest candidates autocompletion/suggestion didn't work for method call arguments: ``` const obj = {one: {two: {three: 3}}} JSON.stringify(obj.o ``` didn't expand to `JSON.stringify(obj.one` because the candidates produced didn't start with `JSON.stringify(`, so they were dropped by jline. this change also fixes highlighting of candidate prefixes: before only the typed characters were highlighted, now ringo shell highlights up to the next completion point (if any). --- src/org/ringojs/tools/RingoShell.java | 39 ++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/org/ringojs/tools/RingoShell.java b/src/org/ringojs/tools/RingoShell.java index 1dc773be8..ab3c7af30 100644 --- a/src/org/ringojs/tools/RingoShell.java +++ b/src/org/ringojs/tools/RingoShell.java @@ -23,8 +23,6 @@ import org.jline.reader.impl.history.DefaultHistory; import org.jline.terminal.Terminal; import org.jline.terminal.TerminalBuilder; -import org.jline.utils.AttributedStringBuilder; -import org.jline.utils.AttributedStyle; import org.ringojs.engine.ModuleScope; import org.ringojs.engine.ReloadableScript; import org.ringojs.engine.RhinoEngine; @@ -248,11 +246,12 @@ class JSCompleter implements Completer { @Override public void complete(LineReader lineReader, ParsedLine parsedLine, List list) { try { - Matcher match = variables.matcher(parsedLine.line()); + String line = parsedLine.line(); + Matcher match = variables.matcher(line); if (match.find()) { - String word = match.group(2); + String path = match.group(2); Scriptable obj = scope; - String[] parts = word.split("\\.", -1); + String[] parts = path.split("\\.", -1); for (int k = 0; k < parts.length - 1; k++) { Object o = ScriptableObject.getProperty(obj, parts[k]); if (o == null || o == ScriptableObject.NOT_FOUND) { @@ -260,15 +259,16 @@ public void complete(LineReader lineReader, ParsedLine parsedLine, List list) { + private void collectIds(Object[] ids, Scriptable obj, String line, String lastPart, List list) { for (Object id: ids) { if (!(id instanceof String)) { continue; } String str = (String) id; - if (str.startsWith(lastpart) || word.endsWith(".")) { + if (str.startsWith(lastPart)) { if (ScriptableObject.getProperty(obj, str) instanceof Callable) { str += "("; } - String suffix = str.substring(lastpart.length()); - AttributedStringBuilder sb = new AttributedStringBuilder(); - sb.styled(AttributedStyle.DEFAULT.foreground(AttributedStyle.CYAN), lastpart); - sb.styled(AttributedStyle.DEFAULT, suffix); - list.add(new Candidate(word + suffix, - sb.toAnsi(terminal), null, null, null, null, false)); + Candidate candidate = new Candidate(line + str, line + str, null, null, null, null, false); + list.add(candidate); } } } @@ -308,28 +304,35 @@ private void collectIds(Object[] ids, Scriptable obj, String word, String lastpa "break", "case", "catch", + "const", "continue", + "debugger", "default", "delete", "do", "else", + "false", "finally", "for", "function", "if", "in", "instanceof", + "let", "new", + "null", "return", "switch", "this", "throw", + "true", "try", "typeof", "var", "void", "while", - "with" + "with", + "yield" }; } From aab3568a0ff4ed59569b93475de4dca6fb65e6d5 Mon Sep 17 00:00:00 2001 From: Robert Gaggl Date: Sat, 25 Sep 2021 11:39:12 +0200 Subject: [PATCH 2/2] updated jline to 3.20.0 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 9330f8469..872a3d918 100644 --- a/build.gradle +++ b/build.gradle @@ -50,7 +50,7 @@ dependencies { implementation 'org.apache.logging.log4j:log4j-core:2.14.0' implementation 'org.apache.logging.log4j:log4j-api:2.14.0' implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.14.0' - implementation 'org.jline:jline:3.17.1' + implementation 'org.jline:jline:3.20.0' implementation 'junit:junit:4.13.1' }