Commit cea5d886 authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppTools: Fix global completion after "/// text."

Like for other comments, don't try member completion if the doxygen
comment ends with a dot.

Task-number: QTCREATORBUG-8597
Change-Id: I2d5204ba8f45fc9ee94e285a907364cc722e62c7
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@theqtcompany.com>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@theqtcompany.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 7697bd4b
......@@ -680,6 +680,7 @@ int ClangCompletionAssistProcessor::startCompletionHelper()
return startCompletionInternal(fileName, line, column, endOfOperator);
}
// TODO: Extract duplicated logic from InternalCppCompletionAssistProcessor::startOfOperator
int ClangCompletionAssistProcessor::startOfOperator(int pos,
unsigned *kind,
bool wantFunctionCall) const
......@@ -724,8 +725,9 @@ int ClangCompletionAssistProcessor::startOfOperator(int pos,
start = pos;
}
// Don't complete in comments or strings, but still check for include completion
else if (tk.is(T_COMMENT) || tk.is(T_CPP_COMMENT) ||
(tk.isLiteral() && (*kind != T_STRING_LITERAL
else if (tk.is(T_COMMENT) || tk.is(T_CPP_COMMENT)
|| tk.is(T_CPP_DOXY_COMMENT) || tk.is(T_DOXY_COMMENT)
|| (tk.isLiteral() && (*kind != T_STRING_LITERAL
&& *kind != T_ANGLE_STRING_LITERAL
&& *kind != T_SLASH))) {
*kind = T_EOF_SYMBOL;
......
......@@ -341,25 +341,48 @@ void CppToolsPlugin::test_global_completion_data()
{
QTest::addColumn<QByteArray>("code");
QTest::addColumn<QByteArray>("prefix");
QTest::addColumn<QStringList>("requiredCompletionItems");
// Check that special completion after '&' for Qt5 signal/slots does not
// interfere global completion after '&'
QTest::newRow("global completion after & in return expression")
<< _("void f() { foo(myObject, @); }\n")
<< _("&");
<< _("&")
<< QStringList();
QTest::newRow("global completion after & in function argument")
<< _("int f() { return @; }\n")
<< _("&");
<< _("&")
<< QStringList();
// Check global completion after one line comments
const QByteArray codeTemplate = "int myGlobal;\n"
"<REPLACEMENT>\n"
"@\n";
const QStringList replacements = QStringList()
<< QLatin1String("// text")
<< QLatin1String("// text.")
<< QLatin1String("/// text")
<< QLatin1String("/// text.")
;
foreach (const QString &replacement, replacements) {
QByteArray code = codeTemplate;
code.replace("<REPLACEMENT>", replacement.toUtf8());
const QByteArray tag = _("completion after comment: ") + replacement.toUtf8();
QTest::newRow(tag) << code << QByteArray() << QStringList(QLatin1String("myGlobal"));
}
}
void CppToolsPlugin::test_global_completion()
{
QFETCH(QByteArray, code);
QFETCH(QByteArray, prefix);
QFETCH(QStringList, requiredCompletionItems);
CompletionTestCase test(code, prefix);
QVERIFY(test.succeededSoFar());
QVERIFY(isProbablyGlobalCompletion(test.getCompletions()));
const QStringList completions = test.getCompletions();
QVERIFY(isProbablyGlobalCompletion(completions));
QVERIFY(completions.toSet().contains(requiredCompletionItems.toSet()));
}
static void enumTestCase(const QByteArray &tag, const QByteArray &source,
......
......@@ -974,8 +974,9 @@ int InternalCppCompletionAssistProcessor::startOfOperator(int pos,
start = pos;
}
// Don't complete in comments or strings, but still check for include completion
else if (tk.is(T_COMMENT) || tk.is(T_CPP_COMMENT) ||
(tk.isLiteral() && (*kind != T_STRING_LITERAL
else if (tk.is(T_COMMENT) || tk.is(T_CPP_COMMENT)
|| tk.is(T_CPP_DOXY_COMMENT) || tk.is(T_DOXY_COMMENT)
|| (tk.isLiteral() && (*kind != T_STRING_LITERAL
&& *kind != T_ANGLE_STRING_LITERAL
&& *kind != T_SLASH
&& *kind != T_DOT))) {
......
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