forked from qt-creator/qt-creator
		
	C++: clean-up CppCompletionAssist.
This is step 1 of 2 for merging the various provider factories into a single class. Merging has the advantage that selecting based on editor (content) mime-type only has to select one class, instead of re-doing the selection for each class separately. Change-Id: I11f815151bd4769ae6028b636793d6a80d02e202 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
		
				
					committed by
					
						
						Nikolai Kosjar
					
				
			
			
				
	
			
			
			
						parent
						
							49adb78ec9
						
					
				
				
					commit
					b4a1bd415f
				
			@@ -416,44 +416,25 @@ IAssistProcessor *InternalCompletionAssistProvider::createProcessor() const
 | 
			
		||||
    return new CppCompletionAssistProcessor;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace {
 | 
			
		||||
class CppCompletionSupportInternal: public CppCompletionSupport
 | 
			
		||||
TextEditor::IAssistInterface *InternalCompletionAssistProvider::createAssistInterface(
 | 
			
		||||
        ProjectExplorer::Project *project, const QString &filePath, QTextDocument *document,
 | 
			
		||||
        int position, TextEditor::AssistReason reason) const
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    CppCompletionSupportInternal(TextEditor::ITextEditor *editor)
 | 
			
		||||
        : CppCompletionSupport(editor)
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
    virtual ~CppCompletionSupportInternal()
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
    virtual TextEditor::IAssistInterface *createAssistInterface(ProjectExplorer::Project *project,
 | 
			
		||||
                                                                QTextDocument *document,
 | 
			
		||||
                                                                int position,
 | 
			
		||||
                                                                TextEditor::AssistReason reason) const
 | 
			
		||||
    {
 | 
			
		||||
        CppModelManagerInterface *modelManager = CppModelManagerInterface::instance();
 | 
			
		||||
        QStringList includePaths;
 | 
			
		||||
        QStringList frameworkPaths;
 | 
			
		||||
        if (project) {
 | 
			
		||||
            includePaths = modelManager->projectInfo(project).includePaths();
 | 
			
		||||
            frameworkPaths = modelManager->projectInfo(project).frameworkPaths();
 | 
			
		||||
        }
 | 
			
		||||
        return new CppTools::Internal::CppCompletionAssistInterface(
 | 
			
		||||
                    document,
 | 
			
		||||
                    position,
 | 
			
		||||
                    editor()->document()->filePath(),
 | 
			
		||||
                    reason,
 | 
			
		||||
                    modelManager->snapshot(),
 | 
			
		||||
                    includePaths,
 | 
			
		||||
                    frameworkPaths);
 | 
			
		||||
    CppModelManagerInterface *modelManager = CppModelManagerInterface::instance();
 | 
			
		||||
    QStringList includePaths;
 | 
			
		||||
    QStringList frameworkPaths;
 | 
			
		||||
    if (project) {
 | 
			
		||||
        includePaths = modelManager->projectInfo(project).includePaths();
 | 
			
		||||
        frameworkPaths = modelManager->projectInfo(project).frameworkPaths();
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CppCompletionSupport *InternalCompletionAssistProvider::completionSupport(ITextEditor *editor)
 | 
			
		||||
{
 | 
			
		||||
    return new CppCompletionSupportInternal(editor);
 | 
			
		||||
    return new CppTools::Internal::CppCompletionAssistInterface(
 | 
			
		||||
                document,
 | 
			
		||||
                position,
 | 
			
		||||
                filePath,
 | 
			
		||||
                reason,
 | 
			
		||||
                modelManager->snapshot(),
 | 
			
		||||
                includePaths,
 | 
			
		||||
                frameworkPaths);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// -----------------
 | 
			
		||||
 
 | 
			
		||||
@@ -89,7 +89,11 @@ class InternalCompletionAssistProvider : public CppCompletionAssistProvider
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    virtual TextEditor::IAssistProcessor *createProcessor() const;
 | 
			
		||||
    virtual CppCompletionSupport *completionSupport(TextEditor::ITextEditor *editor);
 | 
			
		||||
 | 
			
		||||
    virtual TextEditor::IAssistInterface *createAssistInterface(
 | 
			
		||||
            ProjectExplorer::Project *project, const QString &filePath, QTextDocument *document,
 | 
			
		||||
            int position, TextEditor::AssistReason reason) const;
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class CppCompletionAssistProcessor : public TextEditor::IAssistProcessor
 | 
			
		||||
 
 | 
			
		||||
@@ -30,11 +30,23 @@
 | 
			
		||||
#ifndef CPPTOOLS_CPPCOMPLETIONASSISTPROVIDER_H
 | 
			
		||||
#define CPPTOOLS_CPPCOMPLETIONASSISTPROVIDER_H
 | 
			
		||||
 | 
			
		||||
#include "cppcompletionsupport.h"
 | 
			
		||||
#include "cpptools_global.h"
 | 
			
		||||
 | 
			
		||||
#include <texteditor/codeassist/assistenums.h>
 | 
			
		||||
#include <texteditor/codeassist/completionassistprovider.h>
 | 
			
		||||
 | 
			
		||||
QT_BEGIN_NAMESPACE
 | 
			
		||||
class QTextDocument;
 | 
			
		||||
QT_END_NAMESPACE
 | 
			
		||||
 | 
			
		||||
namespace ProjectExplorer {
 | 
			
		||||
class Project;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace TextEditor {
 | 
			
		||||
class IAssistInterface;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace CppTools {
 | 
			
		||||
 | 
			
		||||
class CPPTOOLS_EXPORT CppCompletionAssistProvider : public TextEditor::CompletionAssistProvider
 | 
			
		||||
@@ -46,7 +58,9 @@ public:
 | 
			
		||||
    virtual int activationCharSequenceLength() const;
 | 
			
		||||
    virtual bool isActivationCharSequence(const QString &sequence) const;
 | 
			
		||||
 | 
			
		||||
    virtual CppCompletionSupport *completionSupport(TextEditor::ITextEditor *editor) = 0;
 | 
			
		||||
    virtual TextEditor::IAssistInterface *createAssistInterface(
 | 
			
		||||
            ProjectExplorer::Project *project, const QString &filePath, QTextDocument *document,
 | 
			
		||||
            int position, TextEditor::AssistReason reason) const = 0;
 | 
			
		||||
 | 
			
		||||
    static int activationSequenceChar(const QChar &ch, const QChar &ch2,
 | 
			
		||||
                                      const QChar &ch3, unsigned *kind,
 | 
			
		||||
 
 | 
			
		||||
@@ -1,42 +0,0 @@
 | 
			
		||||
/****************************************************************************
 | 
			
		||||
**
 | 
			
		||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
 | 
			
		||||
** Contact: http://www.qt-project.org/legal
 | 
			
		||||
**
 | 
			
		||||
** This file is part of Qt Creator.
 | 
			
		||||
**
 | 
			
		||||
** Commercial License Usage
 | 
			
		||||
** Licensees holding valid commercial Qt licenses may use this file in
 | 
			
		||||
** accordance with the commercial license agreement provided with the
 | 
			
		||||
** Software or, alternatively, in accordance with the terms contained in
 | 
			
		||||
** a written agreement between you and Digia.  For licensing terms and
 | 
			
		||||
** conditions see http://qt.digia.com/licensing.  For further information
 | 
			
		||||
** use the contact form at http://qt.digia.com/contact-us.
 | 
			
		||||
**
 | 
			
		||||
** GNU Lesser General Public License Usage
 | 
			
		||||
** Alternatively, this file may be used under the terms of the GNU Lesser
 | 
			
		||||
** General Public License version 2.1 as published by the Free Software
 | 
			
		||||
** Foundation and appearing in the file LICENSE.LGPL included in the
 | 
			
		||||
** packaging of this file.  Please review the following information to
 | 
			
		||||
** ensure the GNU Lesser General Public License version 2.1 requirements
 | 
			
		||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 | 
			
		||||
**
 | 
			
		||||
** In addition, as a special exception, Digia gives you certain additional
 | 
			
		||||
** rights.  These rights are described in the Digia Qt LGPL Exception
 | 
			
		||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 | 
			
		||||
**
 | 
			
		||||
****************************************************************************/
 | 
			
		||||
 | 
			
		||||
#include "cppcompletionsupport.h"
 | 
			
		||||
 | 
			
		||||
using namespace CppTools;
 | 
			
		||||
 | 
			
		||||
CppCompletionSupport::CppCompletionSupport(TextEditor::ITextEditor *editor)
 | 
			
		||||
    : m_editor(editor)
 | 
			
		||||
{
 | 
			
		||||
    Q_ASSERT(editor);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CppCompletionSupport::~CppCompletionSupport()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
@@ -1,73 +0,0 @@
 | 
			
		||||
/****************************************************************************
 | 
			
		||||
**
 | 
			
		||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
 | 
			
		||||
** Contact: http://www.qt-project.org/legal
 | 
			
		||||
**
 | 
			
		||||
** This file is part of Qt Creator.
 | 
			
		||||
**
 | 
			
		||||
** Commercial License Usage
 | 
			
		||||
** Licensees holding valid commercial Qt licenses may use this file in
 | 
			
		||||
** accordance with the commercial license agreement provided with the
 | 
			
		||||
** Software or, alternatively, in accordance with the terms contained in
 | 
			
		||||
** a written agreement between you and Digia.  For licensing terms and
 | 
			
		||||
** conditions see http://qt.digia.com/licensing.  For further information
 | 
			
		||||
** use the contact form at http://qt.digia.com/contact-us.
 | 
			
		||||
**
 | 
			
		||||
** GNU Lesser General Public License Usage
 | 
			
		||||
** Alternatively, this file may be used under the terms of the GNU Lesser
 | 
			
		||||
** General Public License version 2.1 as published by the Free Software
 | 
			
		||||
** Foundation and appearing in the file LICENSE.LGPL included in the
 | 
			
		||||
** packaging of this file.  Please review the following information to
 | 
			
		||||
** ensure the GNU Lesser General Public License version 2.1 requirements
 | 
			
		||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 | 
			
		||||
**
 | 
			
		||||
** In addition, as a special exception, Digia gives you certain additional
 | 
			
		||||
** rights.  These rights are described in the Digia Qt LGPL Exception
 | 
			
		||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 | 
			
		||||
**
 | 
			
		||||
****************************************************************************/
 | 
			
		||||
 | 
			
		||||
#ifndef CPPTOOLS_CPPCOMPLETIONSUPPORT_H
 | 
			
		||||
#define CPPTOOLS_CPPCOMPLETIONSUPPORT_H
 | 
			
		||||
 | 
			
		||||
#include "cpptools_global.h"
 | 
			
		||||
 | 
			
		||||
#include <texteditor/codeassist/assistenums.h>
 | 
			
		||||
 | 
			
		||||
QT_BEGIN_NAMESPACE
 | 
			
		||||
class QTextDocument;
 | 
			
		||||
QT_END_NAMESPACE
 | 
			
		||||
 | 
			
		||||
namespace ProjectExplorer {
 | 
			
		||||
class Project;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace TextEditor {
 | 
			
		||||
class IAssistInterface;
 | 
			
		||||
class ITextEditor;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace CppTools {
 | 
			
		||||
 | 
			
		||||
class CPPTOOLS_EXPORT CppCompletionSupport
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    CppCompletionSupport(TextEditor::ITextEditor *editor);
 | 
			
		||||
    virtual ~CppCompletionSupport() = 0;
 | 
			
		||||
 | 
			
		||||
    virtual TextEditor::IAssistInterface *createAssistInterface(ProjectExplorer::Project *project,
 | 
			
		||||
                                                                QTextDocument *document,
 | 
			
		||||
                                                                int position,
 | 
			
		||||
                                                                TextEditor::AssistReason reason) const = 0;
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    TextEditor::ITextEditor *editor() const
 | 
			
		||||
    { return m_editor; }
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    TextEditor::ITextEditor *m_editor;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} // namespace CppTools
 | 
			
		||||
 | 
			
		||||
#endif // CPPTOOLS_CPPCOMPLETIONSUPPORT_H
 | 
			
		||||
@@ -259,9 +259,8 @@ CppModelManager::CppModelManager(QObject *parent)
 | 
			
		||||
 | 
			
		||||
    qRegisterMetaType<CPlusPlus::Document::Ptr>("CPlusPlus::Document::Ptr");
 | 
			
		||||
 | 
			
		||||
    m_completionFallback = new InternalCompletionAssistProvider;
 | 
			
		||||
    m_completionAssistProvider = m_completionFallback;
 | 
			
		||||
    ExtensionSystem::PluginManager::addObject(m_completionAssistProvider);
 | 
			
		||||
    m_completionFallback.reset(new InternalCompletionAssistProvider);
 | 
			
		||||
    m_completionAssistProvider = m_completionFallback.data();
 | 
			
		||||
    m_highlightingFallback = new CppHighlightingSupportInternalFactory;
 | 
			
		||||
    m_highlightingFactory = m_highlightingFallback;
 | 
			
		||||
    m_internalIndexingSupport = new BuiltinIndexingSupport;
 | 
			
		||||
@@ -269,8 +268,6 @@ CppModelManager::CppModelManager(QObject *parent)
 | 
			
		||||
 | 
			
		||||
CppModelManager::~CppModelManager()
 | 
			
		||||
{
 | 
			
		||||
    ExtensionSystem::PluginManager::removeObject(m_completionAssistProvider);
 | 
			
		||||
    delete m_completionFallback;
 | 
			
		||||
    delete m_highlightingFallback;
 | 
			
		||||
    delete m_internalIndexingSupport;
 | 
			
		||||
}
 | 
			
		||||
@@ -899,14 +896,6 @@ void CppModelManager::finishedRefreshingSourceFiles(const QStringList &files)
 | 
			
		||||
    emit sourceFilesRefreshed(files);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CppCompletionSupport *CppModelManager::completionSupport(Core::IEditor *editor) const
 | 
			
		||||
{
 | 
			
		||||
    if (TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor *>(editor))
 | 
			
		||||
        return m_completionAssistProvider->completionSupport(textEditor);
 | 
			
		||||
    else
 | 
			
		||||
        return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CppCompletionAssistProvider *CppModelManager::completionAssistProvider(Core::IEditor *editor) const
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(editor);
 | 
			
		||||
@@ -916,12 +905,10 @@ CppCompletionAssistProvider *CppModelManager::completionAssistProvider(Core::IEd
 | 
			
		||||
 | 
			
		||||
void CppModelManager::setCppCompletionAssistProvider(CppCompletionAssistProvider *completionAssistProvider)
 | 
			
		||||
{
 | 
			
		||||
    ExtensionSystem::PluginManager::removeObject(m_completionAssistProvider);
 | 
			
		||||
    if (completionAssistProvider)
 | 
			
		||||
        m_completionAssistProvider = completionAssistProvider;
 | 
			
		||||
    else
 | 
			
		||||
        m_completionAssistProvider = m_completionFallback;
 | 
			
		||||
    ExtensionSystem::PluginManager::addObject(m_completionAssistProvider);
 | 
			
		||||
        m_completionAssistProvider = m_completionFallback.data();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CppHighlightingSupport *CppModelManager::highlightingSupport(Core::IEditor *editor) const
 | 
			
		||||
 
 | 
			
		||||
@@ -104,7 +104,6 @@ public:
 | 
			
		||||
 | 
			
		||||
    void finishedRefreshingSourceFiles(const QStringList &files);
 | 
			
		||||
 | 
			
		||||
    virtual CppCompletionSupport *completionSupport(Core::IEditor *editor) const;
 | 
			
		||||
    virtual CppCompletionAssistProvider *completionAssistProvider(Core::IEditor *editor) const;
 | 
			
		||||
    virtual void setCppCompletionAssistProvider(CppCompletionAssistProvider *completionAssistProvider);
 | 
			
		||||
 | 
			
		||||
@@ -204,7 +203,7 @@ private:
 | 
			
		||||
 | 
			
		||||
    // Completion
 | 
			
		||||
    CppCompletionAssistProvider *m_completionAssistProvider;
 | 
			
		||||
    CppCompletionAssistProvider *m_completionFallback;
 | 
			
		||||
    QScopedPointer<CppCompletionAssistProvider> m_completionFallback;
 | 
			
		||||
 | 
			
		||||
    // Highlighting
 | 
			
		||||
    CppHighlightingSupportFactory *m_highlightingFactory;
 | 
			
		||||
 
 | 
			
		||||
@@ -53,7 +53,6 @@ namespace CppTools {
 | 
			
		||||
 | 
			
		||||
class AbstractEditorSupport;
 | 
			
		||||
class CppCompletionAssistProvider;
 | 
			
		||||
class CppCompletionSupport;
 | 
			
		||||
class CppEditorSupport;
 | 
			
		||||
class CppHighlightingSupport;
 | 
			
		||||
class CppHighlightingSupportFactory;
 | 
			
		||||
@@ -241,7 +240,6 @@ public:
 | 
			
		||||
    virtual void setIfdefedOutBlocks(const QString &fileName,
 | 
			
		||||
                                     const QList<TextEditor::BlockRange> &ifdeffedOutBlocks) = 0;
 | 
			
		||||
 | 
			
		||||
    virtual CppTools::CppCompletionSupport *completionSupport(Core::IEditor *editor) const = 0;
 | 
			
		||||
    virtual CppCompletionAssistProvider *completionAssistProvider(Core::IEditor *editor) const = 0;
 | 
			
		||||
    virtual void setCppCompletionAssistProvider(CppTools::CppCompletionAssistProvider *completionAssistProvider) = 0;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -32,7 +32,6 @@ HEADERS += completionsettingspage.h \
 | 
			
		||||
    doxygengenerator.h \
 | 
			
		||||
    commentssettings.h \
 | 
			
		||||
    symbolfinder.h \
 | 
			
		||||
    cppcompletionsupport.h \
 | 
			
		||||
    cpphighlightingsupport.h \
 | 
			
		||||
    cpphighlightingsupportinternal.h \
 | 
			
		||||
    cppchecksymbols.h \
 | 
			
		||||
@@ -77,7 +76,6 @@ SOURCES += completionsettingspage.cpp \
 | 
			
		||||
    doxygengenerator.cpp \
 | 
			
		||||
    commentssettings.cpp \
 | 
			
		||||
    symbolfinder.cpp \
 | 
			
		||||
    cppcompletionsupport.cpp \
 | 
			
		||||
    cpphighlightingsupport.cpp \
 | 
			
		||||
    cpphighlightingsupportinternal.cpp \
 | 
			
		||||
    cppchecksymbols.cpp \
 | 
			
		||||
 
 | 
			
		||||
@@ -43,8 +43,6 @@ QtcPlugin {
 | 
			
		||||
        "cppcompletionassist.h",
 | 
			
		||||
        "cppcompletionassistprovider.cpp",
 | 
			
		||||
        "cppcompletionassistprovider.h",
 | 
			
		||||
        "cppcompletionsupport.cpp",
 | 
			
		||||
        "cppcompletionsupport.h",
 | 
			
		||||
        "cppcurrentdocumentfilter.cpp",
 | 
			
		||||
        "cppcurrentdocumentfilter.h",
 | 
			
		||||
        "cppdoxygen.cpp",
 | 
			
		||||
 
 | 
			
		||||
@@ -232,7 +232,7 @@ void CppEditorSupport::recalculateSemanticInfoDetached(bool force)
 | 
			
		||||
 | 
			
		||||
CppCompletionAssistProvider *CppEditorSupport::completionAssistProvider() const
 | 
			
		||||
{
 | 
			
		||||
    return m_completionAssistProvider.data();
 | 
			
		||||
    return m_completionAssistProvider;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CppEditorSupport::updateDocument()
 | 
			
		||||
@@ -526,6 +526,8 @@ void CppEditorSupport::onMimeTypeChanged()
 | 
			
		||||
        connect(this, SIGNAL(semanticInfoUpdated(CppTools::SemanticInfo)),
 | 
			
		||||
                this, SLOT(startHighlighting()));
 | 
			
		||||
 | 
			
		||||
    m_completionAssistProvider = m_modelManager->completionAssistProvider(m_textEditor);
 | 
			
		||||
 | 
			
		||||
    updateDocumentNow();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -195,7 +195,7 @@ private:
 | 
			
		||||
    QScopedPointer<CppTools::CppHighlightingSupport> m_highlightingSupport;
 | 
			
		||||
 | 
			
		||||
    // Completion:
 | 
			
		||||
    QScopedPointer<CppCompletionAssistProvider> m_completionAssistProvider;
 | 
			
		||||
    CppCompletionAssistProvider *m_completionAssistProvider;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} // namespace CppTools
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user