forked from qt-creator/qt-creator
Clang: fix findStartOfName handling
... of templates and qualified names Change-Id: Ic8c2dec35cb74484f474c0c608857e7cf48c7468 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -247,10 +247,33 @@ int ActivationSequenceContextProcessor::findStartOfName(
|
|||||||
{
|
{
|
||||||
int position = startPosition;
|
int position = startPosition;
|
||||||
QChar character;
|
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 {
|
do {
|
||||||
character = assistInterface->characterAt(--position);
|
character = assistInterface->characterAt(--position);
|
||||||
} while (isValidIdentifierChar(character));
|
} 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;
|
return position + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -144,6 +144,14 @@ TEST(ActivationSequenceContextProcessor, TemplateFunctionLeftParen)
|
|||||||
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_LPAREN);
|
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)
|
TEST(ActivationSequenceContextProcessor, ExpressionLeftParen)
|
||||||
{
|
{
|
||||||
ClangCompletionAssistInterface interface("x * (", 5);
|
ClangCompletionAssistInterface interface("x * (", 5);
|
||||||
|
@@ -490,4 +490,11 @@ TEST_F(ClangCompletionContextAnalyzer, AsteriskLeftParen)
|
|||||||
ASSERT_THAT(analyzer, IsPassThroughToClang());
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user