forked from qt-creator/qt-creator
C++: Fix completion for doxygen tags I
There are three cases that must be handled: 1. Completion in C++ style comment 2. Completion in first line of a C style comment 3. Completion in non-first line of a C style comment This change fixes case 1 + 2. Case 3 will be addressed in a follow-up change, same goes for the duplication. Task-number: QTCREATORBUG-15143 Change-Id: I449711f965ddcbbe6158870a8a5ae33218e0d238 Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "cppcompletionassist.h"
|
||||
#include "cppdoxygen.h"
|
||||
#include "cppmodelmanager.h"
|
||||
#include "cpptoolsplugin.h"
|
||||
#include "cpptoolstestcase.h"
|
||||
@@ -171,6 +172,17 @@ bool isProbablyGlobalCompletion(const QStringList &list)
|
||||
&& list.contains(QLatin1String("bool"));
|
||||
}
|
||||
|
||||
bool isDoxygenTagCompletion(const QStringList &list)
|
||||
{
|
||||
for (int i = 1; i < T_DOXY_LAST_TAG; ++i) {
|
||||
const QString doxygenTag = QString::fromLatin1(doxygenTagSpell(i));
|
||||
if (!list.contains(doxygenTag))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
void CppToolsPlugin::test_completion_basic_1()
|
||||
@@ -384,6 +396,29 @@ void CppToolsPlugin::test_global_completion()
|
||||
QVERIFY(completions.toSet().contains(requiredCompletionItems.toSet()));
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_doxygen_tag_completion_data()
|
||||
{
|
||||
QTest::addColumn<QByteArray>("code");
|
||||
|
||||
QTest::newRow("C++ comment")
|
||||
<< _("/// @");
|
||||
|
||||
QTest::newRow("C comment single line")
|
||||
<< _("/*! @ */");
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_doxygen_tag_completion()
|
||||
{
|
||||
QFETCH(QByteArray, code);
|
||||
|
||||
const QByteArray prefix = "\\";
|
||||
|
||||
CompletionTestCase test(code, prefix);
|
||||
QVERIFY(test.succeededSoFar());
|
||||
const QStringList completions = test.getCompletions();
|
||||
QVERIFY(isDoxygenTagCompletion(completions));
|
||||
}
|
||||
|
||||
static void enumTestCase(const QByteArray &tag, const QByteArray &source,
|
||||
const QByteArray &prefix = QByteArray())
|
||||
{
|
||||
|
||||
@@ -991,7 +991,8 @@ int InternalCppCompletionAssistProcessor::startOfOperator(int 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.is(T_CPP_DOXY_COMMENT) || tk.is(T_DOXY_COMMENT)
|
||||
|| ((tk.is(T_CPP_DOXY_COMMENT) || tk.is(T_DOXY_COMMENT))
|
||||
&& !isDoxygenTagCompletionCharacter(ch))
|
||||
|| (tk.isLiteral() && (*kind != T_STRING_LITERAL
|
||||
&& *kind != T_ANGLE_STRING_LITERAL
|
||||
&& *kind != T_SLASH
|
||||
|
||||
@@ -70,4 +70,10 @@ void CppCompletionAssistProcessor::addSnippets()
|
||||
m_completions.append(m_snippetCollector.collect());
|
||||
}
|
||||
|
||||
bool CppCompletionAssistProcessor::isDoxygenTagCompletionCharacter(const QChar &character)
|
||||
{
|
||||
return character == QLatin1Char('\\')
|
||||
|| character == QLatin1Char('@') ;
|
||||
}
|
||||
|
||||
} // namespace CppTools
|
||||
|
||||
@@ -43,6 +43,8 @@ public:
|
||||
protected:
|
||||
void addSnippets();
|
||||
|
||||
static bool isDoxygenTagCompletionCharacter(const QChar &character);
|
||||
|
||||
int m_positionForProposal;
|
||||
QList<TextEditor::AssistProposalItemInterface *> m_completions;
|
||||
QStringList m_preprocessorCompletions;
|
||||
|
||||
@@ -109,6 +109,9 @@ private slots:
|
||||
void test_global_completion_data();
|
||||
void test_global_completion();
|
||||
|
||||
void test_doxygen_tag_completion_data();
|
||||
void test_doxygen_tag_completion();
|
||||
|
||||
void test_completion_member_access_operator_data();
|
||||
void test_completion_member_access_operator();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user