Commit 8f9e2eeb authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Added #preprocessor directive completion.

parent eb9e7866
......@@ -523,6 +523,10 @@ static int startOfOperator(TextEditor::ITextEditable *editor,
completionKind = T_SLASH;
--start;
break;
case '#':
completionKind = T_POUND;
--start;
break;
}
if (start == pos)
......@@ -678,6 +682,13 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
return m_startPosition;
}
// Pre-processor completion
if (m_completionOperator == T_POUND) {
completePreprocessor();
m_startPosition = startOfName;
return m_startPosition;
}
// Include completion
if (m_completionOperator == T_STRING_LITERAL
|| m_completionOperator == T_ANGLE_STRING_LITERAL
......@@ -1256,6 +1267,37 @@ bool CppCodeCompletion::completeInclude(const QTextCursor &cursor)
return !m_completions.isEmpty();
}
QStringList CppCodeCompletion::preprocessorCompletions
= QStringList()
<< QLatin1String("define")
<< QLatin1String("error")
<< QLatin1String("include")
<< QLatin1String("line")
<< QLatin1String("pragma")
<< QLatin1String("undef")
<< QLatin1String("if")
<< QLatin1String("ifdef")
<< QLatin1String("ifndef")
<< QLatin1String("elif")
<< QLatin1String("else")
<< QLatin1String("endif")
;
void CppCodeCompletion::completePreprocessor()
{
TextEditor::CompletionItem item(this);
foreach (const QString &preprocessorCompletion, preprocessorCompletions) {
item.text = preprocessorCompletion;
m_completions.append(item);
}
if (objcKeywordsWanted()) {
item.text = QLatin1String("import");
m_completions.append(item);
}
}
void CppCodeCompletion::completeNamespace(ClassOrNamespace *b)
{
QSet<ClassOrNamespace *> bindingsVisited;
......
......@@ -94,6 +94,7 @@ private:
void addCompletionItem(CPlusPlus::Symbol *symbol);
bool completeInclude(const QTextCursor &cursor);
void completePreprocessor();
int globalCompletion(CPlusPlus::Symbol *lastVisibleSymbol,
CPlusPlus::Document::Ptr thisDocument,
......@@ -132,6 +133,8 @@ private:
private:
bool objcKeywordsWanted() const;
static QStringList preprocessorCompletions;
CppModelManager *m_manager;
TextEditor::ITextEditable *m_editor;
int m_startPosition; // Position of the cursor from which completion started
......
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