aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Haumann <[email protected]>2015-07-15 16:42:50 +0200
committerDominik Haumann <[email protected]>2015-07-15 16:42:50 +0200
commit6e9aec0e5558f4b2f3e8714e6ebcda128f7324fa (patch)
tree3be82e5f396bca3646abdfd8514a157bd7294f67
parent2660dc19fc6749dd2b9b4b99a0f677c190c446d7 (diff)
Projects plugin: rudimentary support for an rtags client
Right now, rtags needs to be starte manually based on the file compile_commands.json. For your project, run cmake with the option -DCMAKE_EXPORT_COMPILE_COMMANDS=ON or add to CMakeLists.txt set(CMAKE_EXPORT_COMPILE_COMMANDS ON) Then, run the rtags daemon somewhere through rdm &. And then go into the build folder where the compile_commands.json file is located and tpye `rc -J`. Then, open Kate with the projects plugin and you can follow the symbol under the cursor by pressing ALT+G. This is just a test for now, so expect more to come...
-rw-r--r--addons/project/CMakeLists.txt1
-rw-r--r--addons/project/kateprojectpluginview.cpp17
-rw-r--r--addons/project/kateprojectpluginview.h5
-rw-r--r--addons/project/rtags/katertagsclient.cpp217
-rw-r--r--addons/project/rtags/katertagsclient.h85
5 files changed, 324 insertions, 1 deletions
diff --git a/addons/project/CMakeLists.txt b/addons/project/CMakeLists.txt
index 83dd4a7..50e8369 100644
--- a/addons/project/CMakeLists.txt
+++ b/addons/project/CMakeLists.txt
@@ -30,6 +30,7 @@ set(kateprojectplugin_PART_SRCS
kateprojectinfoviewcodeanalysis.cpp
kateprojectinfoviewnotes.cpp
kateprojectconfigpage.cpp
+ rtags/katertagsclient.cpp
)
add_library(kateprojectplugin MODULE ${kateprojectplugin_PART_SRCS})
diff --git a/addons/project/kateprojectpluginview.cpp b/addons/project/kateprojectpluginview.cpp
index 004c519..f09ba13 100644
--- a/addons/project/kateprojectpluginview.cpp
+++ b/addons/project/kateprojectpluginview.cpp
@@ -19,6 +19,7 @@
*/
#include "kateprojectpluginview.h"
+#include "rtags/katertagsclient.h"
#include "fileutil.h"
#include <ktexteditor/editor.h>
@@ -84,6 +85,10 @@ KateProjectPluginView::KateProjectPluginView(KateProjectPlugin *plugin, KTextEdi
a = actionCollection()->addAction(KStandardAction::Forward, QStringLiteral("projects_next_project"), this, SLOT(slotProjectNext()));
actionCollection()->setDefaultShortcut(a, QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Right));
+ a = actionCollection()->addAction(QStringLiteral("projects_follow_location"), this, SLOT(slotFollowLocation()));
+ actionCollection()->setDefaultShortcut(a, QKeySequence(Qt::ALT | Qt::Key_G));
+ a->setText(i18n("Follow Location"));
+
/**
* add us to gui
*/
@@ -462,5 +467,15 @@ void KateProjectPluginView::slotProjectReload()
}
}
-#include "kateprojectpluginview.moc"
+void KateProjectPluginView::slotFollowLocation()
+{
+ auto view = KTextEditor::Editor::instance()->application()->activeMainWindow()->activeView();
+ if (!view) {
+ return;
+ }
+
+ KateRtagsClient client;
+ client.followLocation(view->document(), view->cursorPosition());
+}
+#include "kateprojectpluginview.moc"
diff --git a/addons/project/kateprojectpluginview.h b/addons/project/kateprojectpluginview.h
index 60e7fe5..c8f2e55 100644
--- a/addons/project/kateprojectpluginview.h
+++ b/addons/project/kateprojectpluginview.h
@@ -137,6 +137,11 @@ private Q_SLOTS:
*/
void slotProjectReload();
+ /**
+ * Follow location.
+ */
+ void slotFollowLocation();
+
Q_SIGNALS:
/**
* Emitted if projectFileName changed.
diff --git a/addons/project/rtags/katertagsclient.cpp b/addons/project/rtags/katertagsclient.cpp
new file mode 100644
index 0000000..5a74c88
--- /dev/null
+++ b/addons/project/rtags/katertagsclient.cpp
@@ -0,0 +1,217 @@
+/* This file is part of the Kate project.
+ *
+ * Copyright (C) 2012 Christoph Cullmann <[email protected]>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "katertagsclient.h"
+
+#include <QProcess>
+#include <QDir>
+#include <QRegularExpression>
+#include <QStandardPaths>
+
+#include <KTextEditor/Editor>
+#include <KTextEditor/Application>
+#include <KTextEditor/MainWindow>
+#include <KTextEditor/View>
+
+KateRtagsClient::KateRtagsClient()
+ : QObject()
+{
+}
+
+KateRtagsClient::~KateRtagsClient()
+{
+}
+
+bool KateRtagsClient::rtagsAvailable() const
+{
+ return (!QStandardPaths::findExecutable(QStringLiteral("rc")).isEmpty())
+ && (!QStandardPaths::findExecutable(QStringLiteral("rdm")).isEmpty());
+}
+
+bool KateRtagsClient::rtagsDaemonRunning() const
+{
+ // Try to run 'rc --project'
+ QProcess rc;
+ rc.start(QStringLiteral("rc"), QStringList() << QStringLiteral("--project"));
+ // If rc is not installed, return false.
+ if (!rc.waitForStarted()) {
+ return false;
+ }
+
+ // wait for done
+ if (!rc.waitForFinished()) {
+ return false;
+ }
+
+ // if rdm is not running, the exit code is non-zero.
+ return (rc.exitStatus() == QProcess::NormalExit) && (rc.exitCode() == 0);
+}
+
+bool KateRtagsClient::isIndexing() const
+{
+ // Try to run 'rc --is-indexing'
+ QProcess rc;
+ rc.start(QStringLiteral("rc"), QStringList() << QStringLiteral("--is-indexing"));
+ // If rc is not installed, return false.
+ if (!rc.waitForStarted()) {
+ return false;
+ }
+
+ // wait for done
+ if (!rc.waitForFinished()) {
+ return false;
+ }
+
+ // get stdout
+ const QString output = QString::fromLocal8Bit(rc.readAllStandardOutput());
+
+ // if indexing, "1" is returned. If not indexing, "0" is returned.
+ return output.contains(QLatin1Char('1'));
+}
+
+QStringList KateRtagsClient::indexedProjects() const
+{
+ // Try to run 'rc --project'
+ QProcess rc;
+ rc.start(QStringLiteral("rc"), QStringList() << QStringLiteral("--project"));
+ // If rc is not installed, return false.
+ if (!rc.waitForStarted()) {
+ return QStringList();
+ }
+
+ // wait for done
+ if (!rc.waitForFinished()) {
+ return QStringList();
+ }
+
+ // get stdout
+ const QString output = QString::fromLocal8Bit(rc.readAllStandardOutput());
+
+ // return projects as string list
+ return output.split(QRegularExpression(QStringLiteral("[\n\r]")), QString::SkipEmptyParts);
+}
+
+void KateRtagsClient::setCurrentFile(KTextEditor::Document * document)
+{
+ QUrl url = document->url();
+ if (!url.isValid() || !url.isLocalFile()) {
+ return;
+ }
+
+ QString file = url.toLocalFile();
+
+ // run 'rc --current-file <file>'
+ QProcess::startDetached(QStringLiteral("rc"), QStringList() << QStringLiteral("--current-file") << file);
+}
+
+void KateRtagsClient::followLocation(KTextEditor::Document * document, const KTextEditor::Cursor & cursor)
+{
+ QUrl url = document->url();
+ if (!url.isValid() || !url.isLocalFile()) {
+ return;
+ }
+
+ const QString location = document->url().toLocalFile() + QStringLiteral(":%1:%2").arg(cursor.line() + 1).arg(cursor.column() + 1);
+ qDebug() << "rc command:" << location;
+
+ // run 'rc --follow-location <file>:line:column'
+ QProcess rc;
+ rc.start(QStringLiteral("rc"), QStringList() << QStringLiteral("--follow-location") << location);
+ // If rc is not installed, return false.
+ if (!rc.waitForStarted()) {
+ return;
+ }
+
+ // wait for done
+ if (!rc.waitForFinished()) {
+ return;
+ }
+
+ rc.closeWriteChannel();
+ const QString output = QString::fromLocal8Bit(rc.readAllStandardOutput());
+ qDebug() << "output" << output;
+ QStringList list = output.split(QLatin1Char(':'), QString::SkipEmptyParts);
+ qDebug() << list;
+ if (list.size() < 3) {
+ return;
+ }
+
+ // output is: file:line:column
+ const QString file = list[0];
+ const int line = list[1].toInt() - 1;
+ const int column = list[2].toInt() - 1;
+
+ KTextEditor::View * view = KTextEditor::Editor::instance()->application()->activeMainWindow()->openUrl(QUrl::fromLocalFile(file));
+ if (!view) {
+ return;
+ }
+
+ view->setCursorPosition(KTextEditor::Cursor(line, column));
+}
+
+#if 0
+--> Get uses of symbol
[email protected]:rtags :-) (master) $ rc --cursorinfo-include-references --cursor-info /home/dh/kde/kf5/src/kde/applications/kate/addons/project/rtags/katertagsclient.cpp:87:15
+/home/dh/kde/kf5/src/kde/applications/kate/addons/project/rtags/katertagsclient.cpp:87:14: QProcess rc;
+SymbolName: QProcess rc
+Kind: VarDecl
+Type: Record
+SymbolLength: 2
+Range: 87:5-87:16
+Definition
+References:
+ /home/dh/kde/kf5/src/kde/applications/kate/addons/project/rtags/katertagsclient.cpp:88:5: rc.start(QStringLiteral("rc"), QStringList() << QStringLiteral("--project"));
+ /home/dh/kde/kf5/src/kde/applications/kate/addons/project/rtags/katertagsclient.cpp:90:10: if (!rc.waitForStarted()) {
+ /home/dh/kde/kf5/src/kde/applications/kate/addons/project/rtags/katertagsclient.cpp:95:10: if (!rc.waitForFinished()) {
+ /home/dh/kde/kf5/src/kde/applications/kate/addons/project/rtags/katertagsclient.cpp:100:51: const QString output = QString::fromLocal8Bit(rc.readAllStandardOutput());
+
+
+
+
+
+
[email protected]:project :-) (master) $ rc --all-references --references /home/dh/kde/kf5/src/kde/applications/kate/addons/project/kateproject.cpp:233:23
+/home/dh/kde/kf5/src/kde/applications/kate/addons/project/kateproject.h:171:10: void saveNotesDocument();
+/home/dh/kde/kf5/src/kde/applications/kate/addons/project/kateproject.cpp:47:5: saveNotesDocument();
+/home/dh/kde/kf5/src/kde/applications/kate/addons/project/kateproject.cpp:233:19: void KateProject::saveNotesDocument()
+
+
+
+
+
+listtet alle Vorkommen eines Symbols
+rc --all-references --references-name KateDocManager
+
+
+
+listed alle Funktionsaufrufe
[email protected]:src :-) (master) $ rc --all-references --references /home/dh/kde/kf5/src/kde/applications/kate/kate/src/katedocmanager.cpp:89:46
+/home/dh/kde/kf5/src/kde/applications/kate/kate/src/katedocmanager.h:66:28: KTextEditor::Document *createDoc(const KateDocumentInfo &docInfo = KateDocumentInfo());
+/home/dh/kde/kf5/src/kde/applications/kate/kate/src/kateviewspace.cpp:517:70: KTextEditor::Document *doc = KateApp::self()->documentManager()->createDoc();
+/home/dh/kde/kf5/src/kde/applications/kate/kate/src/katemainwindow.cpp:698:49: KateApp::self()->documentManager()->createDoc();
+/home/dh/kde/kf5/src/kde/applications/kate/kate/src/katedocmanager.cpp:62:5: createDoc();
+/home/dh/kde/kf5/src/kde/applications/kate/kate/src/katedocmanager.cpp:171:15: doc = createDoc(docInfo);
+/home/dh/kde/kf5/src/kde/applications/kate/kate/src/katedocmanager.cpp:259:9: createDoc();
+/home/dh/kde/kf5/src/kde/applications/kate/kate/src/katedocmanager.cpp:453:19: doc = createDoc();
+/home/dh/kde/kf5/src/kde/applications/kate/kate/src/kateviewmanager.cpp:442:51: doc = KateApp::self()->documentManager()->createDoc();
+/home/dh/kde/kf5/src/kde/applications/kate/kate/src/katedocmanager.cpp:89:40: KTextEditor::Document *KateDocManager::createDoc(const KateDocumentInfo &docInfo)
+
+
+#endif
diff --git a/addons/project/rtags/katertagsclient.h b/addons/project/rtags/katertagsclient.h
new file mode 100644
index 0000000..de71f4e
--- /dev/null
+++ b/addons/project/rtags/katertagsclient.h
@@ -0,0 +1,85 @@
+/* This file is part of the Kate project.
+ *
+ * Copyright (C) 2015 Dominik Haumann <[email protected]>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef KATE_PROJECT_RTAGS_CLIENT_H
+#define KATE_PROJECT_RTAGS_CLIENT_H
+
+#include <QObject>
+#include <QStringList>
+
+#include <KTextEditor/Document>
+
+/**
+ * Class to communicate with the rtags server rdm.
+ *
+ * This class is more or less a wrapper around the 'rc' tool that is part
+ * of the rtags daemon 'rdm'.
+ */
+class KateRtagsClient : public QObject
+{
+public:
+ /**
+ * Construct an rtags client.
+ */
+ KateRtagsClient();
+
+ /**
+ * deconstruct project
+ */
+ ~KateRtagsClient();
+
+//
+// diagnostics
+//
+public:
+ /**
+ * Check if the rtags tools 'rc' and 'rdm' are installed.
+ */
+ bool rtagsAvailable() const;
+
+ /**
+ * Check if the rtags daemon is running.
+ */
+ bool rtagsDaemonRunning() const;
+
+ /**
+ * Check whether the rtags daemon 'rdm' is currently indexing.
+ */
+ bool isIndexing() const;
+
+ /**
+ * Get a list of indexed projects.
+ */
+ QStringList indexedProjects() const;
+
+ void followLocation(KTextEditor::Document * document, const KTextEditor::Cursor & cursor);
+
+//
+//
+//
+public Q_SLOTS:
+ /**
+ * Tell rtags the current file, giving it a better chance of
+ * quickly following the right project.
+ */
+ void setCurrentFile(KTextEditor::Document * document);
+};
+
+#endif