Commit 27760736 authored by Antonio Rojas's avatar Antonio Rojas
Browse files

Fix tab completion in Sage

Get the completions from Sage itself, instead of relying on ipython internals.

BUG:434024
parent 01147fba
Pipeline #55039 skipped
......@@ -16,7 +16,7 @@ file was created there while the computation was in progress.
Sage offers the pretty_print_default option to automatically return latex code
for the results. This is used when Typesetting is enabled.
TabCompletion is implemented by calling __IPYTHON.complete in the Session and parsing the
TabCompletion is implemented by calling sage.interfaces.tab_completion.completions in the Session and parsing the
output. To make sure it doesn't mess with the history, some tricks are used. (see the code)
Highlighting uses a simple list of known keywords and some regular expressions. (so no magic here)
......@@ -49,7 +49,7 @@ QString SageBackend::id() const
QString SageBackend::version() const
{
return QLatin1String("8.1, 8.2");
return QLatin1String("8.3");
}
Cantor::Session* SageBackend::createSession()
......
......@@ -61,7 +61,7 @@ void SageCompletionObject::fetchCompletions()
//cache the value of the "_" variable into __hist_tmp__, so we can restore the previous result
//after complete() was evaluated
const QString& cmd = QLatin1String("__hist_tmp__=_; __CANTOR_IPYTHON_SHELL__.complete(\"")+command()+QLatin1String("\");_=__hist_tmp__");
const QString& cmd = QLatin1String("__hist_tmp__=_; sage.interfaces.tab_completion.completions(\"")+command()+QLatin1String("\",globals());_=__hist_tmp__");
m_expression=session()->evaluateExpression(cmd, Cantor::Expression::FinishingBehavior::DoNotDelete, true);
connect(m_expression, &Cantor::Expression::gotResult, this, &SageCompletionObject::extractCompletions);
}
......@@ -91,13 +91,9 @@ void SageCompletionObject::extractCompletionsNew()
//the result looks like "['comp1', 'comp2']" parse it
//for sage version 5.7 this looks like
//('s1', ['comp1','comp2']) where s1 is the string we called complete with
QString txt=res->data().toString().trimmed();
txt=txt.mid(txt.indexOf(command())+command().length()+2).trimmed();
txt=txt.mid(1); //remove [
txt.chop(2); //remove ]
txt.chop(1); //remove ]
qDebug()<<"completion string: "<<txt;
......@@ -108,7 +104,7 @@ void SageCompletionObject::extractCompletionsNew()
{
c=c.trimmed();
c.chop(1);
completions<<c.mid(2);
completions<<c.mid(1);
}
completions << SageKeywords::instance()->keywords();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment