diff --git a/ports/cpp/source/antlr4-c3/CodeCompletionCore.hpp b/ports/cpp/source/antlr4-c3/CodeCompletionCore.hpp index ce023ea..0792085 100644 --- a/ports/cpp/source/antlr4-c3/CodeCompletionCore.hpp +++ b/ports/cpp/source/antlr4-c3/CodeCompletionCore.hpp @@ -181,7 +181,7 @@ class CodeCompletionCore * @returns The collection of completion candidates. If cancelled or timed out, the returned collection will have its 'cancelled' * value set to true and the collected candidates may be incomplete. */ - CandidatesCollection collectCandidates(size_t caretTokenIndex, antlr4::ParserRuleContext * context, size_t timeoutMS, std::atomic * cancel); + CandidatesCollection collectCandidates(size_t caretTokenIndex, antlr4::ParserRuleContext * context = nullptr, size_t timeoutMS = 0, std::atomic * cancel = nullptr); diff --git a/ports/cpp/test/cpp14/Cpp14Test.cpp b/ports/cpp/test/cpp14/Cpp14Test.cpp index 7b1a647..8af94bf 100644 --- a/ports/cpp/test/cpp14/Cpp14Test.cpp +++ b/ports/cpp/test/cpp14/Cpp14Test.cpp @@ -6,7 +6,6 @@ #include #include -#include namespace c3::test { @@ -51,7 +50,7 @@ TEST(CPP14Parser, SimpleExample) { { // 1) At the input start. - auto candidates = Candidates(completion, 0); + auto candidates = completion.collectCandidates(0); EXPECT_THAT( Keys(candidates.tokens), @@ -99,7 +98,7 @@ TEST(CPP14Parser, SimpleExample) { // Note when counting token indexes: the C++14 grammar skips all // whitespaces, hence there are no tokens for them. completion.translateRulesTopDown = translateRulesTopDown; - auto candidates = Candidates(completion, 10); + auto candidates = completion.collectCandidates(10); const std::vector idexpressionStack = { CPP14Parser::RuleTranslationunit, @@ -180,7 +179,7 @@ TEST(CPP14Parser, SimpleExample) { // Note when counting token indexes: the C++14 grammar skips all // whitespaces, hence there are no tokens for them. completion.translateRulesTopDown = true; - auto candidates = Candidates(completion, 10); + auto candidates = completion.collectCandidates(10); EXPECT_EQ(candidates.tokens.size(), 82); @@ -241,7 +240,7 @@ TEST(CPP14Parser, SimpleCppExampleWithErrorsInInput) { { // At the opening parenthesis. - auto candidates = Candidates(completion, 11); + auto candidates = completion.collectCandidates(11); EXPECT_THAT(Keys(candidates.tokens), UnorderedElementsAre(CPP14Lexer::LeftParen)); @@ -249,7 +248,7 @@ TEST(CPP14Parser, SimpleCppExampleWithErrorsInInput) { { // At the closing parenthesis -> again everything in an expression allowed // (no control flow this time, though). - auto candidates = Candidates(completion, 12); + auto candidates = completion.collectCandidates(12); EXPECT_EQ(candidates.tokens.size(), 65); @@ -271,7 +270,7 @@ TEST(CPP14Parser, SimpleCppExampleWithErrorsInInput) { } { // After the error position -> no suggestions. - auto candidates = Candidates(completion, 13); + auto candidates = completion.collectCandidates(13); EXPECT_EQ(candidates.tokens.size(), 0); EXPECT_EQ(candidates.rules.size(), 0); @@ -348,7 +347,7 @@ TEST(CPP14Parser, RealCppFile) { }); { - auto candidates = Candidates(completion, 3469); + auto candidates = completion.collectCandidates(3469); EXPECT_THAT(Keys(candidates.rules), UnorderedElementsAre(CPP14Parser::RuleClassname, @@ -362,7 +361,7 @@ TEST(CPP14Parser, RealCppFile) { // We should receive more specific rules when translating top down. completion.translateRulesTopDown = true; - auto candidates = Candidates(completion, 3469); + auto candidates = completion.collectCandidates(3469); EXPECT_THAT(candidates.rules[CPP14Parser::RuleClassname].ruleList, ElementsAreArray(classnameStack)); diff --git a/ports/cpp/test/expr/ExprTest.cpp b/ports/cpp/test/expr/ExprTest.cpp index 78446c5..01edd87 100644 --- a/ports/cpp/test/expr/ExprTest.cpp +++ b/ports/cpp/test/expr/ExprTest.cpp @@ -18,15 +18,10 @@ TEST(SimpleExpressionParser, MostSimpleSetup) { EXPECT_EQ(pipeline.listener.GetErrorCount(), 0); c3::CodeCompletionCore completion(&pipeline.parser); - const auto collectCandidatesAt = [&](std::size_t tokenIndex) { - return completion.collectCandidates(tokenIndex, - /*context=*/nullptr, /*size_t=*/0, - /*cancel=*/nullptr); - }; { // 1) At the input start. - auto candidates = collectCandidatesAt(0); + auto candidates = completion.collectCandidates(0); EXPECT_THAT( Keys(candidates.tokens), UnorderedElementsAre(ExprLexer::VAR, ExprLexer::LET, ExprLexer::ID)); @@ -40,17 +35,17 @@ TEST(SimpleExpressionParser, MostSimpleSetup) { // 2) On the first whitespace. In real implementations you would do some // additional checks where in the whitespace the caret is, as the outcome is // different depending on that position. - auto candidates = collectCandidatesAt(1); + auto candidates = completion.collectCandidates(1); EXPECT_THAT(Keys(candidates.tokens), UnorderedElementsAre(ExprLexer::ID)); } { // 3) On the variable name ('c'). - auto candidates = collectCandidatesAt(2); + auto candidates = completion.collectCandidates(2); EXPECT_THAT(Keys(candidates.tokens), UnorderedElementsAre(ExprLexer::ID)); } { // 4) On the equal sign (ignoring whitespace positions from now on). - auto candidates = collectCandidatesAt(4); + auto candidates = completion.collectCandidates(4); EXPECT_THAT(Keys(candidates.tokens), UnorderedElementsAre(ExprLexer::EQUAL)); } @@ -58,13 +53,13 @@ TEST(SimpleExpressionParser, MostSimpleSetup) { // 5) On the variable reference 'a'. But since we have not configure the c3 // engine to return us var refs (or function refs for that matter) we only // get an ID here. - auto candidates = collectCandidatesAt(6); + auto candidates = completion.collectCandidates(6); EXPECT_THAT(Keys(candidates.tokens), UnorderedElementsAre(ExprLexer::ID)); } { // 6) On the '+' operator. Usually you would not show operators as // candidates, but we have not set up the c3 engine yet to not return them. - auto candidates = collectCandidatesAt(8); + auto candidates = completion.collectCandidates(8); EXPECT_THAT(Keys(candidates.tokens), UnorderedElementsAre(ExprLexer::PLUS, ExprLexer::MINUS, ExprLexer::MULTIPLY, ExprLexer::DIVIDE, @@ -87,15 +82,9 @@ TEST(SimpleExpressionParser, TypicalSetup) { ExprParser::RuleVariableRef, }; - const auto collectCandidatesAt = [&](std::size_t tokenIndex) { - return completion.collectCandidates(tokenIndex, - /*context=*/nullptr, /*size_t=*/0, - /*cancel=*/nullptr); - }; - { // 1) At the input start. - auto candidates = collectCandidatesAt(0); + auto candidates = completion.collectCandidates(0); EXPECT_THAT(Keys(candidates.tokens), UnorderedElementsAre(ExprLexer::VAR, ExprLexer::LET)); @@ -105,17 +94,17 @@ TEST(SimpleExpressionParser, TypicalSetup) { } { // 2) On the variable name ('c'). - auto candidates = collectCandidatesAt(2); + auto candidates = completion.collectCandidates(2); EXPECT_EQ(candidates.tokens.size(), 0); } { // 4) On the equal sign. - auto candidates = collectCandidatesAt(4); + auto candidates = completion.collectCandidates(4); EXPECT_EQ(candidates.tokens.size(), 0); } { // 5) On the variable reference 'a'. - auto candidates = collectCandidatesAt(6); + auto candidates = completion.collectCandidates(6); EXPECT_EQ(candidates.tokens.size(), 0); // Here we get 2 rule indexes, derived from 2 different IDs possible at this // caret position. These are what we told the engine above to be preferred @@ -129,7 +118,7 @@ TEST(SimpleExpressionParser, TypicalSetup) { { // 6) On the whitespace just after the variable reference 'a' (but it could // still be a function reference!). - auto candidates = collectCandidatesAt(7); + auto candidates = completion.collectCandidates(7); EXPECT_EQ(candidates.tokens.size(), 0); EXPECT_THAT(Keys(candidates.rules), UnorderedElementsAre(ExprParser::RuleFunctionRef)); @@ -145,15 +134,9 @@ TEST(SimpleExpressionParser, RecursivePreferredRule) { c3::CodeCompletionCore completion(&pipeline.parser); completion.preferredRules = {ExprParser::RuleSimpleExpression}; - const auto collectCandidatesAt = [&](std::size_t tokenIndex) { - return completion.collectCandidates(tokenIndex, - /*context=*/nullptr, /*size_t=*/0, - /*cancel=*/nullptr); - }; - { // 1) On the variable reference 'a'. - auto candidates = collectCandidatesAt(6); + auto candidates = completion.collectCandidates(6); EXPECT_THAT(Keys(candidates.rules), UnorderedElementsAre(ExprParser::RuleSimpleExpression)); // The start token of the simpleExpression rule begins at token 'a'. @@ -163,7 +146,7 @@ TEST(SimpleExpressionParser, RecursivePreferredRule) { { // 2) On the variable reference 'b'. completion.translateRulesTopDown = false; - auto candidates = collectCandidatesAt(10); + auto candidates = completion.collectCandidates(10); EXPECT_THAT(Keys(candidates.rules), UnorderedElementsAre(ExprParser::RuleSimpleExpression)); // When translateRulesTopDown is false, startTokenIndex should match the @@ -175,7 +158,7 @@ TEST(SimpleExpressionParser, RecursivePreferredRule) { { // 3) On the variable reference 'b' topDown preferred rules. completion.translateRulesTopDown = true; - auto candidates = collectCandidatesAt(10); + auto candidates = completion.collectCandidates(10); EXPECT_THAT(Keys(candidates.rules), UnorderedElementsAre(ExprParser::RuleSimpleExpression)); // When translateRulesTopDown is true, startTokenIndex should match the @@ -198,15 +181,9 @@ TEST(SimpleExpressionParser, CandidateRulesWithDifferentStartTokens) { }; completion.translateRulesTopDown = true; - const auto collectCandidatesAt = [&](std::size_t tokenIndex) { - return completion.collectCandidates(tokenIndex, - /*context=*/nullptr, /*size_t=*/0, - /*cancel=*/nullptr); - }; - { // 1) On the token 'var'. - auto candidates = collectCandidatesAt(0); + auto candidates = completion.collectCandidates(0); EXPECT_THAT(Keys(candidates.rules), UnorderedElementsAre(ExprParser::RuleAssignment, ExprParser::RuleVariableRef)); @@ -217,7 +194,7 @@ TEST(SimpleExpressionParser, CandidateRulesWithDifferentStartTokens) { } { // 2) On the variable reference 'a'. - auto candidates = collectCandidatesAt(6); + auto candidates = completion.collectCandidates(6); EXPECT_THAT(Keys(candidates.rules), UnorderedElementsAre(ExprParser::RuleAssignment, ExprParser::RuleVariableRef)); diff --git a/ports/cpp/test/utility/Extension.hpp b/ports/cpp/test/utility/Extension.hpp deleted file mode 100644 index b06c9d9..0000000 --- a/ports/cpp/test/utility/Extension.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include - -namespace c3::test { - -inline auto Candidates(CodeCompletionCore &completion, - std::size_t caretTokenIndex) { - return completion.collectCandidates(caretTokenIndex, - /*context=*/nullptr, /*size_t=*/0, - /*cancel=*/nullptr); -} - -inline auto Candidates(CodeCompletionCore &completion, - std::size_t caretTokenIndex, - antlr4::ParserRuleContext *context) { - return completion.collectCandidates(caretTokenIndex, - /*context=*/context, /*size_t=*/0, - /*cancel=*/nullptr); -} - -} // namespace c3::test \ No newline at end of file diff --git a/ports/cpp/test/utility/Testing.hpp b/ports/cpp/test/utility/Testing.hpp index 41a30c5..81b1b20 100644 --- a/ports/cpp/test/utility/Testing.hpp +++ b/ports/cpp/test/utility/Testing.hpp @@ -4,7 +4,6 @@ #include #include "AntlrPipeline.hpp" -#include "Extension.hpp" #include "Collections.hpp" namespace c3::test { diff --git a/ports/cpp/test/whitebox/WhiteboxTest.cpp b/ports/cpp/test/whitebox/WhiteboxTest.cpp index 09ca3c5..e43f6a8 100644 --- a/ports/cpp/test/whitebox/WhiteboxTest.cpp +++ b/ports/cpp/test/whitebox/WhiteboxTest.cpp @@ -19,7 +19,7 @@ TEST(WhiteboxGrammarTests, CaretAtTransitionToRuleWithNonExhaustiveFollowSet) { EXPECT_EQ(pipeline.listener.GetErrorCount(), 1); c3::CodeCompletionCore completion(&pipeline.parser); - auto candidates = Candidates(completion, 1, ctx); + auto candidates = completion.collectCandidates(1, ctx); EXPECT_THAT(Keys(candidates.tokens), UnorderedElementsAre(WhiteboxLexer::IPSUM, WhiteboxLexer::DOLOR, @@ -34,7 +34,7 @@ TEST(WhiteboxGrammarTests, CaretAtTransitionToRuleWithEmptyFollowSet) { EXPECT_EQ(pipeline.listener.GetErrorCount(), 1); c3::CodeCompletionCore completion(&pipeline.parser); - auto candidates = Candidates(completion, 1, ctx); + auto candidates = completion.collectCandidates(1, ctx); EXPECT_THAT(Keys(candidates.tokens), UnorderedElementsAre(WhiteboxLexer::IPSUM, WhiteboxLexer::DOLOR, @@ -62,7 +62,7 @@ TEST(WhiteboxGrammarTests, CaretAtOneOfMultiplePossibleStates) { }(); c3::CodeCompletionCore completion(&pipeline.parser); - auto candidates = Candidates(completion, 2, ctx); + auto candidates = completion.collectCandidates(2, ctx); EXPECT_THAT(Keys(candidates.tokens), UnorderedElementsAre(WhiteboxLexer::DOLOR)); @@ -78,7 +78,7 @@ TEST(WhiteboxGrammarTests, auto *ctx = pipeline.parser.test8(); c3::CodeCompletionCore completion(&pipeline.parser); - auto candidates = Candidates(completion, 2, ctx); + auto candidates = completion.collectCandidates(2, ctx); EXPECT_THAT(Keys(candidates.tokens), UnorderedElementsAre(WhiteboxLexer::DOLOR));