From 82268eb77c367981c77bbf34c3278ed81f9757db Mon Sep 17 00:00:00 2001 From: hjk Date: Sat, 15 Nov 2014 13:33:40 +0100 Subject: Debugger: Use line information to find matching scopes for tooltips More robust to variations in tool chains than function names. (e.g. GDB reports 'foo' and LLDB 'foo()') Change-Id: I1e5a3273b571658b4dd4200c9b3a0e9542a16015 Reviewed-by: hjk --- src/plugins/debugger/sourceutils.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/plugins/debugger/sourceutils.cpp') diff --git a/src/plugins/debugger/sourceutils.cpp b/src/plugins/debugger/sourceutils.cpp index d3bf19ff6d..eec4b595cf 100644 --- a/src/plugins/debugger/sourceutils.cpp +++ b/src/plugins/debugger/sourceutils.cpp @@ -269,11 +269,7 @@ bool isCppEditor(TextEditorWidget *editorWidget) QString cppFunctionAt(const QString &fileName, int line, int column) { - CppModelManager *modelManager = CppModelManager::instance(); - if (!modelManager) - return QString(); - - const Snapshot snapshot = modelManager->snapshot(); + const Snapshot snapshot = CppModelManager::instance()->snapshot(); if (const Document::Ptr document = snapshot.document(fileName)) return document->functionAt(line, column); @@ -283,7 +279,8 @@ QString cppFunctionAt(const QString &fileName, int line, int column) // Return the Cpp expression, and, if desired, the function QString cppExpressionAt(TextEditorWidget *editorWidget, int pos, - int *line, int *column, QString *function /* = 0 */) + int *line, int *column, QString *function, + int *scopeFromLine, int *scopeToLine) { *line = *column = 0; if (function) @@ -291,8 +288,7 @@ QString cppExpressionAt(TextEditorWidget *editorWidget, int pos, QTextCursor tc = editorWidget->textCursor(); QString expr = tc.selectedText(); - CppModelManager *modelManager = CppModelManager::instance(); - if (expr.isEmpty() && modelManager) { + if (expr.isEmpty()) { tc.setPosition(pos); const QChar ch = editorWidget->characterAt(pos); if (ch.isLetterOrNumber() || ch == QLatin1Char('_')) @@ -308,8 +304,15 @@ QString cppExpressionAt(TextEditorWidget *editorWidget, int pos, *line = tc.blockNumber(); } - if (function && !expr.isEmpty()) - *function = cppFunctionAt(editorWidget->textDocument()->filePath(), *line, *column); + if (!expr.isEmpty()) { + QString fileName = editorWidget->textDocument()->filePath(); + const Snapshot snapshot = CppModelManager::instance()->snapshot(); + if (const Document::Ptr document = snapshot.document(fileName)) { + QString func = document->functionAt(*line, *column, scopeFromLine, scopeToLine); + if (function) + *function = func; + } + } return expr; } -- cgit v1.2.1