aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Lakhtanov <ivan.lakhtanov@gmail.com>2016-08-20 21:58:58 (GMT)
committerIvan Lakhtanov <ivan.lakhtanov@gmail.com>2016-08-24 18:44:30 (GMT)
commitfacd869bb88e933f50d84e6915fb1df16a7b77c3 (patch)
treeff1383a2ab73af682e11998ae1e512a393604928
parentf774eb096362755bfafda4f2f1947f70474ea6b7 (diff)
Implemented code completion
* Using Base.REPL completion method capable of giving intelegent completions Differential Revision: https://phabricator.kde.org/D2458
-rw-r--r--src/backends/julia/CMakeLists.txt1
-rw-r--r--src/backends/julia/juliabackend.cpp3
-rw-r--r--src/backends/julia/juliacompletionobject.cpp66
-rw-r--r--src/backends/julia/juliacompletionobject.h39
-rw-r--r--src/backends/julia/juliasession.cpp5
-rw-r--r--src/backends/julia/juliasession.h2
6 files changed, 112 insertions, 4 deletions
diff --git a/src/backends/julia/CMakeLists.txt b/src/backends/julia/CMakeLists.txt
index f90fb9f..2403d74 100644
--- a/src/backends/julia/CMakeLists.txt
+++ b/src/backends/julia/CMakeLists.txt
@@ -8,6 +8,7 @@ set(JuliaBackend_SRCS
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
index 12da679..1e2f8d0 100644
--- a/src/backends/julia/juliabackend.cpp
+++ b/src/backends/julia/juliabackend.cpp
@@ -51,7 +51,8 @@ Cantor::Session *JuliaBackend::createSession()
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.cpp b/src/backends/julia/juliacompletionobject.cpp
new file mode 100644
index 0000000..4f4305a
--- /dev/null
+++ b/src/backends/julia/juliacompletionobject.cpp
@@ -0,0 +1,66 @@
+/*
+ * 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 <ivan.lakhtanov@gmail.com>
+ */
+
+#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<JuliaSession *>(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/juliacompletionobject.h b/src/backends/julia/juliacompletionobject.h
new file mode 100644
index 0000000..0a3ec6c
--- /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 <ivan.lakhtanov@gmail.com>
+ */
+
+#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/juliasession.cpp b/src/backends/julia/juliasession.cpp
index 07ca7de..2a5e521 100644
--- 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 @@ Cantor::CompletionObject *JuliaSession::completionFor(
const QString &command,
int index)
{
- Q_UNUSED(command);
- Q_UNUSED(index);
- return nullptr;
+ return new JuliaCompletionObject(command, index, this);
}
QSyntaxHighlighter *JuliaSession::syntaxHighlighter(QObject *parent)
diff --git a/src/backends/julia/juliasession.h b/src/backends/julia/juliasession.h
index eee89f7..8387d98 100644
--- 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 @@ private:
QMap<QString, QString> m_whos_cache;
friend JuliaExpression;
+ friend JuliaCompletionObject;
void runExpression(JuliaExpression *expression);