Commit b4a1bd41 authored by Erik Verbruggen's avatar Erik Verbruggen Committed by Nikolai Kosjar

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: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 49adb78e
...@@ -43,7 +43,6 @@ ...@@ -43,7 +43,6 @@
#include <cpptools/cpptoolsconstants.h> #include <cpptools/cpptoolsconstants.h>
#include <cpptools/cppchecksymbols.h> #include <cpptools/cppchecksymbols.h>
#include <cpptools/cppcodeformatter.h> #include <cpptools/cppcodeformatter.h>
#include <cpptools/cppcompletionsupport.h>
#include <cpptools/cppcompletionassistprovider.h> #include <cpptools/cppcompletionassistprovider.h>
#include <cpptools/cpphighlightingsupport.h> #include <cpptools/cpphighlightingsupport.h>
#include <cpptools/cpplocalsymbols.h> #include <cpptools/cpplocalsymbols.h>
...@@ -511,7 +510,6 @@ CPPEditorWidget::CPPEditorWidget(QWidget *parent) ...@@ -511,7 +510,6 @@ CPPEditorWidget::CPPEditorWidget(QWidget *parent)
, m_firstRenameChange(false) , m_firstRenameChange(false)
, m_objcEnabled(false) , m_objcEnabled(false)
, m_commentsSettings(CppTools::CppToolsSettings::instance()->commentsSettings()) , m_commentsSettings(CppTools::CppToolsSettings::instance()->commentsSettings())
, m_completionSupport(0)
{ {
qRegisterMetaType<SemanticInfo>("CppTools::SemanticInfo"); qRegisterMetaType<SemanticInfo>("CppTools::SemanticInfo");
...@@ -532,8 +530,6 @@ CPPEditorWidget::CPPEditorWidget(QWidget *parent) ...@@ -532,8 +530,6 @@ CPPEditorWidget::CPPEditorWidget(QWidget *parent)
this, SLOT(updateSemanticInfo(CppTools::SemanticInfo))); this, SLOT(updateSemanticInfo(CppTools::SemanticInfo)));
connect(editorSupport, SIGNAL(highlighterStarted(QFuture<TextEditor::HighlightingResult>*,uint)), connect(editorSupport, SIGNAL(highlighterStarted(QFuture<TextEditor::HighlightingResult>*,uint)),
this, SLOT(highlighterStarted(QFuture<TextEditor::HighlightingResult>*,uint))); this, SLOT(highlighterStarted(QFuture<TextEditor::HighlightingResult>*,uint)));
m_completionSupport = m_modelManager->completionSupport(editor());
} }
m_highlightRevision = 0; m_highlightRevision = 0;
...@@ -563,8 +559,6 @@ CPPEditorWidget::~CPPEditorWidget() ...@@ -563,8 +559,6 @@ CPPEditorWidget::~CPPEditorWidget()
{ {
if (m_modelManager) if (m_modelManager)
m_modelManager->deleteCppEditorSupport(editor()); m_modelManager->deleteCppEditorSupport(editor());
delete m_completionSupport;
} }
TextEditor::BaseTextEditor *CPPEditorWidget::createEditor() TextEditor::BaseTextEditor *CPPEditorWidget::createEditor()
...@@ -2111,10 +2105,12 @@ TextEditor::IAssistInterface *CPPEditorWidget::createAssistInterface( ...@@ -2111,10 +2105,12 @@ TextEditor::IAssistInterface *CPPEditorWidget::createAssistInterface(
TextEditor::AssistReason reason) const TextEditor::AssistReason reason) const
{ {
if (kind == TextEditor::Completion) { if (kind == TextEditor::Completion) {
if (m_completionSupport) CppEditorSupport *ces = CppModelManagerInterface::instance()->cppEditorSupport(editor());
return m_completionSupport->createAssistInterface( CppCompletionAssistProvider *cap = ces->completionAssistProvider();
if (cap)
return cap->createAssistInterface(
ProjectExplorer::ProjectExplorerPlugin::currentProject(), ProjectExplorer::ProjectExplorerPlugin::currentProject(),
document(), position(), reason); editor()->document()->filePath(), document(), position(), reason);
} else if (kind == TextEditor::QuickFix) { } else if (kind == TextEditor::QuickFix) {
if (!semanticInfo().doc || isOutdated()) if (!semanticInfo().doc || isOutdated())
return 0; return 0;
......
...@@ -262,8 +262,6 @@ private: ...@@ -262,8 +262,6 @@ private:
QSharedPointer<FunctionDeclDefLink> m_declDefLink; QSharedPointer<FunctionDeclDefLink> m_declDefLink;
CppTools::CommentsSettings m_commentsSettings; CppTools::CommentsSettings m_commentsSettings;
CppTools::CppCompletionSupport *m_completionSupport;
}; };
} // namespace Internal } // namespace Internal
......
...@@ -416,44 +416,25 @@ IAssistProcessor *InternalCompletionAssistProvider::createProcessor() const ...@@ -416,44 +416,25 @@ IAssistProcessor *InternalCompletionAssistProvider::createProcessor() const
return new CppCompletionAssistProcessor; return new CppCompletionAssistProcessor;
} }
namespace { TextEditor::IAssistInterface *InternalCompletionAssistProvider::createAssistInterface(
class CppCompletionSupportInternal: public CppCompletionSupport ProjectExplorer::Project *project, const QString &filePath, QTextDocument *document,
int position, TextEditor::AssistReason reason) const
{ {
public: CppModelManagerInterface *modelManager = CppModelManagerInterface::instance();
CppCompletionSupportInternal(TextEditor::ITextEditor *editor) QStringList includePaths;
: CppCompletionSupport(editor) QStringList frameworkPaths;
{} if (project) {
includePaths = modelManager->projectInfo(project).includePaths();
virtual ~CppCompletionSupportInternal() frameworkPaths = modelManager->projectInfo(project).frameworkPaths();
{}
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);
} }
}; return new CppTools::Internal::CppCompletionAssistInterface(
} document,
position,
CppCompletionSupport *InternalCompletionAssistProvider::completionSupport(ITextEditor *editor) filePath,
{ reason,
return new CppCompletionSupportInternal(editor); modelManager->snapshot(),
includePaths,
frameworkPaths);
} }
// ----------------- // -----------------
......
...@@ -89,7 +89,11 @@ class InternalCompletionAssistProvider : public CppCompletionAssistProvider ...@@ -89,7 +89,11 @@ class InternalCompletionAssistProvider : public CppCompletionAssistProvider
public: public:
virtual TextEditor::IAssistProcessor *createProcessor() const; 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 class CppCompletionAssistProcessor : public TextEditor::IAssistProcessor
......
...@@ -30,11 +30,23 @@ ...@@ -30,11 +30,23 @@
#ifndef CPPTOOLS_CPPCOMPLETIONASSISTPROVIDER_H #ifndef CPPTOOLS_CPPCOMPLETIONASSISTPROVIDER_H
#define CPPTOOLS_CPPCOMPLETIONASSISTPROVIDER_H #define CPPTOOLS_CPPCOMPLETIONASSISTPROVIDER_H
#include "cppcompletionsupport.h"
#include "cpptools_global.h" #include "cpptools_global.h"
#include <texteditor/codeassist/assistenums.h>
#include <texteditor/codeassist/completionassistprovider.h> #include <texteditor/codeassist/completionassistprovider.h>
QT_BEGIN_NAMESPACE
class QTextDocument;
QT_END_NAMESPACE
namespace ProjectExplorer {
class Project;
}
namespace TextEditor {
class IAssistInterface;
}
namespace CppTools { namespace CppTools {
class CPPTOOLS_EXPORT CppCompletionAssistProvider : public TextEditor::CompletionAssistProvider class CPPTOOLS_EXPORT CppCompletionAssistProvider : public TextEditor::CompletionAssistProvider
...@@ -46,7 +58,9 @@ public: ...@@ -46,7 +58,9 @@ public:
virtual int activationCharSequenceLength() const; virtual int activationCharSequenceLength() const;
virtual bool isActivationCharSequence(const QString &sequence) 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, static int activationSequenceChar(const QChar &ch, const QChar &ch2,
const QChar &ch3, unsigned *kind, const QChar &ch3, unsigned *kind,
......
/****************************************************************************
**
** 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()
{
}
/****************************************************************************
**
** 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) ...@@ -259,9 +259,8 @@ CppModelManager::CppModelManager(QObject *parent)
qRegisterMetaType<CPlusPlus::Document::Ptr>("CPlusPlus::Document::Ptr"); qRegisterMetaType<CPlusPlus::Document::Ptr>("CPlusPlus::Document::Ptr");
m_completionFallback = new InternalCompletionAssistProvider; m_completionFallback.reset(new InternalCompletionAssistProvider);
m_completionAssistProvider = m_completionFallback; m_completionAssistProvider = m_completionFallback.data();
ExtensionSystem::PluginManager::addObject(m_completionAssistProvider);
m_highlightingFallback = new CppHighlightingSupportInternalFactory; m_highlightingFallback = new CppHighlightingSupportInternalFactory;
m_highlightingFactory = m_highlightingFallback; m_highlightingFactory = m_highlightingFallback;
m_internalIndexingSupport = new BuiltinIndexingSupport; m_internalIndexingSupport = new BuiltinIndexingSupport;
...@@ -269,8 +268,6 @@ CppModelManager::CppModelManager(QObject *parent) ...@@ -269,8 +268,6 @@ CppModelManager::CppModelManager(QObject *parent)
CppModelManager::~CppModelManager() CppModelManager::~CppModelManager()
{ {
ExtensionSystem::PluginManager::removeObject(m_completionAssistProvider);
delete m_completionFallback;
delete m_highlightingFallback; delete m_highlightingFallback;
delete m_internalIndexingSupport; delete m_internalIndexingSupport;
} }
...@@ -899,14 +896,6 @@ void CppModelManager::finishedRefreshingSourceFiles(const QStringList &files) ...@@ -899,14 +896,6 @@ void CppModelManager::finishedRefreshingSourceFiles(const QStringList &files)
emit sourceFilesRefreshed(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 CppCompletionAssistProvider *CppModelManager::completionAssistProvider(Core::IEditor *editor) const
{ {
Q_UNUSED(editor); Q_UNUSED(editor);
...@@ -916,12 +905,10 @@ CppCompletionAssistProvider *CppModelManager::completionAssistProvider(Core::IEd ...@@ -916,12 +905,10 @@ CppCompletionAssistProvider *CppModelManager::completionAssistProvider(Core::IEd
void CppModelManager::setCppCompletionAssistProvider(CppCompletionAssistProvider *completionAssistProvider) void CppModelManager::setCppCompletionAssistProvider(CppCompletionAssistProvider *completionAssistProvider)
{ {
ExtensionSystem::PluginManager::removeObject(m_completionAssistProvider);
if (completionAssistProvider) if (completionAssistProvider)
m_completionAssistProvider = completionAssistProvider; m_completionAssistProvider = completionAssistProvider;
else else
m_completionAssistProvider = m_completionFallback; m_completionAssistProvider = m_completionFallback.data();
ExtensionSystem::PluginManager::addObject(m_completionAssistProvider);
} }
CppHighlightingSupport *CppModelManager::highlightingSupport(Core::IEditor *editor) const CppHighlightingSupport *CppModelManager::highlightingSupport(Core::IEditor *editor) const
......
...@@ -104,7 +104,6 @@ public: ...@@ -104,7 +104,6 @@ public:
void finishedRefreshingSourceFiles(const QStringList &files); void finishedRefreshingSourceFiles(const QStringList &files);
virtual CppCompletionSupport *completionSupport(Core::IEditor *editor) const;
virtual CppCompletionAssistProvider *completionAssistProvider(Core::IEditor *editor) const; virtual CppCompletionAssistProvider *completionAssistProvider(Core::IEditor *editor) const;
virtual void setCppCompletionAssistProvider(CppCompletionAssistProvider *completionAssistProvider); virtual void setCppCompletionAssistProvider(CppCompletionAssistProvider *completionAssistProvider);
...@@ -204,7 +203,7 @@ private: ...@@ -204,7 +203,7 @@ private:
// Completion // Completion
CppCompletionAssistProvider *m_completionAssistProvider; CppCompletionAssistProvider *m_completionAssistProvider;
CppCompletionAssistProvider *m_completionFallback; QScopedPointer<CppCompletionAssistProvider> m_completionFallback;
// Highlighting // Highlighting
CppHighlightingSupportFactory *m_highlightingFactory; CppHighlightingSupportFactory *m_highlightingFactory;
......
...@@ -53,7 +53,6 @@ namespace CppTools { ...@@ -53,7 +53,6 @@ namespace CppTools {
class AbstractEditorSupport; class AbstractEditorSupport;
class CppCompletionAssistProvider; class CppCompletionAssistProvider;
class CppCompletionSupport;
class CppEditorSupport; class CppEditorSupport;
class CppHighlightingSupport; class CppHighlightingSupport;
class CppHighlightingSupportFactory; class CppHighlightingSupportFactory;
...@@ -241,7 +240,6 @@ public: ...@@ -241,7 +240,6 @@ public:
virtual void setIfdefedOutBlocks(const QString &fileName, virtual void setIfdefedOutBlocks(const QString &fileName,
const QList<TextEditor::BlockRange> &ifdeffedOutBlocks) = 0; const QList<TextEditor::BlockRange> &ifdeffedOutBlocks) = 0;
virtual CppTools::CppCompletionSupport *completionSupport(Core::IEditor *editor) const = 0;
virtual CppCompletionAssistProvider *completionAssistProvider(Core::IEditor *editor) const = 0; virtual CppCompletionAssistProvider *completionAssistProvider(Core::IEditor *editor) const = 0;
virtual void setCppCompletionAssistProvider(CppTools::CppCompletionAssistProvider *completionAssistProvider) = 0; virtual void setCppCompletionAssistProvider(CppTools::CppCompletionAssistProvider *completionAssistProvider) = 0;
......
...@@ -32,7 +32,6 @@ HEADERS += completionsettingspage.h \ ...@@ -32,7 +32,6 @@ HEADERS += completionsettingspage.h \
doxygengenerator.h \ doxygengenerator.h \
commentssettings.h \ commentssettings.h \
symbolfinder.h \ symbolfinder.h \
cppcompletionsupport.h \
cpphighlightingsupport.h \ cpphighlightingsupport.h \
cpphighlightingsupportinternal.h \ cpphighlightingsupportinternal.h \
cppchecksymbols.h \ cppchecksymbols.h \
...@@ -77,7 +76,6 @@ SOURCES += completionsettingspage.cpp \ ...@@ -77,7 +76,6 @@ SOURCES += completionsettingspage.cpp \
doxygengenerator.cpp \ doxygengenerator.cpp \
commentssettings.cpp \ commentssettings.cpp \
symbolfinder.cpp \ symbolfinder.cpp \
cppcompletionsupport.cpp \
cpphighlightingsupport.cpp \ cpphighlightingsupport.cpp \
cpphighlightingsupportinternal.cpp \ cpphighlightingsupportinternal.cpp \
cppchecksymbols.cpp \ cppchecksymbols.cpp \
......
...@@ -43,8 +43,6 @@ QtcPlugin { ...@@ -43,8 +43,6 @@ QtcPlugin {
"cppcompletionassist.h", "cppcompletionassist.h",
"cppcompletionassistprovider.cpp", "cppcompletionassistprovider.cpp",
"cppcompletionassistprovider.h", "cppcompletionassistprovider.h",
"cppcompletionsupport.cpp",
"cppcompletionsupport.h",
"cppcurrentdocumentfilter.cpp", "cppcurrentdocumentfilter.cpp",
"cppcurrentdocumentfilter.h", "cppcurrentdocumentfilter.h",
"cppdoxygen.cpp", "cppdoxygen.cpp",
......
...@@ -232,7 +232,7 @@ void CppEditorSupport::recalculateSemanticInfoDetached(bool force) ...@@ -232,7 +232,7 @@ void CppEditorSupport::recalculateSemanticInfoDetached(bool force)
CppCompletionAssistProvider *CppEditorSupport::completionAssistProvider() const CppCompletionAssistProvider *CppEditorSupport::completionAssistProvider() const
{ {
return m_completionAssistProvider.data(); return m_completionAssistProvider;
} }
void CppEditorSupport::updateDocument() void CppEditorSupport::updateDocument()
...@@ -526,6 +526,8 @@ void CppEditorSupport::onMimeTypeChanged() ...@@ -526,6 +526,8 @@ void CppEditorSupport::onMimeTypeChanged()
connect(this, SIGNAL(semanticInfoUpdated(CppTools::SemanticInfo)), connect(this, SIGNAL(semanticInfoUpdated(CppTools::SemanticInfo)),
this, SLOT(startHighlighting())); this, SLOT(startHighlighting()));
m_completionAssistProvider = m_modelManager->completionAssistProvider(m_textEditor);
updateDocumentNow(); updateDocumentNow();
} }
......
...@@ -195,7 +195,7 @@ private: ...@@ -195,7 +195,7 @@ private:
QScopedPointer<CppTools::CppHighlightingSupport> m_highlightingSupport; QScopedPointer<CppTools::CppHighlightingSupport> m_highlightingSupport;
// Completion: // Completion:
QScopedPointer<CppCompletionAssistProvider> m_completionAssistProvider; CppCompletionAssistProvider *m_completionAssistProvider;
}; };
} // namespace CppTools } // namespace CppTools
......
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