Commit 1a37605f authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

CppTools: Move languageFeatures around in CompletionAssist...

... from InternalCppCompletionAssistProcessor to CppCompletionAssistInterface

Change-Id: I769fd86a387f1087f37b56fe114bdf132f1b0be7
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent 2ffe50c2
...@@ -200,15 +200,14 @@ IAssistProcessor *ClangCompletionAssistProvider::createProcessor() const ...@@ -200,15 +200,14 @@ IAssistProcessor *ClangCompletionAssistProvider::createProcessor() const
} }
AssistInterface *ClangCompletionAssistProvider::createAssistInterface( AssistInterface *ClangCompletionAssistProvider::createAssistInterface(
const QString &filePath, const QString &filePath, QTextDocument *document,
QTextDocument *document, bool isObjCEnabled, int position, AssistReason reason) const const LanguageFeatures &languageFeatures, int position, AssistReason reason) const
{ {
Q_UNUSED(isObjCEnabled);
CppModelManager *modelManager = CppModelManager::instance(); CppModelManager *modelManager = CppModelManager::instance();
QList<ProjectPart::Ptr> parts = modelManager->projectPart(filePath); QList<ProjectPart::Ptr> parts = modelManager->projectPart(filePath);
if (parts.isEmpty()) if (parts.isEmpty())
parts += modelManager->fallbackProjectPart(); parts += modelManager->fallbackProjectPart();
LanguageFeatures features = languageFeatures;
ProjectPart::HeaderPaths headerPaths; ProjectPart::HeaderPaths headerPaths;
QStringList options; QStringList options;
PchInfo::Ptr pchInfo; PchInfo::Ptr pchInfo;
...@@ -220,13 +219,14 @@ AssistInterface *ClangCompletionAssistProvider::createAssistInterface( ...@@ -220,13 +219,14 @@ AssistInterface *ClangCompletionAssistProvider::createAssistInterface(
if (!pchInfo.isNull()) if (!pchInfo.isNull())
options.append(Utils::createPCHInclusionOptions(pchInfo->fileName())); options.append(Utils::createPCHInclusionOptions(pchInfo->fileName()));
headerPaths = part->headerPaths; headerPaths = part->headerPaths;
features = part->languageFeatures;
break; break;
} }
return new ClangCompletionAssistInterface( return new ClangCompletionAssistInterface(
m_clangCompletionWrapper, m_clangCompletionWrapper,
document, position, filePath, reason, document, position, filePath, reason,
options, headerPaths, pchInfo); options, headerPaths, pchInfo, features);
} }
// ------------------------ // ------------------------
...@@ -545,12 +545,14 @@ ClangCompletionAssistInterface::ClangCompletionAssistInterface(ClangCompleter::P ...@@ -545,12 +545,14 @@ ClangCompletionAssistInterface::ClangCompletionAssistInterface(ClangCompleter::P
AssistReason reason, AssistReason reason,
const QStringList &options, const QStringList &options,
const QList<ProjectPart::HeaderPath> &headerPaths, const QList<ProjectPart::HeaderPath> &headerPaths,
const PchInfo::Ptr &pchInfo) const PchInfo::Ptr &pchInfo,
const LanguageFeatures &features)
: AssistInterface(document, position, fileName, reason) : AssistInterface(document, position, fileName, reason)
, m_clangWrapper(clangWrapper) , m_clangWrapper(clangWrapper)
, m_options(options) , m_options(options)
, m_headerPaths(headerPaths) , m_headerPaths(headerPaths)
, m_savedPchPointer(pchInfo) , m_savedPchPointer(pchInfo)
, m_languageFeatures(features)
{ {
Q_ASSERT(!clangWrapper.isNull()); Q_ASSERT(!clangWrapper.isNull());
...@@ -711,10 +713,7 @@ int ClangCompletionAssistProcessor::startOfOperator(int pos, ...@@ -711,10 +713,7 @@ int ClangCompletionAssistProcessor::startOfOperator(int pos,
} }
SimpleLexer tokenize; SimpleLexer tokenize;
LanguageFeatures lf = tokenize.languageFeatures(); tokenize.setLanguageFeatures(m_interface->languageFeatures());
lf.qtMocRunEnabled = true;
lf.objCEnabled = true;
tokenize.setLanguageFeatures(lf);
tokenize.setSkipComments(false); tokenize.setSkipComments(false);
const Tokens &tokens = tokenize(tc.block().text(), BackwardsScanner::previousBlockState(tc.block())); const Tokens &tokens = tokenize(tc.block().text(), BackwardsScanner::previousBlockState(tc.block()));
const int tokenIdx = SimpleLexer::tokenBefore(tokens, qMax(0, tc.positionInBlock() - 1)); // get the token at the left of the cursor const int tokenIdx = SimpleLexer::tokenBefore(tokens, qMax(0, tc.positionInBlock() - 1)); // get the token at the left of the cursor
......
...@@ -58,9 +58,9 @@ public: ...@@ -58,9 +58,9 @@ public:
virtual TextEditor::IAssistProcessor *createProcessor() const; virtual TextEditor::IAssistProcessor *createProcessor() const;
virtual TextEditor::AssistInterface *createAssistInterface( virtual TextEditor::AssistInterface *createAssistInterface(
const QString &filePath, const QString &filePath, QTextDocument *document,
QTextDocument *document, bool isObjCEnabled, int position, const CPlusPlus::LanguageFeatures &languageFeatures,
TextEditor::AssistReason reason) const; int position, TextEditor::AssistReason reason) const;
private: private:
ClangCodeModel::ClangCompleter::Ptr m_clangCompletionWrapper; ClangCodeModel::ClangCompleter::Ptr m_clangCompletionWrapper;
...@@ -78,7 +78,8 @@ public: ...@@ -78,7 +78,8 @@ public:
TextEditor::AssistReason reason, TextEditor::AssistReason reason,
const QStringList &options, const QStringList &options,
const QList<CppTools::ProjectPart::HeaderPath> &headerPaths, const QList<CppTools::ProjectPart::HeaderPath> &headerPaths,
const Internal::PchInfo::Ptr &pchInfo); const Internal::PchInfo::Ptr &pchInfo,
const CPlusPlus::LanguageFeatures &features);
ClangCodeModel::ClangCompleter::Ptr clangWrapper() const ClangCodeModel::ClangCompleter::Ptr clangWrapper() const
{ return m_clangWrapper; } { return m_clangWrapper; }
...@@ -94,12 +95,16 @@ public: ...@@ -94,12 +95,16 @@ public:
const QList<CppTools::ProjectPart::HeaderPath> &headerPaths() const const QList<CppTools::ProjectPart::HeaderPath> &headerPaths() const
{ return m_headerPaths; } { return m_headerPaths; }
CPlusPlus::LanguageFeatures languageFeatures() const
{ return m_languageFeatures; }
private: private:
ClangCodeModel::ClangCompleter::Ptr m_clangWrapper; ClangCodeModel::ClangCompleter::Ptr m_clangWrapper;
ClangCodeModel::Internal::UnsavedFiles m_unsavedFiles; ClangCodeModel::Internal::UnsavedFiles m_unsavedFiles;
QStringList m_options; QStringList m_options;
QList<CppTools::ProjectPart::HeaderPath> m_headerPaths; QList<CppTools::ProjectPart::HeaderPath> m_headerPaths;
Internal::PchInfo::Ptr m_savedPchPointer; Internal::PchInfo::Ptr m_savedPchPointer;
CPlusPlus::LanguageFeatures m_languageFeatures;
}; };
class CLANG_EXPORT ClangCompletionAssistProcessor : public CppTools::CppCompletionAssistProcessor class CLANG_EXPORT ClangCompletionAssistProcessor : public CppTools::CppCompletionAssistProcessor
......
...@@ -612,10 +612,14 @@ AssistInterface *CppEditorWidget::createAssistInterface(AssistKind kind, AssistR ...@@ -612,10 +612,14 @@ AssistInterface *CppEditorWidget::createAssistInterface(AssistKind kind, AssistR
if (kind == Completion) { if (kind == Completion) {
if (CppCompletionAssistProvider *cap = if (CppCompletionAssistProvider *cap =
qobject_cast<CppCompletionAssistProvider *>(cppEditorDocument()->completionAssistProvider())) { qobject_cast<CppCompletionAssistProvider *>(cppEditorDocument()->completionAssistProvider())) {
LanguageFeatures features = LanguageFeatures::defaultFeatures();
if (Document::Ptr doc = d->m_lastSemanticInfo.doc)
features = doc->languageFeatures();
features.objCEnabled = cppEditorDocument()->isObjCEnabled();
return cap->createAssistInterface( return cap->createAssistInterface(
textDocument()->filePath().toString(), textDocument()->filePath().toString(),
document(), document(),
cppEditorDocument()->isObjCEnabled(), features,
position(), position(),
reason); reason);
} }
......
...@@ -105,11 +105,14 @@ public: ...@@ -105,11 +105,14 @@ public:
QStringList getCompletions(bool *replaceAccessOperator = 0) const QStringList getCompletions(bool *replaceAccessOperator = 0) const
{ {
QStringList completions; QStringList completions;
LanguageFeatures languageFeatures = LanguageFeatures::defaultFeatures();
languageFeatures.objCEnabled = false;
CppCompletionAssistInterface *ai CppCompletionAssistInterface *ai
= new CppCompletionAssistInterface(m_editorWidget->textDocument()->filePath().toString(), = new CppCompletionAssistInterface(m_editorWidget->textDocument()->filePath().toString(),
m_editorWidget->document(), m_position, m_editorWidget->document(), m_position,
ExplicitlyInvoked, m_snapshot, ExplicitlyInvoked, m_snapshot,
ProjectPart::HeaderPaths()); ProjectPart::HeaderPaths(),
languageFeatures);
InternalCppCompletionAssistProcessor processor; InternalCppCompletionAssistProcessor processor;
const Tests::IAssistProposalScopedPointer proposal(processor.perform(ai)); const Tests::IAssistProposalScopedPointer proposal(processor.perform(ai));
......
...@@ -419,12 +419,12 @@ IAssistProcessor *InternalCompletionAssistProvider::createProcessor() const ...@@ -419,12 +419,12 @@ IAssistProcessor *InternalCompletionAssistProvider::createProcessor() const
AssistInterface *InternalCompletionAssistProvider::createAssistInterface( AssistInterface *InternalCompletionAssistProvider::createAssistInterface(
const QString &filePath, QTextDocument *document, const QString &filePath, QTextDocument *document,
bool isObjCEnabled, int position, AssistReason reason) const const LanguageFeatures &languageFeatures, int position, AssistReason reason) const
{ {
QTC_ASSERT(document, return 0); QTC_ASSERT(document, return 0);
CppModelManager *modelManager = CppModelManager::instance(); CppModelManager *modelManager = CppModelManager::instance();
return new CppCompletionAssistInterface(filePath, document, isObjCEnabled, position, reason, return new CppCompletionAssistInterface(filePath, document, languageFeatures, position, reason,
modelManager->workingCopy()); modelManager->workingCopy());
} }
...@@ -803,11 +803,6 @@ const Name *minimalName(Symbol *symbol, Scope *targetScope, const LookupContext ...@@ -803,11 +803,6 @@ const Name *minimalName(Symbol *symbol, Scope *targetScope, const LookupContext
InternalCppCompletionAssistProcessor::InternalCppCompletionAssistProcessor() InternalCppCompletionAssistProcessor::InternalCppCompletionAssistProcessor()
: m_model(new CppAssistProposalModel) : m_model(new CppAssistProposalModel)
{ {
// FIXME: C++11?
m_languageFeatures.objCEnabled = true;
m_languageFeatures.qtEnabled = true;
m_languageFeatures.qtKeywordsEnabled = true;
m_languageFeatures.qtMocRunEnabled = true;
} }
InternalCppCompletionAssistProcessor::~InternalCppCompletionAssistProcessor() InternalCppCompletionAssistProcessor::~InternalCppCompletionAssistProcessor()
...@@ -858,14 +853,8 @@ bool InternalCppCompletionAssistProcessor::accepts() const ...@@ -858,14 +853,8 @@ bool InternalCppCompletionAssistProcessor::accepts() const
QTextCursor tc(m_interface->textDocument()); QTextCursor tc(m_interface->textDocument());
tc.setPosition(pos); tc.setPosition(pos);
LanguageFeatures features;
features.qtEnabled = true;
features.qtMocRunEnabled = true;
features.qtKeywordsEnabled = true;
features.objCEnabled = true;
SimpleLexer tokenize; SimpleLexer tokenize;
tokenize.setLanguageFeatures(features); tokenize.setLanguageFeatures(m_interface->languageFeatures());
tokenize.setSkipComments(false); tokenize.setSkipComments(false);
const Tokens &tokens = tokenize(tc.block().text(), BackwardsScanner::previousBlockState(tc.block())); const Tokens &tokens = tokenize(tc.block().text(), BackwardsScanner::previousBlockState(tc.block()));
...@@ -885,7 +874,7 @@ bool InternalCppCompletionAssistProcessor::accepts() const ...@@ -885,7 +874,7 @@ bool InternalCppCompletionAssistProcessor::accepts() const
idToken.utf16charsEnd() - idToken.utf16charsBegin()); idToken.utf16charsEnd() - idToken.utf16charsBegin());
if (identifier == QLatin1String("include") if (identifier == QLatin1String("include")
|| identifier == QLatin1String("include_next") || identifier == QLatin1String("include_next")
|| (m_languageFeatures.objCEnabled && identifier == QLatin1String("import"))) { || (m_interface->languageFeatures().objCEnabled && identifier == QLatin1String("import"))) {
return true; return true;
} }
} }
...@@ -970,7 +959,7 @@ int InternalCppCompletionAssistProcessor::startOfOperator(int pos, ...@@ -970,7 +959,7 @@ int InternalCppCompletionAssistProcessor::startOfOperator(int pos,
} }
SimpleLexer tokenize; SimpleLexer tokenize;
tokenize.setLanguageFeatures(m_languageFeatures); tokenize.setLanguageFeatures(m_interface->languageFeatures());
tokenize.setSkipComments(false); tokenize.setSkipComments(false);
const Tokens &tokens = tokenize(tc.block().text(), BackwardsScanner::previousBlockState(tc.block())); const Tokens &tokens = tokenize(tc.block().text(), BackwardsScanner::previousBlockState(tc.block()));
const int tokenIdx = SimpleLexer::tokenBefore(tokens, qMax(0, tc.positionInBlock() - 1)); // get the token at the left of the cursor const int tokenIdx = SimpleLexer::tokenBefore(tokens, qMax(0, tc.positionInBlock() - 1)); // get the token at the left of the cursor
...@@ -1066,7 +1055,7 @@ int InternalCppCompletionAssistProcessor::findStartOfName(int pos) const ...@@ -1066,7 +1055,7 @@ int InternalCppCompletionAssistProcessor::findStartOfName(int pos) const
int InternalCppCompletionAssistProcessor::startCompletionHelper() int InternalCppCompletionAssistProcessor::startCompletionHelper()
{ {
if (m_languageFeatures.objCEnabled) { if (m_interface->languageFeatures().objCEnabled) {
if (tryObjCCompletion()) if (tryObjCCompletion())
return m_startPosition; return m_startPosition;
} }
...@@ -1387,7 +1376,7 @@ void InternalCppCompletionAssistProcessor::completePreprocessor() ...@@ -1387,7 +1376,7 @@ void InternalCppCompletionAssistProcessor::completePreprocessor()
bool InternalCppCompletionAssistProcessor::objcKeywordsWanted() const bool InternalCppCompletionAssistProcessor::objcKeywordsWanted() const
{ {
if (!m_languageFeatures.objCEnabled) if (!m_interface->languageFeatures().objCEnabled)
return false; return false;
const QString fileName = m_interface->fileName(); const QString fileName = m_interface->fileName();
...@@ -1618,7 +1607,7 @@ bool InternalCppCompletionAssistProcessor::completeMember(const QList<LookupItem ...@@ -1618,7 +1607,7 @@ bool InternalCppCompletionAssistProcessor::completeMember(const QList<LookupItem
ResolveExpression resolveExpression(context); ResolveExpression resolveExpression(context);
bool *replaceDotForArrow = 0; bool *replaceDotForArrow = 0;
if (!m_interface->isObjCEnabled()) if (!m_interface->languageFeatures().objCEnabled)
replaceDotForArrow = &m_model->m_replaceDotForArrow; replaceDotForArrow = &m_model->m_replaceDotForArrow;
if (ClassOrNamespace *binding = if (ClassOrNamespace *binding =
...@@ -2181,5 +2170,9 @@ void CppCompletionAssistInterface::getCppSpecifics() const ...@@ -2181,5 +2170,9 @@ void CppCompletionAssistInterface::getCppSpecifics() const
parser->update(m_workingCopy); parser->update(m_workingCopy);
m_snapshot = parser->snapshot(); m_snapshot = parser->snapshot();
m_headerPaths = parser->headerPaths(); m_headerPaths = parser->headerPaths();
if (Document::Ptr document = parser->document())
m_languageFeatures = document->languageFeatures();
else
m_languageFeatures = LanguageFeatures::defaultFeatures();
} }
} }
...@@ -92,7 +92,7 @@ public: ...@@ -92,7 +92,7 @@ public:
TextEditor::AssistInterface *createAssistInterface( TextEditor::AssistInterface *createAssistInterface(
const QString &filePath, const QString &filePath,
QTextDocument *document, QTextDocument *document,
bool isObjCEnabled, const CPlusPlus::LanguageFeatures &languageFeatures,
int position, int position,
TextEditor::AssistReason reason) const Q_DECL_OVERRIDE; TextEditor::AssistReason reason) const Q_DECL_OVERRIDE;
}; };
...@@ -162,7 +162,6 @@ private: ...@@ -162,7 +162,6 @@ private:
CompleteQt5SlotTrigger CompleteQt5SlotTrigger
}; };
CPlusPlus::LanguageFeatures m_languageFeatures;
QScopedPointer<const CppCompletionAssistInterface> m_interface; QScopedPointer<const CppCompletionAssistInterface> m_interface;
QScopedPointer<CppAssistProposalModel> m_model; QScopedPointer<CppAssistProposalModel> m_model;
}; };
...@@ -172,14 +171,14 @@ class CppCompletionAssistInterface : public TextEditor::AssistInterface ...@@ -172,14 +171,14 @@ class CppCompletionAssistInterface : public TextEditor::AssistInterface
public: public:
CppCompletionAssistInterface(const QString &filePath, CppCompletionAssistInterface(const QString &filePath,
QTextDocument *textDocument, QTextDocument *textDocument,
bool isObjCEnabled, const CPlusPlus::LanguageFeatures &languageFeatures,
int position, int position,
TextEditor::AssistReason reason, TextEditor::AssistReason reason,
const WorkingCopy &workingCopy) const WorkingCopy &workingCopy)
: TextEditor::AssistInterface(textDocument, position, filePath, reason) : TextEditor::AssistInterface(textDocument, position, filePath, reason)
, m_isObjCEnabled(isObjCEnabled)
, m_gotCppSpecifics(false) , m_gotCppSpecifics(false)
, m_workingCopy(workingCopy) , m_workingCopy(workingCopy)
, m_languageFeatures(languageFeatures)
{} {}
CppCompletionAssistInterface(const QString &filePath, CppCompletionAssistInterface(const QString &filePath,
...@@ -187,28 +186,29 @@ public: ...@@ -187,28 +186,29 @@ public:
int position, int position,
TextEditor::AssistReason reason, TextEditor::AssistReason reason,
const CPlusPlus::Snapshot &snapshot, const CPlusPlus::Snapshot &snapshot,
const ProjectPart::HeaderPaths &headerPaths) const ProjectPart::HeaderPaths &headerPaths,
const CPlusPlus::LanguageFeatures &features)
: TextEditor::AssistInterface(textDocument, position, filePath, reason) : TextEditor::AssistInterface(textDocument, position, filePath, reason)
, m_isObjCEnabled(false)
, m_gotCppSpecifics(true) , m_gotCppSpecifics(true)
, m_snapshot(snapshot) , m_snapshot(snapshot)
, m_headerPaths(headerPaths) , m_headerPaths(headerPaths)
, m_languageFeatures(features)
{} {}
bool isObjCEnabled() const { return m_isObjCEnabled; }
const CPlusPlus::Snapshot &snapshot() const { getCppSpecifics(); return m_snapshot; } const CPlusPlus::Snapshot &snapshot() const { getCppSpecifics(); return m_snapshot; }
const ProjectPart::HeaderPaths &headerPaths() const const ProjectPart::HeaderPaths &headerPaths() const
{ getCppSpecifics(); return m_headerPaths; } { getCppSpecifics(); return m_headerPaths; }
CPlusPlus::LanguageFeatures languageFeatures() const
{ getCppSpecifics(); return m_languageFeatures; }
private: private:
void getCppSpecifics() const; void getCppSpecifics() const;
mutable bool m_isObjCEnabled;
mutable bool m_gotCppSpecifics; mutable bool m_gotCppSpecifics;
WorkingCopy m_workingCopy; WorkingCopy m_workingCopy;
mutable CPlusPlus::Snapshot m_snapshot; mutable CPlusPlus::Snapshot m_snapshot;
mutable ProjectPart::HeaderPaths m_headerPaths; mutable ProjectPart::HeaderPaths m_headerPaths;
mutable CPlusPlus::LanguageFeatures m_languageFeatures;
}; };
} // Internal } // Internal
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <texteditor/codeassist/assistenums.h> #include <texteditor/codeassist/assistenums.h>
#include <texteditor/codeassist/completionassistprovider.h> #include <texteditor/codeassist/completionassistprovider.h>
#include <cplusplus/Token.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QTextDocument; class QTextDocument;
...@@ -60,7 +61,9 @@ public: ...@@ -60,7 +61,9 @@ public:
virtual TextEditor::AssistInterface *createAssistInterface( virtual TextEditor::AssistInterface *createAssistInterface(
const QString &filePath, const QString &filePath,
QTextDocument *document, bool isObjCEnabled, int position, QTextDocument *document,
const CPlusPlus::LanguageFeatures &languageFeatures,
int position,
TextEditor::AssistReason reason) const = 0; TextEditor::AssistReason reason) const = 0;
static int activationSequenceChar(const QChar &ch, const QChar &ch2, static int activationSequenceChar(const QChar &ch, const QChar &ch2,
......
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