[education/rkward] /: Provide text hints (object tool tips) for symbols in scripts and console.

Thomas Friedrichsmeier null at kde.org
Sat Jun 18 14:17:18 BST 2022


Git commit 0b5f8469ca94eb0360ef7618022ad8ebfabb0697 by Thomas Friedrichsmeier.
Committed on 18/06/2022 at 13:16.
Pushed by tfry into branch 'master'.

Provide text hints (object tool tips) for symbols in scripts and console.

Of course this involves quite a bit of guessing, and will not work for locals, among other things.

M  +1    -0    ChangeLog
M  +2    -1    rkward/rkconsole.cpp
M  +1    -0    rkward/windows/CMakeLists.txt
M  +2    -0    rkward/windows/rkcommandeditorwindow.cpp
A  +40   -0    rkward/windows/rktexthints.cpp     [License: GPL(v2.0+)]
A  +23   -0    rkward/windows/rktexthints.h     [License: GPL(v2.0+)]

https://invent.kde.org/education/rkward/commit/0b5f8469ca94eb0360ef7618022ad8ebfabb0697

diff --git a/ChangeLog b/ChangeLog
index 0863a552..511b20b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+- Provide tooltips on symbols in scripts and R console
 - Fixed: Expresssions spanning several lines would not be shown, correctly, in "R Console"-mode script preview
 - Fix focus problems, and better efficiency for data previews (as used in data import dialogs)
 - Fixed: Excel import plugin failed to accept file name
diff --git a/rkward/rkconsole.cpp b/rkward/rkconsole.cpp
index d4701b9f..511c4670 100644
--- a/rkward/rkconsole.cpp
+++ b/rkward/rkconsole.cpp
@@ -41,10 +41,10 @@ SPDX-License-Identifier: GPL-2.0-or-later
 #include <KJobWidgets>
 #include <KJobUiDelegate>
 
-
 #include "rkward.h"
 #include "windows/rkhelpsearchwindow.h"
 #include "windows/rkcodecompletion.h"
+#include "windows/rktexthints.h"
 #include "rbackend/rkrinterface.h"
 #include "settings/rksettings.h"
 #include "settings/rksettingsmoduleconsole.h"
@@ -125,6 +125,7 @@ RKConsole::RKConsole (QWidget *parent, bool tool_window, const char *name) : RKM
 	view->installEventFilter(this);
 	auto manager = new RKCompletionManager (view, RKSettingsModuleConsole::completionSettings());  // Must be instantiated _after_ our event filter, so that it will apply its filter first
 	manager->setLinePrefixes(nprefix, iprefix);
+	new RKTextHints(view);
 
 	doc->setModified (false);
 
diff --git a/rkward/windows/CMakeLists.txt b/rkward/windows/CMakeLists.txt
index f67f8807..31f81f07 100644
--- a/rkward/windows/CMakeLists.txt
+++ b/rkward/windows/CMakeLists.txt
@@ -23,6 +23,7 @@ SET(windows_STAT_SRCS
 	rkdebugmessagewindow.cpp
 	katepluginintegration.cpp
 	rkcodecompletion.cpp
+	rktexthints.cpp
 )
 
 ADD_LIBRARY(windows STATIC ${windows_STAT_SRCS})
diff --git a/rkward/windows/rkcommandeditorwindow.cpp b/rkward/windows/rkcommandeditorwindow.cpp
index 13425c04..d6fba5d6 100644
--- a/rkward/windows/rkcommandeditorwindow.cpp
+++ b/rkward/windows/rkcommandeditorwindow.cpp
@@ -58,6 +58,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
 #include "rkworkplace.h"
 #include "katepluginintegration.h"
 #include "rkcodecompletion.h"
+#include "rktexthints.h"
 
 #include "../debug.h"
 
@@ -272,6 +273,7 @@ RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, const QUrl &_url,
 	if (use_r_highlighting || RKSettingsModuleCommandEditor::completionSettings()->completionForAllFileTypes()) {
 		if (flags & RKCommandEditorFlags::UseCodeHinting) {
 			new RKCompletionManager (m_view, RKSettingsModuleCommandEditor::completionSettings());
+			new RKTextHints(m_view);
 			//hinter = new RKFunctionArgHinter (this, m_view);
 		}
 	}
diff --git a/rkward/windows/rktexthints.cpp b/rkward/windows/rktexthints.cpp
new file mode 100644
index 00000000..aecfbf14
--- /dev/null
+++ b/rkward/windows/rktexthints.cpp
@@ -0,0 +1,40 @@
+/*
+rktexthints - This file is part of the RKWard project. Created: Sat Jun 17 2022
+SPDX-FileCopyrightText: 2022 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
+SPDX-License-Identifier: GPL-2.0-or-later
+*/
+#include "rktexthints.h"
+
+#include <KLocalizedString>
+
+#include "../misc/rkcommonfunctions.h"
+#include "../core/robjectlist.h"
+
+#include "../debug.h"
+
+RKTextHints::RKTextHints(KTextEditor::View *view) : QObject(view), KTextEditor::TextHintProvider() {
+	RK_TRACE(COMMANDEDITOR);
+	auto iface = qobject_cast<KTextEditor::TextHintInterface*>(view);
+	if (iface) {
+		iface->registerTextHintProvider(this);
+	} else {
+		RK_ASSERT(iface);
+	}
+}
+
+RKTextHints::~RKTextHints() {
+	RK_TRACE(COMMANDEDITOR);
+}
+
+QString RKTextHints::textHint(KTextEditor::View *view, const KTextEditor::Cursor &position) {
+	RK_TRACE(COMMANDEDITOR);
+	QString line = view->document()->line(position.line()) + ' ';
+	QString symbol = RKCommonFunctions::getCurrentSymbol(line, position.column());
+	auto obj = RObjectList::getObjectList()->findObject(symbol);
+	if (obj) {
+		return i18n("Symbol <i>%1</i> might refer to: ", symbol) + obj->getObjectDescription();
+	}
+	return QString();
+}
+
diff --git a/rkward/windows/rktexthints.h b/rkward/windows/rktexthints.h
new file mode 100644
index 00000000..355302b3
--- /dev/null
+++ b/rkward/windows/rktexthints.h
@@ -0,0 +1,23 @@
+/*
+rktexthints - This file is part of the RKWard project. Created: Sat Jun 17 2022
+SPDX-FileCopyrightText: 2022 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
+SPDX-License-Identifier: GPL-2.0-or-later
+*/
+#ifndef RKTEXTHINTS_H
+#define RKTEXTHINTS_H
+
+#include <ktexteditor/view.h>
+#include <ktexteditor/texthintinterface.h>
+
+/** Provides text hints for a KTextEditor::View */
+class RKTextHints : public QObject, public KTextEditor::TextHintProvider {
+	Q_OBJECT
+public:
+	RKTextHints(KTextEditor::View *view);
+	QString textHint(KTextEditor::View *view, const KTextEditor::Cursor &position) override;
+private:
+	~RKTextHints();
+};
+
+#endif


More information about the rkward-tracker mailing list