Commit d4546072 authored by Roberto Raggi's avatar Roberto Raggi

Implemented tooltip and lookat for #include directives.

parent 6ae2cc0b
......@@ -131,12 +131,16 @@ QString Document::fileName() const
QStringList Document::includedFiles() const
{
return _includedFiles;
QStringList files;
foreach (const Include &i, _includes)
files.append(i.fileName());
files.removeDuplicates();
return files;
}
void Document::addIncludeFile(const QString &fileName)
void Document::addIncludeFile(const QString &fileName, unsigned line)
{
_includedFiles.append(fileName);
_includes.append(Include(fileName, line));
}
void Document::appendMacro(const Macro &macro)
......
......@@ -65,7 +65,7 @@ public:
QString fileName() const;
QStringList includedFiles() const;
void addIncludeFile(const QString &fileName);
void addIncludeFile(const QString &fileName, unsigned line);
void appendMacro(const Macro &macro);
void addMacroUse(const Macro &macro, unsigned offset, unsigned length);
......@@ -181,6 +181,22 @@ public:
{ return pos >= _begin && pos < _end; }
};
class Include {
QString _fileName;
unsigned _line;
public:
Include(const QString &fileName, unsigned line)
: _fileName(fileName), _line(line)
{ }
QString fileName() const
{ return _fileName; }
unsigned line() const
{ return _line; }
};
class MacroUse: public Block {
Macro _macro;
......@@ -196,6 +212,9 @@ public:
{ return _macro; }
};
QList<Include> includes() const
{ return _includes; }
QList<Block> skippedBlocks() const
{ return _skippedBlocks; }
......@@ -207,11 +226,11 @@ private:
private:
QString _fileName;
QStringList _includedFiles;
Control *_control;
TranslationUnit *_translationUnit;
Namespace *_globalNamespace;
QList<DiagnosticMessage> _diagnosticMessages;
QList<Include> _includes;
QList<Macro> _definedMacros;
QList<Block> _skippedBlocks;
QList<MacroUse> _macroUses;
......
......@@ -63,7 +63,8 @@ public:
{ }
virtual void macroAdded(const Macro &macro) = 0;
virtual void sourceNeeded(QString &fileName, IncludeType mode) = 0; // ### FIX the signature.
virtual void sourceNeeded(QString &fileName, IncludeType mode,
unsigned line) = 0; // ### FIX the signature.
virtual void startExpandingMacro(unsigned offset,
const Macro &macro,
......
......@@ -818,7 +818,7 @@ void pp::processInclude(bool skipCurentPath,
QString fn = QString::fromUtf8(path.constData(), path.length());
if (client)
client->sourceNeeded(fn, Client::IncludeGlobal);
client->sourceNeeded(fn, Client::IncludeGlobal, firstToken->lineno);
} else if (tk->is(T_ANGLE_STRING_LITERAL) || tk->is(T_STRING_LITERAL)) {
const QByteArray spell = tokenSpell(*tk);
const char *beginOfPath = spell.constBegin();
......@@ -831,7 +831,7 @@ void pp::processInclude(bool skipCurentPath,
QString fn = QString::fromUtf8(path.constData(), path.length());
if (client)
client->sourceNeeded(fn, Client::IncludeLocal);
client->sourceNeeded(fn, Client::IncludeLocal, firstToken->lineno);
}
}
}
......
......@@ -480,13 +480,23 @@ void CPPEditor::jumpToDefinition()
Document::Ptr doc = m_modelManager->document(file()->fileName());
if (!doc)
return;
QTextCursor tc = textCursor();
unsigned lineno = tc.blockNumber() + 1;
foreach (const Document::Include &incl, doc->includes()) {
if (incl.line() == lineno) {
if (TextEditor::BaseTextEditor::openEditorAt(incl.fileName(), 0, 0))
return; // done
break;
}
}
Symbol *lastSymbol = doc->findSymbolAt(line, column);
if (!lastSymbol)
return;
// Get the expression under the cursor
const int endOfName = endOfNameUnderCursor();
QTextCursor tc = textCursor();
tc.setPosition(endOfName);
ExpressionUnderCursor expressionUnderCursor;
const QString expression = expressionUnderCursor(tc);
......
......@@ -177,6 +177,16 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
}
}
if (m_toolTip.isEmpty()) {
unsigned lineno = tc.blockNumber() + 1;
foreach (const Document::Include &incl, doc->includes()) {
if (lineno == incl.line()) {
m_toolTip = incl.fileName();
break;
}
}
}
if (m_toolTip.isEmpty()) {
// Move to the end of a qualified name
bool stop = false;
......
......@@ -138,7 +138,8 @@ protected:
virtual void stopExpandingMacro(unsigned offset, const Macro &macro);
virtual void startSkippingBlocks(unsigned offset);
virtual void stopSkippingBlocks(unsigned offset);
virtual void sourceNeeded(QString &fileName, IncludeType type);
virtual void sourceNeeded(QString &fileName, IncludeType type,
unsigned line);
private:
QPointer<CppModelManager> m_modelManager;
......@@ -176,7 +177,7 @@ void CppPreprocessor::setProjectFiles(const QStringList &files)
{ m_projectFiles = files; }
void CppPreprocessor::run(QString &fileName)
{ sourceNeeded(fileName, IncludeGlobal); }
{ sourceNeeded(fileName, IncludeGlobal, /*line = */ 0); }
void CppPreprocessor::operator()(QString &fileName)
{ run(fileName); }
......@@ -361,7 +362,8 @@ void CppPreprocessor::stopSkippingBlocks(unsigned offset)
m_currentDoc->stopSkippingBlocks(offset);
}
void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type)
void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type,
unsigned line)
{
if (fileName.isEmpty())
return;
......@@ -369,7 +371,7 @@ void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type)
QByteArray contents = tryIncludeFile(fileName, type);
if (m_currentDoc) {
m_currentDoc->addIncludeFile(fileName);
m_currentDoc->addIncludeFile(fileName, line);
if (contents.isEmpty() && ! QFileInfo(fileName).isAbsolute()) {
QString msg;
msg += fileName;
......
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