diff --git a/src/backends/julia/CMakeLists.txt b/src/backends/julia/CMakeLists.txt --- a/src/backends/julia/CMakeLists.txt +++ b/src/backends/julia/CMakeLists.txt @@ -8,6 +8,7 @@ juliakeywords.cpp juliahighlighter.cpp juliaextensions.cpp + juliacompletionobject.cpp ) kconfig_add_kcfg_files(JuliaBackend_SRCS settings.kcfgc) diff --git a/src/backends/julia/juliabackend.cpp b/src/backends/julia/juliabackend.cpp --- a/src/backends/julia/juliabackend.cpp +++ b/src/backends/julia/juliabackend.cpp @@ -51,7 +51,8 @@ Cantor::Backend::Capabilities JuliaBackend::capabilities() const { return Cantor::Backend::SyntaxHighlighting | - Cantor::Backend::VariableManagement; + Cantor::Backend::VariableManagement| + Cantor::Backend::Completion; } QString JuliaBackend::description() const diff --git a/src/backends/julia/juliacompletionobject.h b/src/backends/julia/juliacompletionobject.h new file mode 100644 --- /dev/null +++ b/src/backends/julia/juliacompletionobject.h @@ -0,0 +1,39 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * --- + * Copyright (C) 2016 Ivan Lakhtanov + */ + +#pragma once + +#include "completionobject.h" + +class JuliaSession; + +class JuliaCompletionObject : public Cantor::CompletionObject +{ +public: + JuliaCompletionObject(const QString &cmd, int index, JuliaSession *session); + ~JuliaCompletionObject(); + +protected: + virtual bool mayIdentifierContain(QChar c) const; + virtual bool mayIdentifierBeginWith(QChar c) const; + +protected Q_SLOTS: + void fetchCompletions(); +}; diff --git a/src/backends/julia/juliacompletionobject.cpp b/src/backends/julia/juliacompletionobject.cpp new file mode 100644 --- /dev/null +++ b/src/backends/julia/juliacompletionobject.cpp @@ -0,0 +1,68 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * --- + * Copyright (C) 2016 Ivan Lakhtanov + */ + +#include + +#include "juliacompletionobject.h" + +#include "juliasession.h" +#include "juliakeywords.h" + +JuliaCompletionObject::JuliaCompletionObject( + const QString &command, int index, JuliaSession *session) + : Cantor::CompletionObject(session) +{ + setLine(command, index); +} + +JuliaCompletionObject::~JuliaCompletionObject() +{ +} + +void JuliaCompletionObject::fetchCompletions() +{ + auto julia_session = dynamic_cast(session()); + julia_session->runJuliaCommand( + QString::fromLatin1( + "join(" + "Base.REPL.REPLCompletions.completions(\"%1\", %2)[1]," + "\"__CANTOR_DELIM__\")" + ).arg(command()).arg(command().size()) + ); + + auto result = julia_session->getOutput(); + result.chop(1); + result.remove(0, 1); + setCompletions(result.split(QLatin1String("__CANTOR_DELIM__"))); + + emit fetchingDone(); +} + +bool JuliaCompletionObject::mayIdentifierContain(QChar c) const +{ + return c.isLetter() || c.isDigit() || c == QLatin1Char('_') || + c == QLatin1Char('%') || c == QLatin1Char('$') || c == QLatin1Char('.'); +} + +bool JuliaCompletionObject::mayIdentifierBeginWith(QChar c) const +{ + return c.isLetter() || c == QLatin1Char('_') || c == QLatin1Char('%') || + c == QLatin1Char('$'); +} diff --git a/src/backends/julia/juliasession.h b/src/backends/julia/juliasession.h --- a/src/backends/julia/juliasession.h +++ b/src/backends/julia/juliasession.h @@ -24,6 +24,7 @@ #include "session.h" class JuliaExpression; +class JuliaCompletionObject; class KProcess; class QDBusInterface; namespace Cantor { @@ -71,6 +72,7 @@ QMap m_whos_cache; friend JuliaExpression; + friend JuliaCompletionObject; void runExpression(JuliaExpression *expression); diff --git a/src/backends/julia/juliasession.cpp b/src/backends/julia/juliasession.cpp --- a/src/backends/julia/juliasession.cpp +++ b/src/backends/julia/juliasession.cpp @@ -33,6 +33,7 @@ #include "juliakeywords.h" #include "juliaextensions.h" #include "juliabackend.h" +#include "juliacompletionobject.h" JuliaSession::JuliaSession(Cantor::Backend *backend) : Session(backend) @@ -143,9 +144,7 @@ const QString &command, int index) { - Q_UNUSED(command); - Q_UNUSED(index); - return nullptr; + return new JuliaCompletionObject(command, index, this); } QSyntaxHighlighter *JuliaSession::syntaxHighlighter(QObject *parent)