Commit aa6aaee5 authored by Marco Bubke's avatar Marco Bubke

Clang: Add brief comment support

Change-Id: I5af23b6694d3d0bf45ed0a30b4d91b350f0515df
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent b278dc87
......@@ -110,6 +110,16 @@ quint32 CodeCompletion::priority() const
return priority_;
}
void CodeCompletion::setBriefComment(const Utf8String &briefComment)
{
briefComment_ = briefComment;
}
const Utf8String &CodeCompletion::briefComment() const
{
return briefComment_;
}
quint32 &CodeCompletion::completionKindAsInt()
{
return reinterpret_cast<quint32&>(completionKind_);
......@@ -123,6 +133,7 @@ quint32 &CodeCompletion::availabilityAsInt()
QDataStream &operator<<(QDataStream &out, const CodeCompletion &message)
{
out << message.text_;
out << message.briefComment_;
out << message.chunks_;
out << message.priority_;
out << message.completionKind_;
......@@ -135,6 +146,7 @@ QDataStream &operator<<(QDataStream &out, const CodeCompletion &message)
QDataStream &operator>>(QDataStream &in, CodeCompletion &message)
{
in >> message.text_;
in >> message.briefComment_;
in >> message.chunks_;
in >> message.priority_;
in >> message.completionKindAsInt();
......
......@@ -107,12 +107,16 @@ public:
void setPriority(quint32 priority);
quint32 priority() const;
void setBriefComment(const Utf8String &briefComment);
const Utf8String &briefComment() const;
private:
quint32 &completionKindAsInt();
quint32 &availabilityAsInt();
private:
Utf8String text_;
Utf8String briefComment_;
CodeCompletionChunks chunks_;
quint32 priority_ = 0;
Kind completionKind_ = Other;
......
......@@ -100,7 +100,12 @@ QList<AssistProposalItem *> toAssistProposalItems(const CodeCompletions &complet
items.insert(name, item);
item->setText(name);
item->setOrder(ccr.priority());
item->setDetail(CompletionChunksToTextConverter::convertToToolTip(ccr.chunks()));
QString detail = CompletionChunksToTextConverter::convertToToolTip(ccr.chunks());
if (!ccr.briefComment().isEmpty())
detail += QStringLiteral("\n\n") + ccr.briefComment().toString();
item->setDetail(detail);
item->setCodeCompletion(ccr);
}
......
......@@ -63,6 +63,7 @@ bool CodeCompletionsExtractor::next()
extractPriority();
extractAvailability();
extractHasParameters();
extractBriefComment();
extractCompletionChunks();
adaptPriority();
......@@ -249,6 +250,13 @@ void CodeCompletionsExtractor::extractHasParameters()
}
}
void CodeCompletionsExtractor::extractBriefComment()
{
ClangString briefComment = clang_getCompletionBriefComment(currentCxCodeCompleteResult.CompletionString);
currentCodeCompletion_.setBriefComment(briefComment);
}
void CodeCompletionsExtractor::extractCompletionChunks()
{
currentCodeCompletion_.setChunks(CodeCompletionChunkConverter::extract(currentCxCodeCompleteResult.CompletionString));
......
......@@ -65,6 +65,7 @@ private:
void extractPriority();
void extractAvailability();
void extractHasParameters();
void extractBriefComment();
void extractCompletionChunks();
void adaptPriority();
......
......@@ -230,7 +230,8 @@ void TranslationUnit::reparseTranslationUnit() const
int TranslationUnit::defaultOptions()
{
return CXTranslationUnit_CacheCompletionResults
| CXTranslationUnit_PrecompiledPreamble;
| CXTranslationUnit_PrecompiledPreamble
| CXTranslationUnit_IncludeBriefCommentsInCodeCompletion;
}
uint TranslationUnit::unsavedFilesCount() const
......
......@@ -101,6 +101,26 @@ MATCHER_P2(HasCompletionChunks, name, chunks,
return false;
}
MATCHER_P2(HasBriefComment, name, briefComment,
std::string(negation ? "hasn't" : "has") + " completion of name " + PrintToString(name) +
" with the brief comment " + PrintToString(briefComment))
{
::CodeCompletionsExtractor &extractor = const_cast<::CodeCompletionsExtractor&>(arg);
while (extractor.next()) {
if (extractor.currentCodeCompletion().text() == name) {
if (extractor.currentCodeCompletion().briefComment() == briefComment) {
return true;
} else if (!extractor.peek(name)) {
*result_listener << "briefComment is " << PrintToString(arg.currentCodeCompletion().briefComment()) << " and not " << PrintToString(briefComment);
return false;
}
}
}
return false;
}
const Utf8String unsavedFileContent(const char *unsavedFilePath)
{
QFile unsavedFileContentFile(QString::fromUtf8(unsavedFilePath));
......@@ -133,39 +153,18 @@ ClangCodeCompleteResults getResults(const TranslationUnit &translationUnit, uint
class CodeCompletionsExtractor : public ::testing::Test
{
public:
static void TearDownTestCase();
protected:
static ClangBackEnd::ProjectPart project;
static ClangBackEnd::UnsavedFiles unsavedFiles;
static TranslationUnit functionTranslationUnit;
static TranslationUnit variableTranslationUnit;
static TranslationUnit classTranslationUnit ;
static TranslationUnit namespaceTranslationUnit;
static TranslationUnit enumerationTranslationUnit;
static TranslationUnit constructorTranslationUnit;
ClangBackEnd::ProjectPart project{Utf8StringLiteral("/path/to/projectfile")};
ClangBackEnd::UnsavedFiles unsavedFiles;
TranslationUnit functionTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"), unsavedFiles, project};
TranslationUnit variableTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_variable.cpp"), unsavedFiles, project};
TranslationUnit classTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_class.cpp"), unsavedFiles, project};
TranslationUnit namespaceTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_namespace.cpp"), unsavedFiles, project};
TranslationUnit enumerationTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_enumeration.cpp"), unsavedFiles, project};
TranslationUnit constructorTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_constructor.cpp"), unsavedFiles, project};
TranslationUnit briefCommentTranslationUnit{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_brief_comment.cpp"), unsavedFiles, project};
};
ClangBackEnd::ProjectPart CodeCompletionsExtractor::project(Utf8StringLiteral("/path/to/projectfile"));
ClangBackEnd::UnsavedFiles CodeCompletionsExtractor::unsavedFiles;
TranslationUnit CodeCompletionsExtractor::functionTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"), unsavedFiles, project);
TranslationUnit CodeCompletionsExtractor::variableTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_variable.cpp"), unsavedFiles, project);
TranslationUnit CodeCompletionsExtractor::classTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_class.cpp"), unsavedFiles, project);
TranslationUnit CodeCompletionsExtractor::namespaceTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_namespace.cpp"), unsavedFiles, project);
TranslationUnit CodeCompletionsExtractor::enumerationTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_enumeration.cpp"), unsavedFiles, project);
TranslationUnit CodeCompletionsExtractor::constructorTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_constructor.cpp"), unsavedFiles, project);
void CodeCompletionsExtractor::TearDownTestCase()
{
functionTranslationUnit.reset();
variableTranslationUnit.reset();
classTranslationUnit.reset();
namespaceTranslationUnit.reset();
enumerationTranslationUnit.reset();
constructorTranslationUnit.reset();
}
TEST_F(CodeCompletionsExtractor, Function)
{
ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20));
......@@ -657,5 +656,14 @@ TEST_F(CodeCompletionsExtractor, CompletionChunksClass)
CodeCompletionChunks({{CodeCompletionChunk::TypedText, Utf8StringLiteral("Class")}})));
}
TEST_F(CodeCompletionsExtractor, BriefComment)
{
ClangCodeCompleteResults completeResults(getResults(briefCommentTranslationUnit, 10));
::CodeCompletionsExtractor extractor(completeResults.data());
ASSERT_THAT(extractor, HasBriefComment(Utf8StringLiteral("BriefComment"), Utf8StringLiteral("A brief comment")));
}
}
/**
* A brief comment
*/
void BriefComment()
{
}
void f() {
}
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