Commit 49b1d357 authored by Nikolai Kosjar's avatar Nikolai Kosjar

Clang: Clean up ClangCompletionContextAnalyzer

Change-Id: I899cc5cffc389ef023b35825807bde469bb6d31d
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@theqtcompany.com>
parent 4f764963
......@@ -91,15 +91,14 @@ void ClangCompletionContextAnalyzer::analyze()
m_positionForProposal = activationSequenceContextProcessor.positionAfterOperator();
const bool actionIsSet = handleNonFunctionCall(afterOperatorPosition);
if (!actionIsSet) {
handleCommaInFunctionCall();
handleFunctionCall(afterOperatorPosition);
}
}
ClangCompletionContextAnalyzer::FunctionInfo ClangCompletionContextAnalyzer::analyzeFunctionCall(
int endOfOperator) const
ClangCompletionContextAnalyzer::FunctionInfo
ClangCompletionContextAnalyzer::analyzeFunctionCall(int endOfOperator) const
{
int index = skipPrecedingWhitespace(endOfOperator);
QTextCursor textCursor(m_interface->textDocument());
......@@ -150,7 +149,8 @@ void ClangCompletionContextAnalyzer::setActionAndClangPosition(CompletionAction
m_positionForClang = position;
}
void ClangCompletionContextAnalyzer::setAction(ClangCompletionContextAnalyzer::CompletionAction action)
void
ClangCompletionContextAnalyzer::setAction(ClangCompletionContextAnalyzer::CompletionAction action)
{
setActionAndClangPosition(action, -1);
}
......
......@@ -28,9 +28,7 @@
**
****************************************************************************/
#include <clangcompletioncontextanalyzer.h>
#include <clangcodemodel/clangcompletioncontextanalyzer.h>
#include <clangcodemodel/clangcompletionassistinterface.h>
#include <utils/qtcassert.h>
......@@ -44,7 +42,9 @@
namespace ClangCodeModel {
namespace Internal {
void PrintTo(const ClangCompletionContextAnalyzer::CompletionAction &completionAction, ::std::ostream* os)
void PrintTo(const ClangCompletionContextAnalyzer::CompletionAction &completionAction,
::std::ostream* os)
{
using CCA = ClangCompletionContextAnalyzer;
......@@ -58,12 +58,15 @@ void PrintTo(const ClangCompletionContextAnalyzer::CompletionAction &completionA
case CCA::CompleteSlot: *os << "CompleteSlot"; break;
}
}
}
}
} // Internal
} // ClangCodeModel
namespace {
using ::testing::PrintToString;
using ClangCodeModel::Internal::ClangCompletionAssistInterface;
using CCA = ClangCodeModel::Internal::ClangCompletionContextAnalyzer;
class TestDocument
{
......@@ -79,62 +82,68 @@ public:
int position;
};
using ::testing::PrintToString;
bool isPassThrough(CCA::CompletionAction completionAction)
{
return completionAction != CCA::PassThroughToLibClang
&& completionAction != CCA::PassThroughToLibClangAfterLeftParen;
}
MATCHER_P4(HasResult, completionAction, positionForClang, positionForProposal, positionInText,
std::string(negation ? "hasn't" : "has")
+ " result of completion action " + PrintToString(completionAction)
+ " and position for clang " + PrintToString(positionForClang)
+ " and position for proprosal " + PrintToString(positionForProposal))
MATCHER(IsPassThroughToClang, std::string(negation ? "isn't" : "is") + " passed through to Clang")
{
int positionForClangDifference = arg.positionForClang() - positionInText;
int positionForProposalDifference = arg.positionForProposal() - positionInText;
if (arg.completionAction() != completionAction
|| positionForClangDifference != positionForClang
|| positionForProposalDifference != positionForProposal) {
*result_listener << "completion action is " << PrintToString(arg.completionAction())
<< " and position for clang is " << PrintToString(positionForClangDifference)
<< " and position for proprosal is " << PrintToString(positionForProposalDifference);
const auto completionAction = arg.completionAction();
if (isPassThrough(completionAction)) {
*result_listener << "completion action is " << PrintToString(completionAction);
return false;
}
return true;
}
MATCHER_P4(HasResultWithoutClangDifference, completionAction, positionForClang, positionForProposal, positionInText,
// Offsets are relative to positionInText
MATCHER_P4(HasResult,
completionAction,
positionForClangOffset,
positionForProposalOffset,
positionInText,
std::string(negation ? "hasn't" : "has")
+ " result of completion action " + PrintToString(completionAction)
+ " and position for clang " + PrintToString(positionForClang)
+ " and position for proprosal " + PrintToString(positionForProposal))
+ " and offset for clang " + PrintToString(positionForClangOffset)
+ " and offset for proprosal " + PrintToString(positionForProposalOffset))
{
int positionForProposalDifference = arg.positionForProposal() - positionInText;
const int actualPositionForClangOffset = arg.positionForClang() - positionInText;
const int actualPositionForProposalOffset = arg.positionForProposal() - positionInText;
if (arg.completionAction() != completionAction
|| arg.positionForClang() != positionForClang
|| positionForProposalDifference != positionForProposal) {
|| actualPositionForClangOffset != positionForClangOffset
|| actualPositionForProposalOffset != positionForProposalOffset) {
*result_listener << "completion action is " << PrintToString(arg.completionAction())
<< " and position for clang is " << PrintToString(arg.positionForClang())
<< " and position for proprosal is " << PrintToString(positionForProposalDifference);
<< " and offset for clang is " << PrintToString(actualPositionForClangOffset)
<< " and offset for proprosal is " << PrintToString(actualPositionForProposalOffset);
return false;
}
return true;
}
using CCA = ClangCodeModel::Internal::ClangCompletionContextAnalyzer;
bool isPassThrough(CCA::CompletionAction completionAction)
{
return completionAction != CCA::PassThroughToLibClang
&& completionAction != CCA::PassThroughToLibClangAfterLeftParen;
}
MATCHER(IsPassThroughToClang, std::string(negation ? "isn't" : "is") + " passed through to Clang")
// Offsets are relative to positionInText
MATCHER_P4(HasResultWithoutClangDifference,
completionAction,
positionForClangOffset,
positionForProposalOffset,
positionInText,
std::string(negation ? "hasn't" : "has")
+ " result of completion action " + PrintToString(completionAction)
+ " and offset for clang " + PrintToString(positionForClangOffset)
+ " and offset for proprosal " + PrintToString(positionForProposalOffset))
{
auto completionAction = arg.completionAction();
if (isPassThrough(completionAction)) {
*result_listener << "completion action is " << PrintToString(completionAction);
const int actualPositionForProposalOffset = arg.positionForProposal() - positionInText;
if (arg.completionAction() != completionAction
|| arg.positionForClang() != positionForClangOffset
|| actualPositionForProposalOffset != positionForProposalOffset) {
*result_listener << "completion action is " << PrintToString(arg.completionAction())
<< " and offset for clang is " << PrintToString(arg.positionForClang())
<< " and offset for proprosal is " << PrintToString(actualPositionForProposalOffset);
return false;
}
......@@ -144,18 +153,17 @@ MATCHER(IsPassThroughToClang, std::string(negation ? "isn't" : "is") + " passed
class ClangCompletionContextAnalyzer : public ::testing::Test
{
protected:
ClangCodeModel::Internal::ClangCompletionContextAnalyzer runAnalyzer(const char *text);
CCA runAnalyzer(const char *text);
protected:
int positionInText = 0;
};
ClangCodeModel::Internal::ClangCompletionContextAnalyzer ClangCompletionContextAnalyzer::runAnalyzer(const char *text)
CCA ClangCompletionContextAnalyzer::runAnalyzer(const char *text)
{
const TestDocument testDocument(text);
ClangCompletionAssistInterface assistInterface(testDocument.source, testDocument.position);
ClangCodeModel::Internal::ClangCompletionContextAnalyzer analyzer(&assistInterface,
CPlusPlus::LanguageFeatures::defaultFeatures());
CCA analyzer(&assistInterface, CPlusPlus::LanguageFeatures::defaultFeatures());
positionInText = testDocument.position;
......@@ -164,7 +172,6 @@ ClangCodeModel::Internal::ClangCompletionContextAnalyzer ClangCompletionContextA
return analyzer;
}
TEST_F(ClangCompletionContextAnalyzer, AtEndOfDotMember)
{
auto analyzer = runAnalyzer("o.mem@");
......@@ -430,6 +437,5 @@ TEST_F(ClangCompletionContextAnalyzer, AsteriskLeftParen)
ASSERT_THAT(analyzer, IsPassThroughToClang());
}
}
}
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