Commit 3a5d3a2f authored by Erik Verbruggen's avatar Erik Verbruggen

C++: unify highlighting/code-completion support "factories".

Both semantic highlighting and code-completion go hand-in-hand, so now
the ModelManagerSupport class acts as a "factory" for the model manager.
Depending on the mime-type of the document in the editor, the model
manager will return the appropriate highlighter or code-completion
engine. If none is registered, the built-in fall-back is used.

Change-Id: I3e5dbb0e3b58e077dd5eda9aecb2ce5d448ac0b8
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 0c6b6448
......@@ -40,7 +40,3 @@ CppHighlightingSupport::CppHighlightingSupport(TextEditor::ITextEditor *editor)
CppHighlightingSupport::~CppHighlightingSupport()
{
}
CppHighlightingSupportFactory::~CppHighlightingSupportFactory()
{
}
......@@ -81,14 +81,6 @@ private:
TextEditor::ITextEditor *m_editor;
};
class CPPTOOLS_EXPORT CppHighlightingSupportFactory
{
public:
virtual ~CppHighlightingSupportFactory() = 0;
virtual CppHighlightingSupport *highlightingSupport(TextEditor::ITextEditor *editor) = 0;
};
} // namespace CppTools
#endif // CPPTOOLS_CPPHIGHLIGHTINGSUPPORT_H
......@@ -92,12 +92,3 @@ QFuture<TextEditor::HighlightingResult> CppHighlightingSupportInternal::highligh
LookupContext context(doc, snapshot);
return CheckSymbols::go(doc, context, macroUses);
}
CppHighlightingSupportInternalFactory::~CppHighlightingSupportInternalFactory()
{
}
CppHighlightingSupport *CppHighlightingSupportInternalFactory::highlightingSupport(TextEditor::ITextEditor *editor)
{
return new CppHighlightingSupportInternal(editor);
}
......@@ -57,14 +57,6 @@ public:
const CPlusPlus::Snapshot &snapshot) const;
};
class CppHighlightingSupportInternalFactory: public CppHighlightingSupportFactory
{
public:
virtual ~CppHighlightingSupportInternalFactory();
virtual CppHighlightingSupport *highlightingSupport(TextEditor::ITextEditor *editor);
};
} // namespace Internal
} // namespace CppTools
......
......@@ -31,11 +31,10 @@
#include "abstracteditorsupport.h"
#include "builtinindexingsupport.h"
#include "cppcompletionassist.h"
#include "cppfindreferences.h"
#include "cpphighlightingsupport.h"
#include "cpphighlightingsupportinternal.h"
#include "cppindexingsupport.h"
#include "cppmodelmanagersupportinternal.h"
#include "cpppreprocessor.h"
#include "cpptoolsconstants.h"
#include "cpptoolseditorsupport.h"
......@@ -230,8 +229,6 @@ CppModelManager *CppModelManager::instance()
CppModelManager::CppModelManager(QObject *parent)
: CppModelManagerInterface(parent)
, m_completionAssistProvider(0)
, m_highlightingFactory(0)
, m_indexingSupporter(0)
, m_enableGC(true)
{
......@@ -259,16 +256,14 @@ CppModelManager::CppModelManager(QObject *parent)
qRegisterMetaType<CPlusPlus::Document::Ptr>("CPlusPlus::Document::Ptr");
m_completionFallback.reset(new InternalCompletionAssistProvider);
m_completionAssistProvider = m_completionFallback.data();
m_highlightingFallback = new CppHighlightingSupportInternalFactory;
m_highlightingFactory = m_highlightingFallback;
m_modelManagerSupportFallback.reset(new ModelManagerSupportInternal);
addModelManagerSupport(m_modelManagerSupportFallback.data());
m_internalIndexingSupport = new BuiltinIndexingSupport;
}
CppModelManager::~CppModelManager()
{
delete m_highlightingFallback;
delete m_internalIndexingSupport;
}
......@@ -911,35 +906,33 @@ void CppModelManager::finishedRefreshingSourceFiles(const QStringList &files)
emit sourceFilesRefreshed(files);
}
CppCompletionAssistProvider *CppModelManager::completionAssistProvider(Core::IEditor *editor) const
void CppModelManager::addModelManagerSupport(ModelManagerSupport *modelManagerSupport)
{
Q_UNUSED(editor);
if (!m_codeModelSupporters.contains(modelManagerSupport))
m_codeModelSupporters.append(modelManagerSupport);
}
return m_completionAssistProvider;
ModelManagerSupport *CppModelManager::modelManagerSupportForMimeType(const QString &mimeType) const
{
return m_mimeTypeToCodeModelSupport.value(mimeType, m_modelManagerSupportFallback.data());
}
void CppModelManager::setCppCompletionAssistProvider(CppCompletionAssistProvider *completionAssistProvider)
CppCompletionAssistProvider *CppModelManager::completionAssistProvider(Core::IEditor *editor) const
{
if (completionAssistProvider)
m_completionAssistProvider = completionAssistProvider;
else
m_completionAssistProvider = m_completionFallback.data();
ModelManagerSupport *cms = modelManagerSupportForMimeType(editor->document()->mimeType());
return cms->completionAssistProvider();
}
CppHighlightingSupport *CppModelManager::highlightingSupport(Core::IEditor *editor) const
{
if (TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor *>(editor))
return m_highlightingFactory->highlightingSupport(textEditor);
else
TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor *>(editor);
if (!textEditor)
return 0;
}
void CppModelManager::setHighlightingSupportFactory(CppHighlightingSupportFactory *highlightingFactory)
{
if (highlightingFactory)
m_highlightingFactory = highlightingFactory;
else
m_highlightingFactory = m_highlightingFallback;
ModelManagerSupport *cms = modelManagerSupportForMimeType(editor->document()->mimeType());
return cms->highlightingSupport(textEditor);
}
void CppModelManager::setIndexingSupport(CppIndexingSupport *indexingSupport)
......
......@@ -105,11 +105,10 @@ public:
void finishedRefreshingSourceFiles(const QStringList &files);
virtual void addModelManagerSupport(ModelManagerSupport *codeModelSupport);
virtual ModelManagerSupport *modelManagerSupportForMimeType(const QString &mimeType) const;
virtual CppCompletionAssistProvider *completionAssistProvider(Core::IEditor *editor) const;
virtual void setCppCompletionAssistProvider(CppCompletionAssistProvider *completionAssistProvider);
virtual CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const;
virtual void setHighlightingSupportFactory(CppHighlightingSupportFactory *highlightingFactory);
virtual void setIndexingSupport(CppIndexingSupport *indexingSupport);
virtual CppIndexingSupport *indexingSupport();
......@@ -202,13 +201,10 @@ private:
QMap<TextEditor::BaseTextEditor *, CppEditorSupport *> m_cppEditorSupports;
QSet<AbstractEditorSupport *> m_extraEditorSupports;
// Completion
CppCompletionAssistProvider *m_completionAssistProvider;
QScopedPointer<CppCompletionAssistProvider> m_completionFallback;
// Highlighting
CppHighlightingSupportFactory *m_highlightingFactory;
CppHighlightingSupportFactory *m_highlightingFallback;
// Completion & highlighting
QList<ModelManagerSupport *> m_codeModelSupporters;
QScopedPointer<ModelManagerSupport> m_modelManagerSupportFallback;
QHash<QString, ModelManagerSupport *> m_mimeTypeToCodeModelSupport;
// Indexing
CppIndexingSupport *m_indexingSupporter;
......
......@@ -52,6 +52,7 @@ namespace Utils { class FileName; }
namespace CppTools {
class AbstractEditorSupport;
class ModelManagerSupport;
class CppCompletionAssistProvider;
class CppEditorSupport;
class CppHighlightingSupport;
......@@ -243,14 +244,13 @@ public:
virtual void setIfdefedOutBlocks(const QString &fileName,
const QList<TextEditor::BlockRange> &ifdeffedOutBlocks) = 0;
virtual void addModelManagerSupport(ModelManagerSupport *modelManagerSupport) = 0;
virtual ModelManagerSupport *modelManagerSupportForMimeType(const QString &mimeType) const = 0;
virtual CppCompletionAssistProvider *completionAssistProvider(Core::IEditor *editor) const = 0;
virtual void setCppCompletionAssistProvider(CppTools::CppCompletionAssistProvider *completionAssistProvider) = 0;
virtual CppTools::CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const = 0;
virtual void setHighlightingSupportFactory(CppTools::CppHighlightingSupportFactory *highlightingFactory) = 0;
virtual CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const = 0;
virtual void setIndexingSupport(CppTools::CppIndexingSupport *indexingSupport) = 0;
virtual CppTools::CppIndexingSupport *indexingSupport() = 0;
virtual CppIndexingSupport *indexingSupport() = 0;
signals:
/// Project data might be locked while this is emitted.
......
/****************************************************************************
**
** 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 "cppmodelmanagersupport.h"
using namespace CppTools;
ModelManagerSupport::~ModelManagerSupport()
{
}
/****************************************************************************
**
** 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_CPPMODELMANAGERSUPPORT_H
#define CPPTOOLS_CPPMODELMANAGERSUPPORT_H
#include "cpptools_global.h"
#include <QString>
namespace TextEditor { class ITextEditor; }
namespace CppTools {
class CppCompletionAssistProvider;
class CppHighlightingSupport;
class CPPTOOLS_EXPORT ModelManagerSupport
{
public:
virtual ~ModelManagerSupport() = 0;
virtual QString id() const = 0;
virtual QString displayName() const = 0;
virtual CppCompletionAssistProvider *completionAssistProvider() = 0;
virtual CppHighlightingSupport *highlightingSupport(TextEditor::ITextEditor *editor) = 0;
};
} // CppTools namespace
#endif // CPPTOOLS_CPPMODELMANAGERSUPPORT_H
/****************************************************************************
**
** 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 "cppcompletionassist.h"
#include "cpphighlightingsupportinternal.h"
#include "cppmodelmanagersupportinternal.h"
#include <QCoreApplication>
using namespace CppTools;
using namespace CppTools::Internal;
ModelManagerSupportInternal::ModelManagerSupportInternal()
: m_completionAssistProvider(new InternalCompletionAssistProvider)
{
}
ModelManagerSupportInternal::~ModelManagerSupportInternal()
{
}
QString ModelManagerSupportInternal::id() const
{
return QLatin1String("CppTools.BuiltinCodeModel");
}
QString ModelManagerSupportInternal::displayName() const
{
return QCoreApplication::translate("ModelManagerSupportInternal::displayName",
"Qt Creator Built-in");
}
CppCompletionAssistProvider *ModelManagerSupportInternal::completionAssistProvider()
{
return m_completionAssistProvider.data();
}
CppHighlightingSupport *ModelManagerSupportInternal::highlightingSupport(TextEditor::ITextEditor *editor)
{
return new CppHighlightingSupportInternal(editor);
}
/****************************************************************************
**
** 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_INTERNAL_CPPMODELMANAGERSUPPORTINTERNAL_H
#define CPPTOOLS_INTERNAL_CPPMODELMANAGERSUPPORTINTERNAL_H
#include "cppmodelmanagersupport.h"
#include <QScopedPointer>
namespace CppTools {
namespace Internal {
class ModelManagerSupportInternal: public ModelManagerSupport
{
Q_DISABLE_COPY(ModelManagerSupportInternal)
public:
ModelManagerSupportInternal();
virtual ~ModelManagerSupportInternal();
virtual QString id() const;
virtual QString displayName() const;
virtual CppCompletionAssistProvider *completionAssistProvider();
virtual CppHighlightingSupport *highlightingSupport(TextEditor::ITextEditor *editor);
private:
QScopedPointer<CppCompletionAssistProvider> m_completionAssistProvider;
};
} // Internal namespace
} // CppTools namespace
#endif // CPPTOOLS_INTERNAL_CPPMODELMANAGERSUPPORTINTERNAL_H
......@@ -32,6 +32,7 @@ HEADERS += completionsettingspage.h \
doxygengenerator.h \
commentssettings.h \
symbolfinder.h \
cppmodelmanagersupport.h \
cpphighlightingsupport.h \
cpphighlightingsupportinternal.h \
cppchecksymbols.h \
......@@ -45,7 +46,8 @@ HEADERS += completionsettingspage.h \
cppprojectfile.h \
cpppreprocessor.h \
includeutils.h \
cpplocatordata.h
cpplocatordata.h \
cppmodelmanagersupportinternal.h
SOURCES += completionsettingspage.cpp \
cppclassesfilter.cpp \
......@@ -76,6 +78,7 @@ SOURCES += completionsettingspage.cpp \
doxygengenerator.cpp \
commentssettings.cpp \
symbolfinder.cpp \
cppmodelmanagersupport.cpp \
cpphighlightingsupport.cpp \
cpphighlightingsupportinternal.cpp \
cppchecksymbols.cpp \
......@@ -89,7 +92,8 @@ SOURCES += completionsettingspage.cpp \
cppprojectfile.cpp \
cpppreprocessor.cpp \
includeutils.cpp \
cpplocatordata.cpp
cpplocatordata.cpp \
cppmodelmanagersupportinternal.cpp
FORMS += completionsettingspage.ui \
cppfilesettingspage.ui \
......
......@@ -67,6 +67,10 @@ QtcPlugin {
"cpplocatorfilter.h",
"cppmodelmanager.cpp",
"cppmodelmanager.h",
"cppmodelmanagersupport.h",
"cppmodelmanagersupport.cpp",
"cppmodelmanagersupportinternal.h",
"cppmodelmanagersupportinternal.cpp",
"cppmodelmanagerinterface.cpp",
"cppmodelmanagerinterface.h",
"cppqtstyleindenter.cpp",
......
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