Sven created ZEPPELIN-731:
-----------------------------
Summary: Invalid cursor position passed to auto-completion if
%interpreter is given explicitly.
Key: ZEPPELIN-731
URL: https://issues.apache.org/jira/browse/ZEPPELIN-731
Project: Zeppelin
Issue Type: Bug
Components: Core, Interpreters
Affects Versions: 0.5.6, 0.6.0
Environment: Ubuntu, Firefox
Reporter: Sven
h3. The bug
Consider the following notebook-command:
{noformat}"%interpreter TextAfter10Spaces "{noformat}
with the cursor placed directly between "Text" and "After".
Pressing Ctrl + . (for auto-complete) passes the following values to the method
_Interpreter.completion(String buf, int cursor)_:
{{buffer = "TextAfter10Spaces"}} // i.e., the *trimmed* string without
leading/trailing spaces
{{cursor = 14}} // i.e., cursor position referring to the original *untrimmed*
string
For that reason it is impossible to determine the correct cursor position in
the passed buffer, since we have no access to the number of trimmed spaces
(which is usually = 1)
If no interpreter name is given (taking the default interpreter), then the
behaviour is different and correct:
{noformat}commandline = " TextAfter10Spaces "{noformat}
{noformat}buffer = " TextAfter10Spaces "{noformat} // i.e., the
complete, untrimmed string
{{cursor = 14}} // i.e., correctly referring to the untrimmed string
h3. The solution
The solution would be to always pass the full, non-trimmed substring that
follows directly the %interpretermark.
This would in particular give the intuitive guarantee that {{cursor <=
buffer.length()}} holds always true.
h3. Try it yourself
I stumbled upon this on writing my own interpreter, but you can also test it by
adding the following lines to _SparkInterpreter.java_ directly after _public
List<String> completion(String buf, int cursor)_:
{noformat}
javax.swing.JOptionPane.showMessageDialog(null,
"buffer: " + buf + " (" + buf.length() + ")\ncursor:" + cursor);
{noformat}
Then a Swing message window pops up whenever you type Ctrl + .
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)