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