Commit a26bef5f authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Ignore undefined macros in macro completion

Done with Roberto Raggi
parent d94dd392
......@@ -819,33 +819,45 @@ void CppCodeCompletion::addKeywords()
void CppCodeCompletion::addMacros(const LookupContext &context)
{
// macro completion items.
QSet<QByteArray> macroNames;
QSet<QString> processed;
QList<QString> todo;
todo.append(context.thisDocument()->fileName());
while (! todo.isEmpty()) {
QString fn = todo.last();
todo.removeLast();
if (processed.contains(fn))
continue;
processed.insert(fn);
if (Document::Ptr doc = context.document(fn)) {
foreach (const Macro &macro, doc->definedMacros()) {
macroNames.insert(macro.name());
}
todo += doc->includedFiles();
}
}
QSet<QString> definedMacros;
foreach (const QByteArray &macroName, macroNames) {
addMacros_helper(context, context.thisDocument()->fileName(),
&processed, &definedMacros);
foreach (const QString &macroName, definedMacros) {
TextEditor::CompletionItem item(this);
item.m_text = QString::fromUtf8(macroName.constData(), macroName.length());
item.m_text = macroName;
item.m_icon = m_icons.macroIcon();
m_completions.append(item);
}
}
void CppCodeCompletion::addMacros_helper(const LookupContext &context,
const QString &fileName,
QSet<QString> *processed,
QSet<QString> *definedMacros)
{
Document::Ptr doc = context.document(fileName);
if (! doc || processed->contains(doc->fileName()))
return;
processed->insert(doc->fileName());
foreach (const Document::Include &i, doc->includes()) {
addMacros_helper(context, i.fileName(), processed, definedMacros);
}
foreach (const Macro &macro, doc->definedMacros()) {
const QString macroName = QString::fromUtf8(macro.name().constData(), macro.name().length());
if (! macro.isHidden())
definedMacros->insert(macroName);
else
definedMacros->remove(macroName);
}
}
void CppCodeCompletion::addCompletionItem(Symbol *symbol)
{
ConvertToCompletionItem toCompletionItem(this);
......
......@@ -84,6 +84,10 @@ public:
private:
void addKeywords();
void addMacros(const CPlusPlus::LookupContext &context);
void addMacros_helper(const CPlusPlus::LookupContext &context,
const QString &fileName,
QSet<QString> *processed,
QSet<QString> *definedMacros);
void addCompletionItem(CPlusPlus::Symbol *symbol);
bool completeConstructorOrFunction(CPlusPlus::FullySpecifiedType exprTy,
......
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