forked from qt-creator/qt-creator
		
	Added #preprocessor directive completion.
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user