From 567c676530ee1872d93ff6431b4fa4725aa9885c Mon Sep 17 00:00:00 2001 From: Tomas Stupka <tomas.stupka@oracle.com> Date: Wed, 11 Oct 2017 18:23:35 +0200 Subject: [PATCH] fixed completion token start offset computation --- .../truffle/r/launcher/JLineConsoleCompleter.java | 12 ++++-------- .../test/engine/shell/TestJLineConsoleCompleter.java | 5 +++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/JLineConsoleCompleter.java b/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/JLineConsoleCompleter.java index 9f44951bda..fda22b4054 100644 --- a/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/JLineConsoleCompleter.java +++ b/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/JLineConsoleCompleter.java @@ -111,14 +111,10 @@ public class JLineConsoleCompleter implements Completer { start = lastIdxOf(buffer, opt, "function.suffix", start, cursor); } - // are we just after a ',' or ' ' - if (cursor > 0 && cursor <= buffer.length() && (buffer.charAt(cursor - 1) == ',' || buffer.charAt(cursor - 1) == ' ')) { - return cursor; - } - - // is there any next closest ',' or ' '? - int idx = cursor >= buffer.length() ? buffer.length() - 1 : cursor; - while (idx >= start && (buffer.charAt(idx) != ',' && buffer.charAt(idx) != ' ')) { + // is there any preceeding ',' or ' ' - lets start from there + String precBuffer = buffer.length() > cursor ? buffer.substring(0, cursor) : buffer; + int idx = cursor >= precBuffer.length() ? precBuffer.length() - 1 : cursor - 1; + while (idx >= start && precBuffer.charAt(idx) != ',' && precBuffer.charAt(idx) != ' ') { --idx; } if (idx > -1) { diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/shell/TestJLineConsoleCompleter.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/shell/TestJLineConsoleCompleter.java index f197deb077..c8817f4c9f 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/shell/TestJLineConsoleCompleter.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/shell/TestJLineConsoleCompleter.java @@ -92,6 +92,11 @@ public class TestJLineConsoleCompleter { assertCompl("strtoi", 4, "strtoi", "strtrim"); assertCompl("strto ", 6); assertCompl("strto,", 6); + assertCompl("strt blabla", 4, "strtoi", "strtrim"); + assertCompl("strt blabla", 4, "strtoi", "strtrim"); + assertCompl("strt,,blabla", 4, "strtoi", "strtrim"); + assertCompl("strt, blabla", 4, "strtoi", "strtrim"); + assertCompl("strto blabla", 4, "strtoi", "strtrim"); assertCompl("blabla,strt", 11, "strtoi", "strtrim"); assertCompl("blabla strt", 11, "strtoi", "strtrim"); assertCompl("blabla,,strt", 12, "strtoi", "strtrim"); -- GitLab