Commit fb5f7260 authored by Sergey Kalinichev's avatar Sergey Kalinichev

Mark out the current argument with bold font

Also added new class, to store argument-hint items
parent 6885bbd1
......@@ -291,6 +291,50 @@ private:
QString m_replacement;
};
class ArgumentHintItem : public DeclarationItem
{
public:
struct CurrentArgumentRange
{
int start;
int end;
};
ArgumentHintItem(Declaration* decl, const QString& prefix, const QString& name, const QString& arguments, const CurrentArgumentRange& range)
: DeclarationItem(decl, name, prefix, {})
, m_range(range)
, m_arguments(arguments)
{}
QVariant data(const QModelIndex& index, int role, const CodeCompletionModel* model) const override
{
if (role == CodeCompletionModel::CustomHighlight && index.column() == CodeCompletionModel::Arguments && argumentHintDepth()) {
QList<QVariant> highlighting;
highlighting << QVariant(m_range.start);
highlighting << QVariant(m_range.end);
QTextCharFormat boldFormat;
boldFormat.setFontWeight(QFont::Bold);
highlighting << boldFormat;
return highlighting;
}
if (role == CodeCompletionModel::HighlightingMethod && index.column() == CodeCompletionModel::Arguments && argumentHintDepth()) {
return QVariant(CodeCompletionModel::CustomHighlighting);
}
if (index.column() == CodeCompletionModel::Arguments && !m_declaration) {
return m_arguments;
}
return DeclarationItem::data(index, role, model);
}
private:
CurrentArgumentRange m_range;
QString m_arguments;
};
/**
* A minimalistic completion item for macros and such
*/
......@@ -858,6 +902,10 @@ QList<CompletionTreeItemPointer> ClangCodeCompletionContext::completionItems(boo
QString resultType;
// the replacement text when an item gets executed
QString replacement;
QString arguments;
ArgumentHintItem::CurrentArgumentRange argumentRange;
//BEGIN function signature parsing
// nesting depth of parentheses
int parenDepth = 0;
......@@ -904,7 +952,7 @@ QList<CompletionTreeItemPointer> ClangCodeCompletionContext::completionItems(boo
continue;
case CXCompletionChunk_Placeholder:
if (signatureState == Inside) {
display += string;
arguments += string;
}
continue;
case CXCompletionChunk_LeftParen:
......@@ -916,7 +964,7 @@ QList<CompletionTreeItemPointer> ClangCodeCompletionContext::completionItems(boo
case CXCompletionChunk_RightParen:
--parenDepth;
if (signatureState == Inside && !parenDepth) {
display += QLatin1Char(')');
arguments += QLatin1Char(')');
signatureState = After;
}
break;
......@@ -928,11 +976,15 @@ QList<CompletionTreeItemPointer> ClangCodeCompletionContext::completionItems(boo
}
#endif
break;
case CXCompletionChunk_CurrentParameter:
argumentRange.start = arguments.size();
argumentRange.end = string.size();
break;
default:
break;
}
if (signatureState == Inside) {
display += string;
arguments += string;
}
}
......@@ -1003,9 +1055,9 @@ QList<CompletionTreeItemPointer> ClangCodeCompletionContext::completionItems(boo
#if CINDEX_VERSION_MINOR >= 30
if (result.CursorKind == CXCursor_OverloadCandidate) {
// TODO: No parent context for CXCursor_OverloadCandidate items, hence qid is broken -> no declaration found
auto di = new DeclarationItem({}, display, resultType, replacement);
di->setArgumentHintDepth(1);
item = di;
auto ahi = new ArgumentHintItem({}, resultType, typed, arguments, argumentRange);
ahi->setArgumentHintDepth(1);
item = ahi;
} else {
#endif
// still, let's trust that Clang found something useful and put it into the completion result list
......@@ -1031,7 +1083,7 @@ QList<CompletionTreeItemPointer> ClangCodeCompletionContext::completionItems(boo
if (result.CursorKind == CXCursor_MacroDefinition) {
// TODO: grouping of macros and built-in stuff
static const QIcon icon = QIcon::fromTheme(QStringLiteral("code-macro"));
auto item = CompletionTreeItemPointer(new SimpleItem(display, resultType, replacement, icon));
auto item = CompletionTreeItemPointer(new SimpleItem(display + arguments, resultType, replacement, icon));
macros.append(item);
} else if (result.CursorKind == CXCursor_NotImplemented) {
auto item = CompletionTreeItemPointer(new SimpleItem(display, resultType, replacement));
......
......@@ -159,7 +159,6 @@ void executeCompletionTest(const QString& code, const CompletionItems& expectedC
QEXPECT_FAIL("look-ahead template parameter substitution", "No parameters substitution so far", Continue);
QEXPECT_FAIL("look-ahead auto item", "Auto type, like many other types, is not exposed through LibClang. We assign DelayedType to it instead of IdentifiedType", Continue);
QEXPECT_FAIL("deleted-overload-global", "The range for a global function defintion ends after the '=' so 'delete' after that is not detected.", Continue);
QEXPECT_FAIL("default parameters", "Default parameters not supported yet", Continue);
QCOMPARE(tester.names, expectedCompletionItems.completions);
}
......@@ -369,7 +368,7 @@ void TestCodeCompletion::testClangCodeCompletion_data()
<< CompletionItems{{1, 0},
{"A", "B", "b", "c", "f",
#if CINDEX_VERSION_MINOR >= 30
"f(A)",
"f",
#endif
"main"},
{"c", "A", "b", "B"}
......@@ -400,7 +399,7 @@ void TestCodeCompletion::testClangCodeCompletion_data()
<< CompletionItems{{1, 0}, {
"Class", "LookAhead", "function",
#if CINDEX_VERSION_MINOR >= 30
"function(Class cl)",
"function",
#endif
"instance", "instance.classItem",
"main", "pInstance", "pInstance->classItem",
......@@ -970,7 +969,7 @@ void TestCodeCompletion::testArgumentHintCompletion_data()
<< "void foo(int);\n"
"int main() { \nfoo( "
<< CompletionItems{{2,4}, {
"foo", "foo(int)",
"foo", "foo",
"main"
}};
......@@ -978,7 +977,7 @@ void TestCodeCompletion::testArgumentHintCompletion_data()
<< "struct Struct{ void foo(int);}\n"
"int main() {Struct s; \ns.foo( "
<< CompletionItems{{2,6}, {
"Struct", "foo(int)",
"Struct", "foo",
"main", "s"
}};
......@@ -986,7 +985,7 @@ void TestCodeCompletion::testArgumentHintCompletion_data()
<< "template <typename T> void foo(T);\n"
"int main() { \nfoo( "
<< CompletionItems{{2,6}, {
"foo", "foo(T)",
"foo", "foo",
"main"
}};
......@@ -994,7 +993,7 @@ void TestCodeCompletion::testArgumentHintCompletion_data()
<< "void foo(int); void foo(int, double)\n"
"int main() { \nfoo( "
<< CompletionItems{{2,6}, {
"foo", "foo", "foo(int)", "foo(int, double)",
"foo", "foo", "foo", "foo",
"main"
}};
......@@ -1002,15 +1001,9 @@ void TestCodeCompletion::testArgumentHintCompletion_data()
<< "void foo(int); void foo(int, double)\n"
"int main() { foo(1,\n "
<< CompletionItems{{2,1}, {
"foo", "foo", "foo(int, double)",
"foo", "foo", "foo",
"main"
}};
QTest::newRow("default parameters")
<< "void foo(int i = 0);\n"
"int main() { \nfoo( "
<< CompletionItems{{2,4}, {
"foo", "foo(int i = 0)",
"main"
}};
// TODO: Test default parameters. We need something like testOverloadedFunctions for that
}
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