Clang: Fix adding completion snippets after {

...e.g. as in "void f() {".

The criteria whether to change snippets got invalidated with

    commit 8d0391a4f9
    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>
This commit is contained in:
Nikolai Kosjar
2018-10-24 10:05:53 +02:00
parent 7d3686359a
commit d946ff5403
4 changed files with 60 additions and 47 deletions

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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