Commit df1bbb07 authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppTools: Extract base class CppCompletionAssistProcessor

As as side effect, this also brings some more pragma completions for the
builtin-in completion engine, e.g. "pragma once" or "pragma omp atomic".

Change-Id: If3ef22076c331c653b78a87cfff836c1da38c8fb
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@theqtcompany.com>
parent 6d22df7d
...@@ -560,37 +560,7 @@ ClangCompletionAssistInterface::ClangCompletionAssistInterface(ClangCompleter::P ...@@ -560,37 +560,7 @@ ClangCompletionAssistInterface::ClangCompletionAssistInterface(ClangCompleter::P
} }
ClangCompletionAssistProcessor::ClangCompletionAssistProcessor() ClangCompletionAssistProcessor::ClangCompletionAssistProcessor()
: m_preprocessorCompletions(QStringList() : m_model(new ClangAssistProposalModel)
<< QLatin1String("define")
<< QLatin1String("error")
<< QLatin1String("include")
<< QLatin1String("line")
<< QLatin1String("pragma")
<< QLatin1String("pragma once")
<< QLatin1String("pragma omp atomic")
<< QLatin1String("pragma omp parallel")
<< QLatin1String("pragma omp for")
<< QLatin1String("pragma omp ordered")
<< QLatin1String("pragma omp parallel for")
<< QLatin1String("pragma omp section")
<< QLatin1String("pragma omp sections")
<< QLatin1String("pragma omp parallel sections")
<< QLatin1String("pragma omp single")
<< QLatin1String("pragma omp master")
<< QLatin1String("pragma omp critical")
<< QLatin1String("pragma omp barrier")
<< QLatin1String("pragma omp flush")
<< QLatin1String("pragma omp threadprivate")
<< QLatin1String("undef")
<< QLatin1String("if")
<< QLatin1String("ifdef")
<< QLatin1String("ifndef")
<< QLatin1String("elif")
<< QLatin1String("else")
<< QLatin1String("endif"))
, m_model(new ClangAssistProposalModel)
, m_hintProposal(0)
{ {
} }
......
...@@ -35,13 +35,13 @@ ...@@ -35,13 +35,13 @@
#include <cplusplus/Icons.h> #include <cplusplus/Icons.h>
#include <cpptools/cppcompletionassistprocessor.h>
#include <cpptools/cppcompletionassistprovider.h> #include <cpptools/cppcompletionassistprovider.h>
#include <cpptools/cppmodelmanager.h> #include <cpptools/cppmodelmanager.h>
#include <texteditor/codeassist/assistproposalitem.h> #include <texteditor/codeassist/assistproposalitem.h>
#include <texteditor/codeassist/completionassistprovider.h> #include <texteditor/codeassist/completionassistprovider.h>
#include <texteditor/codeassist/assistinterface.h> #include <texteditor/codeassist/assistinterface.h>
#include <texteditor/codeassist/iassistprocessor.h>
#include <QStringList> #include <QStringList>
#include <QTextCursor> #include <QTextCursor>
...@@ -102,7 +102,7 @@ private: ...@@ -102,7 +102,7 @@ private:
Internal::PchInfo::Ptr m_savedPchPointer; Internal::PchInfo::Ptr m_savedPchPointer;
}; };
class CLANG_EXPORT ClangCompletionAssistProcessor : public TextEditor::IAssistProcessor class CLANG_EXPORT ClangCompletionAssistProcessor : public CppTools::CppCompletionAssistProcessor
{ {
Q_DECLARE_TR_FUNCTIONS(ClangCodeModel::Internal::ClangCompletionAssistProcessor) Q_DECLARE_TR_FUNCTIONS(ClangCodeModel::Internal::ClangCompletionAssistProcessor)
...@@ -132,13 +132,8 @@ private: ...@@ -132,13 +132,8 @@ private:
const QVariant &data = QVariant()); const QVariant &data = QVariant());
private: private:
int m_startPosition;
QScopedPointer<const ClangCompletionAssistInterface> m_interface; QScopedPointer<const ClangCompletionAssistInterface> m_interface;
QList<TextEditor::AssistProposalItem *> m_completions;
CPlusPlus::Icons m_icons;
QStringList m_preprocessorCompletions;
QScopedPointer<Internal::ClangAssistProposalModel> m_model; QScopedPointer<Internal::ClangAssistProposalModel> m_model;
TextEditor::IAssistProposal *m_hintProposal;
}; };
} // namespace Clang } // namespace Clang
......
...@@ -602,24 +602,7 @@ bool isQPrivateSignal(const Symbol *symbol) ...@@ -602,24 +602,7 @@ bool isQPrivateSignal(const Symbol *symbol)
// InternalCppCompletionAssistProcessor // InternalCppCompletionAssistProcessor
// ------------------------------------ // ------------------------------------
InternalCppCompletionAssistProcessor::InternalCppCompletionAssistProcessor() InternalCppCompletionAssistProcessor::InternalCppCompletionAssistProcessor()
: m_startPosition(-1) : m_model(new CppAssistProposalModel)
, m_snippetCollector(QLatin1String(CppEditor::Constants::CPP_SNIPPETS_GROUP_ID),
QIcon(QLatin1String(":/texteditor/images/snippet.png")))
, 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"))
, m_model(new CppAssistProposalModel)
, m_hintProposal(0)
{ {
// FIXME: C++11? // FIXME: C++11?
m_languageFeatures.objCEnabled = true; m_languageFeatures.objCEnabled = true;
...@@ -1176,7 +1159,7 @@ void InternalCppCompletionAssistProcessor::completeInclude(const QString &realPa ...@@ -1176,7 +1159,7 @@ void InternalCppCompletionAssistProcessor::completeInclude(const QString &realPa
void InternalCppCompletionAssistProcessor::completePreprocessor() void InternalCppCompletionAssistProcessor::completePreprocessor()
{ {
foreach (const QString &preprocessorCompletion, preprocessorCompletions) foreach (const QString &preprocessorCompletion, m_preprocessorCompletions)
addCompletionItem(preprocessorCompletion); addCompletionItem(preprocessorCompletion);
if (objcKeywordsWanted()) if (objcKeywordsWanted())
...@@ -1706,11 +1689,6 @@ bool InternalCppCompletionAssistProcessor::completeQtMethod( ...@@ -1706,11 +1689,6 @@ bool InternalCppCompletionAssistProcessor::completeQtMethod(
return !m_completions.isEmpty(); return !m_completions.isEmpty();
} }
void InternalCppCompletionAssistProcessor::addSnippets()
{
m_completions.append(m_snippetCollector.collect());
}
void InternalCppCompletionAssistProcessor::addKeywords() void InternalCppCompletionAssistProcessor::addKeywords()
{ {
int keywordLimit = T_FIRST_OBJC_AT_KEYWORD; int keywordLimit = T_FIRST_OBJC_AT_KEYWORD;
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#ifndef CPPCOMPLETIONASSIST_H #ifndef CPPCOMPLETIONASSIST_H
#define CPPCOMPLETIONASSIST_H #define CPPCOMPLETIONASSIST_H
#include "cppcompletionassistprocessor.h"
#include "cppcompletionassistprovider.h" #include "cppcompletionassistprovider.h"
#include "cppmodelmanager.h" #include "cppmodelmanager.h"
#include "cppworkingcopy.h" #include "cppworkingcopy.h"
...@@ -96,7 +97,7 @@ public: ...@@ -96,7 +97,7 @@ public:
TextEditor::AssistReason reason) const Q_DECL_OVERRIDE; TextEditor::AssistReason reason) const Q_DECL_OVERRIDE;
}; };
class InternalCppCompletionAssistProcessor : public TextEditor::IAssistProcessor class InternalCppCompletionAssistProcessor : public CppCompletionAssistProcessor
{ {
public: public:
InternalCppCompletionAssistProcessor(); InternalCppCompletionAssistProcessor();
...@@ -144,7 +145,6 @@ private: ...@@ -144,7 +145,6 @@ private:
const QVariant &data = QVariant()); const QVariant &data = QVariant());
void addCompletionItem(CPlusPlus::Symbol *symbol, void addCompletionItem(CPlusPlus::Symbol *symbol,
int order = 0); int order = 0);
void addSnippets();
void addKeywords(); void addKeywords();
void addMacros(const QString &fileName, const CPlusPlus::Snapshot &snapshot); void addMacros(const QString &fileName, const CPlusPlus::Snapshot &snapshot);
void addMacros_helper(const CPlusPlus::Snapshot &snapshot, void addMacros_helper(const CPlusPlus::Snapshot &snapshot,
...@@ -152,15 +152,9 @@ private: ...@@ -152,15 +152,9 @@ private:
QSet<QString> *processed, QSet<QString> *processed,
QSet<QString> *definedMacros); QSet<QString> *definedMacros);
int m_startPosition;
CPlusPlus::LanguageFeatures m_languageFeatures; CPlusPlus::LanguageFeatures m_languageFeatures;
QScopedPointer<const CppCompletionAssistInterface> m_interface; QScopedPointer<const CppCompletionAssistInterface> m_interface;
QList<TextEditor::AssistProposalItem *> m_completions;
TextEditor::SnippetAssistCollector m_snippetCollector;
CPlusPlus::Icons m_icons;
QStringList preprocessorCompletions;
QScopedPointer<CppAssistProposalModel> m_model; QScopedPointer<CppAssistProposalModel> m_model;
TextEditor::IAssistProposal *m_hintProposal;
}; };
class CppCompletionAssistInterface : public TextEditor::AssistInterface class CppCompletionAssistInterface : public TextEditor::AssistInterface
......
/****************************************************************************
**
** Copyright (C) 2015 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://www.qt.io/licensing. For further information
** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** 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 "cppcompletionassistprocessor.h"
#include <cppeditor/cppeditorconstants.h>
namespace CppTools {
CppCompletionAssistProcessor::CppCompletionAssistProcessor()
: m_startPosition(-1)
, m_preprocessorCompletions(QStringList()
<< QLatin1String("define")
<< QLatin1String("error")
<< QLatin1String("include")
<< QLatin1String("line")
<< QLatin1String("pragma")
<< QLatin1String("pragma once")
<< QLatin1String("pragma omp atomic")
<< QLatin1String("pragma omp parallel")
<< QLatin1String("pragma omp for")
<< QLatin1String("pragma omp ordered")
<< QLatin1String("pragma omp parallel for")
<< QLatin1String("pragma omp section")
<< QLatin1String("pragma omp sections")
<< QLatin1String("pragma omp parallel sections")
<< QLatin1String("pragma omp single")
<< QLatin1String("pragma omp master")
<< QLatin1String("pragma omp critical")
<< QLatin1String("pragma omp barrier")
<< QLatin1String("pragma omp flush")
<< QLatin1String("pragma omp threadprivate")
<< QLatin1String("undef")
<< QLatin1String("if")
<< QLatin1String("ifdef")
<< QLatin1String("ifndef")
<< QLatin1String("elif")
<< QLatin1String("else")
<< QLatin1String("endif"))
, m_hintProposal(0)
, m_snippetCollector(QLatin1String(CppEditor::Constants::CPP_SNIPPETS_GROUP_ID),
QIcon(QLatin1String(":/texteditor/images/snippet.png")))
{
}
void CppCompletionAssistProcessor::addSnippets()
{
m_completions.append(m_snippetCollector.collect());
}
} // namespace CppTools
/****************************************************************************
**
** Copyright (C) 2015 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://www.qt.io/licensing. For further information
** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** 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 CPPCOMPLETIONASSISTPROCESSOR_H
#define CPPCOMPLETIONASSISTPROCESSOR_H
#include "cpptools_global.h"
#include <texteditor/codeassist/iassistprocessor.h>
#include <texteditor/snippets/snippetassistcollector.h>
#include <cplusplus/Icons.h>
namespace CppTools {
class CPPTOOLS_EXPORT CppCompletionAssistProcessor : public TextEditor::IAssistProcessor
{
public:
CppCompletionAssistProcessor();
protected:
void addSnippets();
int m_startPosition;
QList<TextEditor::AssistProposalItem *> m_completions;
QStringList m_preprocessorCompletions;
TextEditor::IAssistProposal *m_hintProposal;
CPlusPlus::Icons m_icons;
private:
TextEditor::SnippetAssistCollector m_snippetCollector;
};
} // namespace CppTools
#endif // CPPCOMPLETIONASSISTPROCESSOR_H
...@@ -22,6 +22,7 @@ HEADERS += \ ...@@ -22,6 +22,7 @@ HEADERS += \
cppcodestylesettings.h \ cppcodestylesettings.h \
cppcodestylesettingspage.h \ cppcodestylesettingspage.h \
cppcompletionassist.h \ cppcompletionassist.h \
cppcompletionassistprocessor.h \
cppcompletionassistprovider.h \ cppcompletionassistprovider.h \
cppcurrentdocumentfilter.h \ cppcurrentdocumentfilter.h \
cppdoxygen.h \ cppdoxygen.h \
...@@ -84,6 +85,7 @@ SOURCES += \ ...@@ -84,6 +85,7 @@ SOURCES += \
cppcodestylesettings.cpp \ cppcodestylesettings.cpp \
cppcodestylesettingspage.cpp \ cppcodestylesettingspage.cpp \
cppcompletionassist.cpp \ cppcompletionassist.cpp \
cppcompletionassistprocessor.cpp \
cppcompletionassistprovider.cpp \ cppcompletionassistprovider.cpp \
cppcurrentdocumentfilter.cpp \ cppcurrentdocumentfilter.cpp \
cppdoxygen.cpp \ cppdoxygen.cpp \
......
...@@ -40,6 +40,7 @@ QtcPlugin { ...@@ -40,6 +40,7 @@ QtcPlugin {
"cppcodestylesettings.cpp", "cppcodestylesettings.h", "cppcodestylesettings.cpp", "cppcodestylesettings.h",
"cppcodestylesettingspage.cpp", "cppcodestylesettingspage.h", "cppcodestylesettingspage.ui", "cppcodestylesettingspage.cpp", "cppcodestylesettingspage.h", "cppcodestylesettingspage.ui",
"cppcompletionassist.cpp", "cppcompletionassist.h", "cppcompletionassist.cpp", "cppcompletionassist.h",
"cppcompletionassistprocessor.cpp", "cppcompletionassistprocessor.h",
"cppcompletionassistprovider.cpp", "cppcompletionassistprovider.h", "cppcompletionassistprovider.cpp", "cppcompletionassistprovider.h",
"cppcurrentdocumentfilter.cpp", "cppcurrentdocumentfilter.h", "cppcurrentdocumentfilter.cpp", "cppcurrentdocumentfilter.h",
"cppdoxygen.cpp", "cppdoxygen.h", "cppdoxygen.cpp", "cppdoxygen.h",
......
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