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