Commit 82d0650b authored by Ivan Donchevskii's avatar Ivan Donchevskii

Clang: fix findStartOfName handling

... of templates and qualified names

Change-Id: Ic8c2dec35cb74484f474c0c608857e7cf48c7468
Reviewed-by: Nikolai Kosjar's avatarNikolai Kosjar <nikolai.kosjar@qt.io>
parent 5fb54e7c
......@@ -247,10 +247,33 @@ int ActivationSequenceContextProcessor::findStartOfName(
{
int position = startPosition;
QChar character;
if (position > 2 && assistInterface->characterAt(position - 1) == '>'
&& assistInterface->characterAt(position - 2) != '-') {
uint unbalancedLessGreater = 1;
--position;
while (unbalancedLessGreater > 0 && position > 2) {
character = assistInterface->characterAt(--position);
// Do not count -> usage inside temlate argument list
if (character == '<')
--unbalancedLessGreater;
else if (character == '>' && assistInterface->characterAt(position-1) != '-')
++unbalancedLessGreater;
}
position = skipPrecedingWhitespace(assistInterface, position) - 1;
}
do {
character = assistInterface->characterAt(--position);
} while (isValidIdentifierChar(character));
int prevPosition = skipPrecedingWhitespace(assistInterface, position);
if (assistInterface->characterAt(prevPosition) == ':'
&& assistInterface->characterAt(prevPosition - 1) == ':') {
// Handle :: case - go recursive
prevPosition = skipPrecedingWhitespace(assistInterface, prevPosition - 2);
return findStartOfName(assistInterface, prevPosition + 1);
}
return position + 1;
}
......
......@@ -144,6 +144,14 @@ TEST(ActivationSequenceContextProcessor, TemplateFunctionLeftParen)
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_LPAREN);
}
TEST(ActivationSequenceContextProcessor, TemplateFunctionSecondParameter)
{
ClangCompletionAssistInterface interface("foo<X>(", 7);
int startOfname = ContextProcessor::findStartOfName(&interface, 6);
ASSERT_THAT(startOfname, 0);
}
TEST(ActivationSequenceContextProcessor, ExpressionLeftParen)
{
ClangCompletionAssistInterface interface("x * (", 5);
......
......@@ -490,4 +490,11 @@ TEST_F(ClangCompletionContextAnalyzer, AsteriskLeftParen)
ASSERT_THAT(analyzer, IsPassThroughToClang());
}
TEST_F(ClangCompletionContextAnalyzer, TemplatedFunctionSecondArgument)
{
auto analyzer = runAnalyzer("f < decltype(bar -> member) > (1, @");
ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClangAfterLeftParen, -3, -3, positionInText));
}
}
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