summaryrefslogtreecommitdiff
path: root/src/plugins/clangcodemodel
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@qt.io>2018-10-24 10:05:53 +0200
committerNikolai Kosjar <nikolai.kosjar@qt.io>2018-10-25 12:13:57 +0000
commitd946ff540312210f1da8cc509c474a39da45117c (patch)
treed0c5fda0396b8946015e937d293d13d798804dd9 /src/plugins/clangcodemodel
parent7d3686359aeba2b5ce4abac8fa18b81021e71ea0 (diff)
downloadqt-creator-d946ff540312210f1da8cc509c474a39da45117c.tar.gz
Clang: Fix adding completion snippets after {
...e.g. as in "void f() {". The criteria whether to change snippets got invalidated with commit 8d0391a4f9b91fb15ee3d20db725c7a37c4646aa Clang: Treat brace initialization as constructor completion as the completion operator might be T_LBRACE now instead of T_EOF_SYMBOL for normal completions. This fixes the plugin test ClangCodeCompletionTest::testCompleteGlobals. Add also unit tests. Change-Id: I85cf522b9b307359c5c3e25198dd228cbb68ded0 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Diffstat (limited to 'src/plugins/clangcodemodel')
-rw-r--r--src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp2
-rw-r--r--src/plugins/clangcodemodel/clangcompletioncontextanalyzer.cpp3
-rw-r--r--src/plugins/clangcodemodel/clangcompletioncontextanalyzer.h2
3 files changed, 6 insertions, 1 deletions
diff --git a/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp b/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp
index b16f458ca5..fec7b69dab 100644
--- a/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp
+++ b/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp
@@ -262,6 +262,7 @@ IAssistProposal *ClangCompletionAssistProcessor::startCompletionHelper()
analyzer.analyze();
m_completionOperator = analyzer.completionOperator();
m_positionForProposal = analyzer.positionForProposal();
+ m_addSnippets = analyzer.addSnippets();
QByteArray modifiedFileContent;
@@ -285,7 +286,6 @@ IAssistProposal *ClangCompletionAssistProcessor::startCompletionHelper()
analyzer.positionEndOfExpression());
Q_FALLTHROUGH();
case ClangCompletionContextAnalyzer::PassThroughToLibClang: {
- m_addSnippets = m_completionOperator == T_EOF_SYMBOL;
m_sentRequestType = NormalCompletion;
m_requestSent = sendCompletionRequest(analyzer.positionForClang(),
modifiedFileContent);
diff --git a/src/plugins/clangcodemodel/clangcompletioncontextanalyzer.cpp b/src/plugins/clangcodemodel/clangcompletioncontextanalyzer.cpp
index 7cc9721712..194d944cf5 100644
--- a/src/plugins/clangcodemodel/clangcompletioncontextanalyzer.cpp
+++ b/src/plugins/clangcodemodel/clangcompletioncontextanalyzer.cpp
@@ -169,6 +169,7 @@ void ClangCompletionContextAnalyzer::handleFunctionCall(int afterOperatorPositio
m_positionForProposal,
functionNameStart);
} else { // e.g. "(" without any function name in front
+ m_addSnippets = true;
m_positionForProposal = afterOperatorPosition;
setActionAndClangPosition(PassThroughToLibClang, afterOperatorPosition);
}
@@ -179,6 +180,8 @@ void ClangCompletionContextAnalyzer::handleFunctionCall(int afterOperatorPositio
bool ClangCompletionContextAnalyzer::handleNonFunctionCall(int position)
{
if (isTokenForPassThrough(m_completionOperator)) {
+ if (m_completionOperator == T_EOF_SYMBOL)
+ m_addSnippets = true;
setActionAndClangPosition(PassThroughToLibClang, position);
return true;
} else if (m_completionOperator == T_DOXY_COMMENT) {
diff --git a/src/plugins/clangcodemodel/clangcompletioncontextanalyzer.h b/src/plugins/clangcodemodel/clangcompletioncontextanalyzer.h
index 113384c761..b51029492f 100644
--- a/src/plugins/clangcodemodel/clangcompletioncontextanalyzer.h
+++ b/src/plugins/clangcodemodel/clangcompletioncontextanalyzer.h
@@ -58,6 +58,7 @@ public:
int positionForClang() const { return m_positionForClang; }
int functionNameStart() const { return m_functionNameStart; }
int positionEndOfExpression() const { return m_positionEndOfExpression; }
+ bool addSnippets() const { return m_addSnippets; }
private:
ClangCompletionContextAnalyzer();
@@ -84,6 +85,7 @@ private:
int m_positionForClang = -1;
int m_functionNameStart = -1;
int m_positionEndOfExpression = -1;
+ bool m_addSnippets = false;
};
} // namespace Internal