[rkward-cvs] SF.net SVN: rkward:[4007] trunk/rkward/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Fri Oct 28 14:10:59 UTC 2011
Revision: 4007
http://rkward.svn.sourceforge.net/rkward/?rev=4007&view=rev
Author: tfry
Date: 2011-10-28 14:10:59 +0000 (Fri, 28 Oct 2011)
Log Message:
-----------
Add indication of current source line to callstack viewer window (if source line is known)
Modified Paths:
--------------
trunk/rkward/rkward/agents/rkdebughandler.cpp
trunk/rkward/rkward/agents/rkdebughandler.h
trunk/rkward/rkward/rbackend/rkrbackend.cpp
trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_debugger.R
trunk/rkward/rkward/windows/rkcallstackviewer.cpp
trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp
trunk/rkward/rkward/windows/rkcommandeditorwindow.h
Modified: trunk/rkward/rkward/agents/rkdebughandler.cpp
===================================================================
--- trunk/rkward/rkward/agents/rkdebughandler.cpp 2011-10-28 13:10:13 UTC (rev 4006)
+++ trunk/rkward/rkward/agents/rkdebughandler.cpp 2011-10-28 14:10:59 UTC (rev 4007)
@@ -49,6 +49,9 @@
_environments = request->params["envs"].toStringList ();
_locals = request->params["locals"].toStringList ();
_prompt = request->params["prompt"].toString ();
+ QStringList dummy = request->params["relsrclines"].toStringList ();
+ _rel_src_lines.clear ();
+ for (int i = 0; i < dummy.size (); ++i) _rel_src_lines.append (dummy.at (i).toInt ());
_state = InDebugPrompt;
newDebugState ();
Modified: trunk/rkward/rkward/agents/rkdebughandler.h
===================================================================
--- trunk/rkward/rkward/agents/rkdebughandler.h 2011-10-28 13:10:13 UTC (rev 4006)
+++ trunk/rkward/rkward/agents/rkdebughandler.h 2011-10-28 14:10:59 UTC (rev 4007)
@@ -50,6 +50,7 @@
QStringList functions () const { return _functions; };
QStringList environments () const { return _environments; };
QStringList locals () const { return _locals; };
+ QList<int> relativeSourceLines () const { return _rel_src_lines; };
QString debugPrompt () const { return _prompt; };
RCommand *command () const { return _command; };
signals:
@@ -57,6 +58,7 @@
private:
RCommand *_command;
QStringList _calls, _functions, _environments, _locals;
+ QList<int> _rel_src_lines;
QString _prompt, _output_context;
DebugState _state;
RBackendRequest *_request;
Modified: trunk/rkward/rkward/rbackend/rkrbackend.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkrbackend.cpp 2011-10-28 13:10:13 UTC (rev 4006)
+++ trunk/rkward/rkward/rbackend/rkrbackend.cpp 2011-10-28 14:10:59 UTC (rev 4007)
@@ -392,6 +392,7 @@
params["funs"] = QVariant (dummy_data.at (1)->stringVector ());
params["envs"] = QVariant (dummy_data.at (2)->stringVector ());
params["locals"] = QVariant (dummy_data.at (3)->stringVector ());
+ params["relsrclines"] = QVariant (dummy_data.at (4)->stringVector ()); // hacky: passing a QList<int> is not supported by QVariant
} else {
RK_ASSERT (false);
}
Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_debugger.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_debugger.R 2011-10-28 13:10:13 UTC (rev 4006)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_debugger.R 2011-10-28 14:10:59 UTC (rev 4007)
@@ -6,6 +6,7 @@
funs <- character (0)
envs <- character (0)
locals <- character (0)
+ relsrclines <- integer (0)
if (nframes > 0) {
for (i in 1:nframes) {
@@ -13,7 +14,23 @@
funs[i] <- as.character (try (paste (deparse (sys.function (i), control="all"), collapse="\n"), silent=TRUE))
envs[i] <- as.character (try (capture.output (print (environment (sys.function (i)))), silent=TRUE))
locals[i] <- as.character (try (paste (ls (sys.frame (i), all.names=TRUE), collapse="\n"), silent=TRUE))
+ relsrclines[i] <- as.character (try (rk.relative.src.line (sys.call (i+1), sys.function (i)), silent=TRUE))
}
}
- list ("calls"=calls, "functions"=funs, "environments"=envs, "locals"=locals)
+ list ("calls"=calls, "functions"=funs, "environments"=envs, "locals"=locals, "relsrclines"=relsrclines)
}
+
+# get relative source location
+# NOTE: this requires R >= 2.13.0
+rk.relative.src.line <- function (inner, outer) {
+ if (!inherits (inner, "srcref")) inner <- getSrcref (inner)
+ if (!inherits (outer, "srcref")) outer <- getSrcref (outer)
+ if (is.null (inner) || is.null (outer)) return (NA)
+ if (getSrcFilename (inner) != getSrcFilename (outer)) return (NA)
+ outer_first <- getSrcLocation (outer, "line")
+ outer_last <- getSrcLocation (outer, "line", first=FALSE)
+ inner_first <- getSrcLocation (inner, "line")
+ inner_last <- getSrcLocation (inner, "line", first=FALSE)
+ if ((inner_first < outer_first) || (inner_last > outer_last)) return (NA)
+ return (inner_first - outer_first + 1)
+}
Modified: trunk/rkward/rkward/windows/rkcallstackviewer.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkcallstackviewer.cpp 2011-10-28 13:10:13 UTC (rev 4006)
+++ trunk/rkward/rkward/windows/rkcallstackviewer.cpp 2011-10-28 14:10:59 UTC (rev 4007)
@@ -146,6 +146,12 @@
Qt::escape (RKDebugHandler::instance ()->environments ().value (frame_number)),
Qt::escape (RKDebugHandler::instance ()->locals ().value (frame_number).split ('\n').join (", "))));
frame_source->setText (RKDebugHandler::instance ()->functions ().value (frame_number));
+ int line = RKDebugHandler::instance ()->relativeSourceLines ().value (frame_number, 0);
+ frame_source->clearLineHighlights ();
+ if (line > 0) frame_source->highlightLine (line -1);
+ else {
+ // TODO: some clever heuristics
+ }
}
#include "rkcallstackviewer.moc"
Modified: trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp 2011-10-28 13:10:13 UTC (rev 4006)
+++ trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp 2011-10-28 14:10:59 UTC (rev 4007)
@@ -22,6 +22,7 @@
#include <ktexteditor/sessionconfiginterface.h>
#include <ktexteditor/editorchooser.h>
#include <ktexteditor/modificationinterface.h>
+#include <ktexteditor/markinterface.h>
#include <qlayout.h>
#include <qapplication.h>
@@ -489,6 +490,32 @@
if (!old_rw) m_doc->setReadWrite (false);
}
+void RKCommandEditorWindow::highlightLine (int linenum) {
+ RK_TRACE (COMMANDEDITOR);
+
+ KTextEditor::MarkInterface *markiface = qobject_cast<KTextEditor::MarkInterface*> (m_doc);
+ if (!markiface) {
+ RK_ASSERT (markiface);
+ return;
+ }
+ bool old_rw = m_doc->isReadWrite ();
+ if (!old_rw) m_doc->setReadWrite (true);
+ markiface->addMark (linenum, KTextEditor::MarkInterface::BreakpointActive);
+ if (!old_rw) m_doc->setReadWrite (false);
+}
+
+void RKCommandEditorWindow::clearLineHighlights() {
+ KTextEditor::MarkInterface *markiface = qobject_cast<KTextEditor::MarkInterface*> (m_doc);
+ if (!markiface) {
+ RK_ASSERT (markiface);
+ return;
+ }
+ bool old_rw = m_doc->isReadWrite ();
+ if (!old_rw) m_doc->setReadWrite (true);
+ markiface->clearMarks ();
+ if (!old_rw) m_doc->setReadWrite (false);
+}
+
void RKCommandEditorWindow::updateCaption (KTextEditor::Document*) {
RK_TRACE (COMMANDEDITOR);
QString name = url ().fileName ();
Modified: trunk/rkward/rkward/windows/rkcommandeditorwindow.h
===================================================================
--- trunk/rkward/rkward/windows/rkcommandeditorwindow.h 2011-10-28 13:10:13 UTC (rev 4006)
+++ trunk/rkward/rkward/windows/rkcommandeditorwindow.h 2011-10-28 14:10:59 UTC (rev 4007)
@@ -188,6 +188,9 @@
QString provideContext (int line_rev);
QString currentCompletionWord () const;
+
+ void highlightLine (int linenum);
+ void clearLineHighlights ();
public slots:
/** update Tab caption according to the current url. Display the filename-component of the URL, or - if not available - a more elaborate description of the url. Also appends a "[modified]" if appropriate */
void updateCaption (KTextEditor::Document* = 0);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the rkward-tracker
mailing list