Commit 20e36cc3 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

tooltip for macro definitions.

parent 4a552ead
...@@ -146,9 +146,9 @@ void Document::appendMacro(const Macro &macro) ...@@ -146,9 +146,9 @@ void Document::appendMacro(const Macro &macro)
_definedMacros.append(macro); _definedMacros.append(macro);
} }
void Document::addMacroUse(unsigned offset, unsigned length) void Document::addMacroUse(const Macro &macro, unsigned offset, unsigned length)
{ {
_macroUses.append(Block(offset, offset + length)); _macroUses.append(MacroUse(macro, offset, offset + length));
} }
TranslationUnit *Document::translationUnit() const TranslationUnit *Document::translationUnit() const
......
...@@ -68,8 +68,7 @@ public: ...@@ -68,8 +68,7 @@ public:
void addIncludeFile(const QString &fileName); void addIncludeFile(const QString &fileName);
void appendMacro(const Macro &macro); void appendMacro(const Macro &macro);
void addMacroUse(const Macro &macro, unsigned offset, unsigned length);
void addMacroUse(unsigned offset, unsigned length);
Control *control() const; Control *control() const;
TranslationUnit *translationUnit() const; TranslationUnit *translationUnit() const;
...@@ -177,12 +176,30 @@ public: ...@@ -177,12 +176,30 @@ public:
inline unsigned end() const inline unsigned end() const
{ return _end; } { return _end; }
bool contains(unsigned pos) const
{ return pos >= _begin && pos < _end; }
};
class MacroUse: public Block {
Macro _macro;
public:
inline MacroUse(const Macro &macro,
unsigned begin = 0,
unsigned end = 0)
: Block(begin, end),
_macro(macro)
{ }
const Macro &macro() const
{ return _macro; }
}; };
QList<Block> skippedBlocks() const QList<Block> skippedBlocks() const
{ return _skippedBlocks; } { return _skippedBlocks; }
QList<Block> macroUses() const QList<MacroUse> macroUses() const
{ return _macroUses; } { return _macroUses; }
private: private:
...@@ -197,7 +214,7 @@ private: ...@@ -197,7 +214,7 @@ private:
QList<DiagnosticMessage> _diagnosticMessages; QList<DiagnosticMessage> _diagnosticMessages;
QList<Macro> _definedMacros; QList<Macro> _definedMacros;
QList<Block> _skippedBlocks; QList<Block> _skippedBlocks;
QList<Block> _macroUses; QList<MacroUse> _macroUses;
}; };
} // end of namespace CPlusPlus } // end of namespace CPlusPlus
......
...@@ -604,28 +604,29 @@ void pp::operator()(const QByteArray &source, QByteArray *result) ...@@ -604,28 +604,29 @@ void pp::operator()(const QByteArray &source, QByteArray *result)
m->definition.constEnd(), m->definition.constEnd(),
result); result);
m->hidden = false;
if (client) if (client)
client->stopExpandingMacro(_dot->offset, *m); client->stopExpandingMacro(_dot->offset, *m);
m->hidden = false;
continue; continue;
} else { } else {
QByteArray tmp; QByteArray tmp;
m->hidden = true;
if (client) if (client)
client->startExpandingMacro(identifierToken->offset, client->startExpandingMacro(identifierToken->offset,
*m, spell); *m, spell);
m->hidden = true;
expand(m->definition.constBegin(), expand(m->definition.constBegin(),
m->definition.constEnd(), m->definition.constEnd(),
&tmp); &tmp);
m->hidden = false;
if (client) if (client)
client->stopExpandingMacro(_dot->offset, *m); client->stopExpandingMacro(_dot->offset, *m);
m->hidden = false;
m = 0; // reset the active the macro m = 0; // reset the active the macro
pushState(createStateFromSource(tmp)); pushState(createStateFromSource(tmp));
......
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
#include <QByteArray> #include <QByteArray>
#include <QVector> #include <QVector>
#include <QString>
namespace CPlusPlus { namespace CPlusPlus {
...@@ -89,6 +90,33 @@ public: ...@@ -89,6 +90,33 @@ public:
hashcode(0), hashcode(0),
state(0) state(0)
{ } { }
QString toString() const
{
QString text;
if (hidden)
text += QLatin1String("#undef ");
else
text += QLatin1String("#define ");
text += QString::fromUtf8(name.constData(), name.size());
if (function_like) {
text += QLatin1Char('(');
bool first = true;
foreach (const QByteArray formal, formals) {
if (! first)
text += QLatin1String(", ");
else
first = false;
text += QString::fromUtf8(formal.constData(), formal.size());
}
if (variadics)
text += QLatin1String("...");
text += QLatin1Char(' ');
}
text += QLatin1Char(' ');
text += QString::fromUtf8(definition.constData(), definition.size());
return text;
}
}; };
} // namespace CPlusPlus } // namespace CPlusPlus
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/uniqueidmanager.h> #include <coreplugin/uniqueidmanager.h>
#include <texteditor/itexteditor.h> #include <texteditor/itexteditor.h>
#include <texteditor/basetexteditor.h>
#include <debugger/debuggerconstants.h> #include <debugger/debuggerconstants.h>
#include <CoreTypes.h> #include <CoreTypes.h>
...@@ -51,13 +52,13 @@ ...@@ -51,13 +52,13 @@
#include <cplusplus/TypeOfExpression.h> #include <cplusplus/TypeOfExpression.h>
#include <QtGui/QToolTip> #include <QtGui/QToolTip>
#include <QtGui/QPlainTextEdit>
#include <QtGui/QTextCursor> #include <QtGui/QTextCursor>
#include <QtGui/QTextBlock> #include <QtGui/QTextBlock>
#include <QtHelp/QHelpEngineCore> #include <QtHelp/QHelpEngineCore>
#include <QtCore/QtCore> #include <QtCore/QtCore>
using namespace CppTools::Internal; using namespace CppTools::Internal;
using namespace CPlusPlus;
CppHoverHandler::CppHoverHandler(CppModelManager *manager, QObject *parent) CppHoverHandler::CppHoverHandler(CppModelManager *manager, QObject *parent)
: QObject(parent), m_manager(manager), m_helpEngineNeedsSetup(false) : QObject(parent), m_manager(manager), m_helpEngineNeedsSetup(false)
...@@ -104,11 +105,9 @@ void CppHoverHandler::showToolTip(TextEditor::ITextEditor *editor, const QPoint ...@@ -104,11 +105,9 @@ void CppHoverHandler::showToolTip(TextEditor::ITextEditor *editor, const QPoint
} }
} }
static QString buildHelpId(const CPlusPlus::FullySpecifiedType &type, static QString buildHelpId(const FullySpecifiedType &type,
const CPlusPlus::Symbol *symbol) const Symbol *symbol)
{ {
using namespace CPlusPlus;
Name *name = 0; Name *name = 0;
Scope *scope = 0; Scope *scope = 0;
...@@ -156,12 +155,10 @@ static QString buildHelpId(const CPlusPlus::FullySpecifiedType &type, ...@@ -156,12 +155,10 @@ static QString buildHelpId(const CPlusPlus::FullySpecifiedType &type,
void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, int pos) void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, int pos)
{ {
using namespace CPlusPlus;
m_helpId.clear(); m_helpId.clear();
m_toolTip.clear(); m_toolTip.clear();
QPlainTextEdit *edit = qobject_cast<QPlainTextEdit *>(editor->widget()); TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor *>(editor->widget());
if (!edit) if (!edit)
return; return;
...@@ -169,8 +166,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in ...@@ -169,8 +166,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
tc.setPosition(pos); tc.setPosition(pos);
const int lineNumber = tc.block().blockNumber() + 1; const int lineNumber = tc.block().blockNumber() + 1;
const QString fileName = editor->file()->fileName();
QString fileName = editor->file()->fileName();
Document::Ptr doc = m_manager->document(fileName); Document::Ptr doc = m_manager->document(fileName);
if (doc) { if (doc) {
foreach (Document::DiagnosticMessage m, doc->diagnosticMessages()) { foreach (Document::DiagnosticMessage m, doc->diagnosticMessages()) {
...@@ -179,6 +175,15 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in ...@@ -179,6 +175,15 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
break; break;
} }
} }
if (m_toolTip.isEmpty()) {
foreach (const Document::MacroUse use, doc->macroUses()) {
if (use.contains(pos)) {
m_toolTip = use.macro().toString();
break;
}
}
}
} }
if (m_toolTip.isEmpty()) { if (m_toolTip.isEmpty()) {
......
...@@ -302,14 +302,14 @@ void CppPreprocessor::macroAdded(const Macro &macro) ...@@ -302,14 +302,14 @@ void CppPreprocessor::macroAdded(const Macro &macro)
} }
void CppPreprocessor::startExpandingMacro(unsigned offset, void CppPreprocessor::startExpandingMacro(unsigned offset,
const Macro &, const Macro &macro,
const QByteArray &originalText) const QByteArray &originalText)
{ {
if (! m_currentDoc) if (! m_currentDoc)
return; return;
//qDebug() << "start expanding:" << macro.name << "text:" << originalText; //qDebug() << "start expanding:" << macro.name << "text:" << originalText;
m_currentDoc->addMacroUse(offset, originalText.length()); m_currentDoc->addMacroUse(macro, offset, originalText.length());
} }
void CppPreprocessor::stopExpandingMacro(unsigned, const Macro &) void CppPreprocessor::stopExpandingMacro(unsigned, const Macro &)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment