2021-10-29 21:25:12 +01:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#include "Luau/Autocomplete.h"
|
|
|
|
#include "Luau/BuiltinDefinitions.h"
|
|
|
|
#include "Luau/TypeInfer.h"
|
2023-01-04 20:53:17 +00:00
|
|
|
#include "Luau/Type.h"
|
|
|
|
#include "Luau/VisitType.h"
|
2021-10-29 21:25:12 +01:00
|
|
|
#include "Luau/StringUtils.h"
|
|
|
|
|
|
|
|
#include "Fixture.h"
|
2022-11-16 18:15:01 +00:00
|
|
|
#include "ScopedFlags.h"
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
#include "doctest.h"
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
LUAU_FASTFLAG(LuauTraceTypesInNonstrictMode2)
|
|
|
|
LUAU_FASTFLAG(LuauSetMetatableDoesNotTimeTravel)
|
2023-01-20 20:27:03 +00:00
|
|
|
LUAU_FASTFLAG(LuauFixAutocompleteInWhile)
|
|
|
|
LUAU_FASTFLAG(LuauFixAutocompleteInFor)
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
using namespace Luau;
|
|
|
|
|
2023-01-11 16:28:11 +00:00
|
|
|
static std::optional<AutocompleteEntryMap> nullCallback(std::string tag, std::optional<const ClassType*> ptr, std::optional<std::string> contents)
|
2021-10-29 21:25:12 +01:00
|
|
|
{
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
template<class BaseType>
|
|
|
|
struct ACFixtureImpl : BaseType
|
2021-10-29 21:25:12 +01:00
|
|
|
{
|
2022-04-07 22:29:01 +01:00
|
|
|
ACFixtureImpl()
|
2022-05-13 20:36:37 +01:00
|
|
|
: BaseType(true, true)
|
2022-04-07 22:29:01 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-10-29 21:25:12 +01:00
|
|
|
AutocompleteResult autocomplete(unsigned row, unsigned column)
|
|
|
|
{
|
2021-11-05 02:34:35 +00:00
|
|
|
return Luau::autocomplete(this->frontend, "MainModule", Position{row, column}, nullCallback);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 16:28:11 +00:00
|
|
|
AutocompleteResult autocomplete(char marker, StringCompletionCallback callback = nullCallback)
|
2021-10-29 21:25:12 +01:00
|
|
|
{
|
2023-01-11 16:28:11 +00:00
|
|
|
return Luau::autocomplete(this->frontend, "MainModule", getPosition(marker), callback);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CheckResult check(const std::string& source)
|
|
|
|
{
|
|
|
|
markerPosition.clear();
|
|
|
|
std::string filteredSource;
|
|
|
|
filteredSource.reserve(source.size());
|
|
|
|
|
|
|
|
Position curPos(0, 0);
|
2021-11-05 02:34:35 +00:00
|
|
|
char prevChar{};
|
2021-10-29 21:25:12 +01:00
|
|
|
for (char c : source)
|
|
|
|
{
|
2021-11-05 02:34:35 +00:00
|
|
|
if (prevChar == '@')
|
|
|
|
{
|
|
|
|
LUAU_ASSERT("Illegal marker character" && c >= '0' && c <= '9');
|
|
|
|
LUAU_ASSERT("Duplicate marker found" && markerPosition.count(c) == 0);
|
|
|
|
markerPosition.insert(std::pair{c, curPos});
|
|
|
|
}
|
|
|
|
else if (c == '@')
|
2021-10-29 21:25:12 +01:00
|
|
|
{
|
2021-11-05 02:34:35 +00:00
|
|
|
// skip the '@' character
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
filteredSource.push_back(c);
|
|
|
|
if (c == '\n')
|
|
|
|
{
|
|
|
|
curPos.line++;
|
|
|
|
curPos.column = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
curPos.column++;
|
|
|
|
}
|
|
|
|
}
|
2021-11-05 02:34:35 +00:00
|
|
|
prevChar = c;
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
2021-11-05 02:34:35 +00:00
|
|
|
LUAU_ASSERT("Digit expected after @ symbol" && prevChar != '@');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2022-04-07 22:29:01 +01:00
|
|
|
return BaseType::check(filteredSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
LoadDefinitionFileResult loadDefinition(const std::string& source)
|
|
|
|
{
|
2022-05-26 23:08:16 +01:00
|
|
|
TypeChecker& typeChecker = this->frontend.typeCheckerForAutocomplete;
|
|
|
|
unfreeze(typeChecker.globalTypes);
|
|
|
|
LoadDefinitionFileResult result = loadDefinitionFile(typeChecker, typeChecker.globalScope, source, "@test");
|
|
|
|
freeze(typeChecker.globalTypes);
|
2022-04-07 22:29:01 +01:00
|
|
|
|
2022-05-26 23:08:16 +01:00
|
|
|
REQUIRE_MESSAGE(result.success, "loadDefinition: unable to load definition file");
|
|
|
|
return result;
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
const Position& getPosition(char marker) const
|
|
|
|
{
|
|
|
|
auto i = markerPosition.find(marker);
|
|
|
|
LUAU_ASSERT(i != markerPosition.end());
|
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
|
2021-10-29 21:25:12 +01:00
|
|
|
// Maps a marker character (0-9 inclusive) to a position in the source code.
|
|
|
|
std::map<char, Position> markerPosition;
|
|
|
|
};
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
struct ACFixture : ACFixtureImpl<Fixture>
|
2022-05-13 20:36:37 +01:00
|
|
|
{
|
|
|
|
ACFixture()
|
|
|
|
: ACFixtureImpl<Fixture>()
|
|
|
|
{
|
2022-09-08 23:14:25 +01:00
|
|
|
addGlobalBinding(frontend, "table", Binding{typeChecker.anyType});
|
|
|
|
addGlobalBinding(frontend, "math", Binding{typeChecker.anyType});
|
2022-05-13 20:36:37 +01:00
|
|
|
addGlobalBinding(frontend.typeCheckerForAutocomplete, "table", Binding{typeChecker.anyType});
|
|
|
|
addGlobalBinding(frontend.typeCheckerForAutocomplete, "math", Binding{typeChecker.anyType});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ACBuiltinsFixture : ACFixtureImpl<BuiltinsFixture>
|
2021-11-05 02:34:35 +00:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2021-10-29 21:25:12 +01:00
|
|
|
TEST_SUITE_BEGIN("AutocompleteTest");
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "empty_program")
|
|
|
|
{
|
2021-11-05 02:34:35 +00:00
|
|
|
check(" @1");
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(!ac.entryMap.empty());
|
|
|
|
CHECK(ac.entryMap.count("table"));
|
|
|
|
CHECK(ac.entryMap.count("math"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Statement);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "local_initializer")
|
|
|
|
{
|
2021-11-05 02:34:35 +00:00
|
|
|
check("local a = @1");
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("table"));
|
|
|
|
CHECK(ac.entryMap.count("math"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Expression);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "leave_numbers_alone")
|
|
|
|
{
|
2021-11-05 02:34:35 +00:00
|
|
|
check("local a = 3.@11");
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.empty());
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Unknown);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "user_defined_globals")
|
|
|
|
{
|
2021-11-05 02:34:35 +00:00
|
|
|
check("local myLocal = 4; @1");
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("myLocal"));
|
|
|
|
CHECK(ac.entryMap.count("table"));
|
|
|
|
CHECK(ac.entryMap.count("math"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Statement);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "dont_suggest_local_before_its_definition")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local myLocal = 4
|
|
|
|
function abc()
|
2021-11-05 02:34:35 +00:00
|
|
|
@1 local myInnerLocal = 1
|
|
|
|
@2
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
2021-11-05 02:34:35 +00:00
|
|
|
@3 )");
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("myLocal"));
|
|
|
|
CHECK(!ac.entryMap.count("myInnerLocal"));
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('2');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("myLocal"));
|
|
|
|
CHECK(ac.entryMap.count("myInnerLocal"));
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('3');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("myLocal"));
|
|
|
|
CHECK(!ac.entryMap.count("myInnerLocal"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "recursive_function")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
function foo()
|
2021-11-05 02:34:35 +00:00
|
|
|
@1 end
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("foo"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Statement);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "nested_recursive_function")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local function outer()
|
|
|
|
local function inner()
|
2021-11-05 02:34:35 +00:00
|
|
|
@1 end
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("inner"));
|
|
|
|
CHECK(ac.entryMap.count("outer"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "user_defined_local_functions_in_own_definition")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local function abc()
|
2021-11-05 02:34:35 +00:00
|
|
|
@1
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("abc"));
|
|
|
|
CHECK(ac.entryMap.count("table"));
|
|
|
|
CHECK(ac.entryMap.count("math"));
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local abc = function()
|
2021-11-05 02:34:35 +00:00
|
|
|
@1
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("abc")); // FIXME: This is actually incorrect!
|
|
|
|
CHECK(ac.entryMap.count("table"));
|
|
|
|
CHECK(ac.entryMap.count("math"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "global_functions_are_not_scoped_lexically")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
if true then
|
|
|
|
function abc()
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
2021-11-05 02:34:35 +00:00
|
|
|
@1 )");
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(!ac.entryMap.empty());
|
|
|
|
CHECK(ac.entryMap.count("abc"));
|
|
|
|
CHECK(ac.entryMap.count("table"));
|
|
|
|
CHECK(ac.entryMap.count("math"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "local_functions_fall_out_of_scope")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
if true then
|
|
|
|
local function abc()
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
2021-11-05 02:34:35 +00:00
|
|
|
@1 )");
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK_NE(0, ac.entryMap.size());
|
|
|
|
CHECK(!ac.entryMap.count("abc"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "function_parameters")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
function abc(test)
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
@1 end
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("test"));
|
|
|
|
}
|
|
|
|
|
2022-05-13 20:36:37 +01:00
|
|
|
TEST_CASE_FIXTURE(ACBuiltinsFixture, "get_member_completions")
|
2021-10-29 21:25:12 +01:00
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local a = table.@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2022-03-31 22:01:51 +01:00
|
|
|
CHECK_EQ(17, ac.entryMap.size());
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("find"));
|
|
|
|
CHECK(ac.entryMap.count("pack"));
|
|
|
|
CHECK(!ac.entryMap.count("math"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "nested_member_completions")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local tbl = { abc = { def = 1234, egh = false } }
|
2021-11-05 02:34:35 +00:00
|
|
|
tbl.abc. @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(2, ac.entryMap.size());
|
|
|
|
CHECK(ac.entryMap.count("def"));
|
|
|
|
CHECK(ac.entryMap.count("egh"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "unsealed_table")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local tbl = {}
|
|
|
|
tbl.prop = 5
|
2021-11-05 02:34:35 +00:00
|
|
|
tbl.@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(1, ac.entryMap.size());
|
|
|
|
CHECK(ac.entryMap.count("prop"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "unsealed_table_2")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local tbl = {}
|
|
|
|
local inner = { prop = 5 }
|
|
|
|
tbl.inner = inner
|
2021-11-05 02:34:35 +00:00
|
|
|
tbl.inner. @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(1, ac.entryMap.size());
|
|
|
|
CHECK(ac.entryMap.count("prop"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "cyclic_table")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local abc = {}
|
|
|
|
local def = { abc = abc }
|
|
|
|
abc.def = def
|
2021-11-05 02:34:35 +00:00
|
|
|
abc.def. @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("abc"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "table_union")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
type t1 = { a1 : string, b2 : number }
|
|
|
|
type t2 = { b2 : string, c3 : string }
|
|
|
|
function func(abc : t1 | t2)
|
2021-11-05 02:34:35 +00:00
|
|
|
abc. @1
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(1, ac.entryMap.size());
|
|
|
|
CHECK(ac.entryMap.count("b2"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "table_intersection")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
type t1 = { a1 : string, b2 : number }
|
2023-01-20 20:27:03 +00:00
|
|
|
type t2 = { b2 : number, c3 : string }
|
2021-10-29 21:25:12 +01:00
|
|
|
function func(abc : t1 & t2)
|
2021-11-05 02:34:35 +00:00
|
|
|
abc. @1
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(3, ac.entryMap.size());
|
|
|
|
CHECK(ac.entryMap.count("a1"));
|
|
|
|
CHECK(ac.entryMap.count("b2"));
|
|
|
|
CHECK(ac.entryMap.count("c3"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
2022-05-13 20:36:37 +01:00
|
|
|
TEST_CASE_FIXTURE(ACBuiltinsFixture, "get_string_completions")
|
2021-10-29 21:25:12 +01:00
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local a = ("foo"):@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK_EQ(17, ac.entryMap.size());
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "get_suggestions_for_new_statement")
|
|
|
|
{
|
2021-11-05 02:34:35 +00:00
|
|
|
check("@1");
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK_NE(0, ac.entryMap.size());
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("table"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Statement);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "get_suggestions_for_the_very_start_of_the_script")
|
|
|
|
{
|
2021-11-05 02:34:35 +00:00
|
|
|
check(R"(@1
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
function aaa() end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("table"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Statement);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "method_call_inside_function_body")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local game = { GetService=function(s) return 'hello' end }
|
|
|
|
|
|
|
|
function a()
|
2021-11-05 02:34:35 +00:00
|
|
|
game: @1
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK_NE(0, ac.entryMap.size());
|
|
|
|
|
|
|
|
CHECK(!ac.entryMap.count("math"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
2022-05-13 20:36:37 +01:00
|
|
|
TEST_CASE_FIXTURE(ACBuiltinsFixture, "method_call_inside_if_conditional")
|
2021-10-29 21:25:12 +01:00
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
if table: @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK_NE(0, ac.entryMap.size());
|
|
|
|
CHECK(ac.entryMap.count("concat"));
|
|
|
|
CHECK(!ac.entryMap.count("math"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "statement_between_two_statements")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
function getmyscripts() end
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
g@1
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
getmyscripts()
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK_NE(0, ac.entryMap.size());
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("getmyscripts"));
|
2022-08-10 21:04:08 +01:00
|
|
|
|
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Statement);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "bias_toward_inner_scope")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local A = {one=1}
|
|
|
|
|
|
|
|
function B()
|
|
|
|
local A = {two=2}
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
A @1
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("A"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Statement);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
TypeId t = follow(*ac.entryMap["A"].type);
|
2023-01-04 20:53:17 +00:00
|
|
|
const TableType* tt = get<TableType>(t);
|
2021-10-29 21:25:12 +01:00
|
|
|
REQUIRE(tt);
|
|
|
|
|
|
|
|
CHECK(tt->props.count("two"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "recommend_statement_starting_keywords")
|
|
|
|
{
|
2021-11-05 02:34:35 +00:00
|
|
|
check("@1");
|
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("local"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Statement);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
check("local i = @1");
|
|
|
|
auto ac2 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(!ac2.entryMap.count("local"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac2.context, AutocompleteContext::Expression);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "do_not_overwrite_context_sensitive_kws")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local function continue()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
@1 )");
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
AutocompleteEntry entry = ac.entryMap["continue"];
|
|
|
|
CHECK(entry.kind == AutocompleteEntryKind::Binding);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Statement);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "dont_offer_any_suggestions_from_within_a_comment")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
--!strict
|
|
|
|
local foo = {}
|
|
|
|
function foo:bar() end
|
|
|
|
|
|
|
|
--[[
|
2021-11-05 02:34:35 +00:00
|
|
|
foo:@1
|
2021-10-29 21:25:12 +01:00
|
|
|
]]
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK_EQ(0, ac.entryMap.size());
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Unknown);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "dont_offer_any_suggestions_from_the_end_of_a_comment")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
--!strict@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK_EQ(0, ac.entryMap.size());
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Unknown);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "dont_offer_any_suggestions_from_within_a_broken_comment")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
--[[ @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK_EQ(0, ac.entryMap.size());
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Unknown);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "dont_offer_any_suggestions_from_within_a_broken_comment_at_the_very_end_of_the_file")
|
|
|
|
{
|
2021-11-05 02:34:35 +00:00
|
|
|
check("--[[@1");
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(0, ac.entryMap.size());
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Unknown);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_for_middle_keywords")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
for x @1=
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac1 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac1.entryMap.count("do"), 0);
|
|
|
|
CHECK_EQ(ac1.entryMap.count("end"), 0);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac1.context, AutocompleteContext::Unknown);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
for x =@1 1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac2 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac2.entryMap.count("do"), 0);
|
|
|
|
CHECK_EQ(ac2.entryMap.count("end"), 0);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac2.context, AutocompleteContext::Unknown);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
for x = 1,@1 2
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac3 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(1, ac3.entryMap.size());
|
|
|
|
CHECK_EQ(ac3.entryMap.count("do"), 1);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac3.context, AutocompleteContext::Keyword);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
for x = 1, @12,
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac4 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac4.entryMap.count("do"), 0);
|
|
|
|
CHECK_EQ(ac4.entryMap.count("end"), 0);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac4.context, AutocompleteContext::Expression);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
for x = 1, 2, @15
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac5 = autocomplete('1');
|
2023-01-20 20:27:03 +00:00
|
|
|
if (FFlag::LuauFixAutocompleteInFor)
|
|
|
|
{
|
|
|
|
CHECK_EQ(ac5.entryMap.count("math"), 1);
|
|
|
|
CHECK_EQ(ac5.entryMap.count("do"), 0);
|
|
|
|
CHECK_EQ(ac5.entryMap.count("end"), 0);
|
|
|
|
CHECK_EQ(ac5.context, AutocompleteContext::Expression);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CHECK_EQ(ac5.entryMap.count("do"), 1);
|
|
|
|
CHECK_EQ(ac5.entryMap.count("end"), 0);
|
|
|
|
CHECK_EQ(ac5.context, AutocompleteContext::Keyword);
|
|
|
|
}
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
for x = 1, 2, 5 f@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac6 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac6.entryMap.size(), 1);
|
|
|
|
CHECK_EQ(ac6.entryMap.count("do"), 1);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac6.context, AutocompleteContext::Keyword);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
for x = 1, 2, 5 do @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac7 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac7.entryMap.count("end"), 1);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac7.context, AutocompleteContext::Statement);
|
2023-01-20 20:27:03 +00:00
|
|
|
|
|
|
|
if (FFlag::LuauFixAutocompleteInFor)
|
|
|
|
{
|
|
|
|
check(R"(local Foo = 1
|
|
|
|
for x = @11, @22, @35
|
|
|
|
)");
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i)
|
|
|
|
{
|
|
|
|
auto ac8 = autocomplete('1' + i);
|
|
|
|
CHECK_EQ(ac8.entryMap.count("Foo"), 1);
|
|
|
|
CHECK_EQ(ac8.entryMap.count("do"), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
check(R"(local Foo = 1
|
|
|
|
for x = @11, @22
|
|
|
|
)");
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; ++i)
|
|
|
|
{
|
|
|
|
auto ac9 = autocomplete('1' + i);
|
|
|
|
CHECK_EQ(ac9.entryMap.count("Foo"), 1);
|
|
|
|
CHECK_EQ(ac9.entryMap.count("do"), 0);
|
|
|
|
}
|
|
|
|
}
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_for_in_middle_keywords")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
for @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac1 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(0, ac1.entryMap.size());
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac1.context, AutocompleteContext::Unknown);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
for x@1 @2
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac2 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(0, ac2.entryMap.size());
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac2.context, AutocompleteContext::Unknown);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac2a = autocomplete('2');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(1, ac2a.entryMap.size());
|
|
|
|
CHECK_EQ(1, ac2a.entryMap.count("in"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac2a.context, AutocompleteContext::Keyword);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
for x in y@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac3 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac3.entryMap.count("table"), 1);
|
|
|
|
CHECK_EQ(ac3.entryMap.count("do"), 0);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac3.context, AutocompleteContext::Expression);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
for x in y @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac4 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac4.entryMap.size(), 1);
|
|
|
|
CHECK_EQ(ac4.entryMap.count("do"), 1);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac4.context, AutocompleteContext::Keyword);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
for x in f f@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac5 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac5.entryMap.size(), 1);
|
|
|
|
CHECK_EQ(ac5.entryMap.count("do"), 1);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac5.context, AutocompleteContext::Keyword);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
for x in y do @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac6 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac6.entryMap.count("in"), 0);
|
|
|
|
CHECK_EQ(ac6.entryMap.count("table"), 1);
|
|
|
|
CHECK_EQ(ac6.entryMap.count("end"), 1);
|
|
|
|
CHECK_EQ(ac6.entryMap.count("function"), 1);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac6.context, AutocompleteContext::Statement);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
for x in y do e@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac7 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac7.entryMap.count("in"), 0);
|
|
|
|
CHECK_EQ(ac7.entryMap.count("table"), 1);
|
|
|
|
CHECK_EQ(ac7.entryMap.count("end"), 1);
|
|
|
|
CHECK_EQ(ac7.entryMap.count("function"), 1);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac7.context, AutocompleteContext::Statement);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_while_middle_keywords")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
while@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac1 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac1.entryMap.count("do"), 0);
|
|
|
|
CHECK_EQ(ac1.entryMap.count("end"), 0);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac1.context, AutocompleteContext::Expression);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
while true @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac2 = autocomplete('1');
|
2023-01-20 20:27:03 +00:00
|
|
|
if (FFlag::LuauFixAutocompleteInWhile)
|
|
|
|
{
|
|
|
|
CHECK_EQ(3, ac2.entryMap.size());
|
|
|
|
CHECK_EQ(ac2.entryMap.count("do"), 1);
|
|
|
|
CHECK_EQ(ac2.entryMap.count("and"), 1);
|
|
|
|
CHECK_EQ(ac2.entryMap.count("or"), 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CHECK_EQ(1, ac2.entryMap.size());
|
|
|
|
CHECK_EQ(ac2.entryMap.count("do"), 1);
|
|
|
|
}
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac2.context, AutocompleteContext::Keyword);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
while true do @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac3 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac3.entryMap.count("end"), 1);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac3.context, AutocompleteContext::Statement);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
while true d@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac4 = autocomplete('1');
|
2023-01-20 20:27:03 +00:00
|
|
|
if (FFlag::LuauFixAutocompleteInWhile)
|
|
|
|
{
|
|
|
|
CHECK_EQ(3, ac4.entryMap.size());
|
|
|
|
CHECK_EQ(ac4.entryMap.count("do"), 1);
|
|
|
|
CHECK_EQ(ac4.entryMap.count("and"), 1);
|
|
|
|
CHECK_EQ(ac4.entryMap.count("or"), 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CHECK_EQ(1, ac4.entryMap.size());
|
|
|
|
CHECK_EQ(ac4.entryMap.count("do"), 1);
|
|
|
|
}
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac4.context, AutocompleteContext::Keyword);
|
2023-01-20 20:27:03 +00:00
|
|
|
|
|
|
|
if (FFlag::LuauFixAutocompleteInWhile)
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
while t@1
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac5 = autocomplete('1');
|
|
|
|
CHECK_EQ(ac5.entryMap.count("do"), 0);
|
|
|
|
CHECK_EQ(ac5.entryMap.count("true"), 1);
|
|
|
|
CHECK_EQ(ac5.entryMap.count("false"), 1);
|
|
|
|
}
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_if_middle_keywords")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
if @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac1 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac1.entryMap.count("then"), 0);
|
|
|
|
CHECK_EQ(ac1.entryMap.count("function"),
|
|
|
|
1); // FIXME: This is kind of dumb. It is technically syntactically valid but you can never do anything interesting with this.
|
|
|
|
CHECK_EQ(ac1.entryMap.count("table"), 1);
|
|
|
|
CHECK_EQ(ac1.entryMap.count("else"), 0);
|
|
|
|
CHECK_EQ(ac1.entryMap.count("elseif"), 0);
|
|
|
|
CHECK_EQ(ac1.entryMap.count("end"), 0);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac1.context, AutocompleteContext::Expression);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
if x @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac2 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac2.entryMap.count("then"), 1);
|
|
|
|
CHECK_EQ(ac2.entryMap.count("function"), 0);
|
|
|
|
CHECK_EQ(ac2.entryMap.count("else"), 0);
|
|
|
|
CHECK_EQ(ac2.entryMap.count("elseif"), 0);
|
|
|
|
CHECK_EQ(ac2.entryMap.count("end"), 0);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac2.context, AutocompleteContext::Keyword);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
Sync to upstream/release/562 (#828)
* Fixed rare use-after-free in analysis during table unification
A lot of work these past months went into two new Luau components:
* A near full rewrite of the typechecker using a new deferred constraint
resolution system
* Native code generation for AoT/JiT compilation of VM bytecode into x64
(avx)/arm64 instructions
Both of these components are far from finished and we don't provide
documentation on building and using them at this point.
However, curious community members expressed interest in learning about
changes that go into these components each week, so we are now listing
them here in the 'sync' pull request descriptions.
---
New typechecker can be enabled by setting
DebugLuauDeferredConstraintResolution flag to 'true'.
It is considered unstable right now, so try it at your own risk.
Even though it already provides better type inference than the current
one in some cases, our main goal right now is to reach feature parity
with current typechecker.
Features which improve over the capabilities of the current typechecker
are marked as '(NEW)'.
Changes to new typechecker:
* Regular for loop index and parameters are now typechecked
* Invalid type annotations on local variables are ignored to improve
autocomplete
* Fixed missing autocomplete type suggestions for function arguments
* Type reduction is now performed to produce simpler types to be
presented to the user (error messages, custom LSPs)
* Internally, complex types like '((number | string) & ~(false?)) |
string' can be produced, which is just 'string | number' when simplified
* Fixed spots where support for unknown and never types was missing
* (NEW) Length operator '#' is now valid to use on top table type, this
type comes up when doing typeof(x) == "table" guards and isn't available
in current typechecker
---
Changes to native code generation:
* Additional math library fast calls are now lowered to x64: math.ldexp,
math.round, math.frexp, math.modf, math.sign and math.clamp
2023-02-03 19:26:13 +00:00
|
|
|
check(R"(
|
|
|
|
if x t@1
|
|
|
|
)");
|
2023-01-13 22:10:01 +00:00
|
|
|
|
Sync to upstream/release/562 (#828)
* Fixed rare use-after-free in analysis during table unification
A lot of work these past months went into two new Luau components:
* A near full rewrite of the typechecker using a new deferred constraint
resolution system
* Native code generation for AoT/JiT compilation of VM bytecode into x64
(avx)/arm64 instructions
Both of these components are far from finished and we don't provide
documentation on building and using them at this point.
However, curious community members expressed interest in learning about
changes that go into these components each week, so we are now listing
them here in the 'sync' pull request descriptions.
---
New typechecker can be enabled by setting
DebugLuauDeferredConstraintResolution flag to 'true'.
It is considered unstable right now, so try it at your own risk.
Even though it already provides better type inference than the current
one in some cases, our main goal right now is to reach feature parity
with current typechecker.
Features which improve over the capabilities of the current typechecker
are marked as '(NEW)'.
Changes to new typechecker:
* Regular for loop index and parameters are now typechecked
* Invalid type annotations on local variables are ignored to improve
autocomplete
* Fixed missing autocomplete type suggestions for function arguments
* Type reduction is now performed to produce simpler types to be
presented to the user (error messages, custom LSPs)
* Internally, complex types like '((number | string) & ~(false?)) |
string' can be produced, which is just 'string | number' when simplified
* Fixed spots where support for unknown and never types was missing
* (NEW) Length operator '#' is now valid to use on top table type, this
type comes up when doing typeof(x) == "table" guards and isn't available
in current typechecker
---
Changes to native code generation:
* Additional math library fast calls are now lowered to x64: math.ldexp,
math.round, math.frexp, math.modf, math.sign and math.clamp
2023-02-03 19:26:13 +00:00
|
|
|
auto ac3 = autocomplete('1');
|
|
|
|
CHECK_EQ(3, ac3.entryMap.size());
|
|
|
|
CHECK_EQ(ac3.entryMap.count("then"), 1);
|
|
|
|
CHECK_EQ(ac3.entryMap.count("and"), 1);
|
|
|
|
CHECK_EQ(ac3.entryMap.count("or"), 1);
|
|
|
|
CHECK_EQ(ac3.context, AutocompleteContext::Keyword);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
|
|
|
if x then
|
2021-11-05 02:34:35 +00:00
|
|
|
@1
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac4 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac4.entryMap.count("then"), 0);
|
|
|
|
CHECK_EQ(ac4.entryMap.count("else"), 1);
|
|
|
|
CHECK_EQ(ac4.entryMap.count("function"), 1);
|
|
|
|
CHECK_EQ(ac4.entryMap.count("elseif"), 1);
|
|
|
|
CHECK_EQ(ac4.entryMap.count("end"), 0);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac4.context, AutocompleteContext::Statement);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
|
|
|
if x then
|
2021-11-05 02:34:35 +00:00
|
|
|
t@1
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac4a = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac4a.entryMap.count("then"), 0);
|
|
|
|
CHECK_EQ(ac4a.entryMap.count("table"), 1);
|
|
|
|
CHECK_EQ(ac4a.entryMap.count("else"), 1);
|
|
|
|
CHECK_EQ(ac4a.entryMap.count("elseif"), 1);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac4a.context, AutocompleteContext::Statement);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
|
|
|
if x then
|
2021-11-05 02:34:35 +00:00
|
|
|
@1
|
2021-10-29 21:25:12 +01:00
|
|
|
elseif x then
|
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac5 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac5.entryMap.count("then"), 0);
|
|
|
|
CHECK_EQ(ac5.entryMap.count("function"), 1);
|
|
|
|
CHECK_EQ(ac5.entryMap.count("else"), 0);
|
|
|
|
CHECK_EQ(ac5.entryMap.count("elseif"), 0);
|
|
|
|
CHECK_EQ(ac5.entryMap.count("end"), 0);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac5.context, AutocompleteContext::Statement);
|
2023-01-20 20:27:03 +00:00
|
|
|
|
Sync to upstream/release/562 (#828)
* Fixed rare use-after-free in analysis during table unification
A lot of work these past months went into two new Luau components:
* A near full rewrite of the typechecker using a new deferred constraint
resolution system
* Native code generation for AoT/JiT compilation of VM bytecode into x64
(avx)/arm64 instructions
Both of these components are far from finished and we don't provide
documentation on building and using them at this point.
However, curious community members expressed interest in learning about
changes that go into these components each week, so we are now listing
them here in the 'sync' pull request descriptions.
---
New typechecker can be enabled by setting
DebugLuauDeferredConstraintResolution flag to 'true'.
It is considered unstable right now, so try it at your own risk.
Even though it already provides better type inference than the current
one in some cases, our main goal right now is to reach feature parity
with current typechecker.
Features which improve over the capabilities of the current typechecker
are marked as '(NEW)'.
Changes to new typechecker:
* Regular for loop index and parameters are now typechecked
* Invalid type annotations on local variables are ignored to improve
autocomplete
* Fixed missing autocomplete type suggestions for function arguments
* Type reduction is now performed to produce simpler types to be
presented to the user (error messages, custom LSPs)
* Internally, complex types like '((number | string) & ~(false?)) |
string' can be produced, which is just 'string | number' when simplified
* Fixed spots where support for unknown and never types was missing
* (NEW) Length operator '#' is now valid to use on top table type, this
type comes up when doing typeof(x) == "table" guards and isn't available
in current typechecker
---
Changes to native code generation:
* Additional math library fast calls are now lowered to x64: math.ldexp,
math.round, math.frexp, math.modf, math.sign and math.clamp
2023-02-03 19:26:13 +00:00
|
|
|
check(R"(
|
|
|
|
if t@1
|
|
|
|
)");
|
2023-01-13 22:10:01 +00:00
|
|
|
|
Sync to upstream/release/562 (#828)
* Fixed rare use-after-free in analysis during table unification
A lot of work these past months went into two new Luau components:
* A near full rewrite of the typechecker using a new deferred constraint
resolution system
* Native code generation for AoT/JiT compilation of VM bytecode into x64
(avx)/arm64 instructions
Both of these components are far from finished and we don't provide
documentation on building and using them at this point.
However, curious community members expressed interest in learning about
changes that go into these components each week, so we are now listing
them here in the 'sync' pull request descriptions.
---
New typechecker can be enabled by setting
DebugLuauDeferredConstraintResolution flag to 'true'.
It is considered unstable right now, so try it at your own risk.
Even though it already provides better type inference than the current
one in some cases, our main goal right now is to reach feature parity
with current typechecker.
Features which improve over the capabilities of the current typechecker
are marked as '(NEW)'.
Changes to new typechecker:
* Regular for loop index and parameters are now typechecked
* Invalid type annotations on local variables are ignored to improve
autocomplete
* Fixed missing autocomplete type suggestions for function arguments
* Type reduction is now performed to produce simpler types to be
presented to the user (error messages, custom LSPs)
* Internally, complex types like '((number | string) & ~(false?)) |
string' can be produced, which is just 'string | number' when simplified
* Fixed spots where support for unknown and never types was missing
* (NEW) Length operator '#' is now valid to use on top table type, this
type comes up when doing typeof(x) == "table" guards and isn't available
in current typechecker
---
Changes to native code generation:
* Additional math library fast calls are now lowered to x64: math.ldexp,
math.round, math.frexp, math.modf, math.sign and math.clamp
2023-02-03 19:26:13 +00:00
|
|
|
auto ac6 = autocomplete('1');
|
|
|
|
CHECK_EQ(ac6.entryMap.count("true"), 1);
|
|
|
|
CHECK_EQ(ac6.entryMap.count("false"), 1);
|
|
|
|
CHECK_EQ(ac6.entryMap.count("then"), 0);
|
|
|
|
CHECK_EQ(ac6.entryMap.count("function"), 1);
|
|
|
|
CHECK_EQ(ac6.entryMap.count("else"), 0);
|
|
|
|
CHECK_EQ(ac6.entryMap.count("elseif"), 0);
|
|
|
|
CHECK_EQ(ac6.entryMap.count("end"), 0);
|
|
|
|
CHECK_EQ(ac6.context, AutocompleteContext::Expression);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_until_in_repeat")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
repeat @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac.entryMap.count("table"), 1);
|
|
|
|
CHECK_EQ(ac.entryMap.count("until"), 1);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Statement);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_until_expression")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
repeat
|
2021-11-05 02:34:35 +00:00
|
|
|
until @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac.entryMap.count("table"), 1);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Expression);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "local_names")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local ab@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac1 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac1.entryMap.size(), 1);
|
|
|
|
CHECK_EQ(ac1.entryMap.count("function"), 1);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac1.context, AutocompleteContext::Unknown);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local ab, cd@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac2 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac2.entryMap.empty());
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac2.context, AutocompleteContext::Unknown);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_end_with_fn_exprs")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local function f() @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac.entryMap.count("end"), 1);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Statement);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_end_with_lambda")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local a = function() local bar = foo en@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac.entryMap.count("end"), 1);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Statement);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "stop_at_first_stat_when_recommending_keywords")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
repeat
|
2021-11-05 02:34:35 +00:00
|
|
|
for x @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac1 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac1.entryMap.count("in"), 1);
|
|
|
|
CHECK_EQ(ac1.entryMap.count("until"), 0);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac1.context, AutocompleteContext::Keyword);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_repeat_middle_keyword")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
repeat @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac1 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac1.entryMap.count("do"), 1);
|
|
|
|
CHECK_EQ(ac1.entryMap.count("function"), 1);
|
|
|
|
CHECK_EQ(ac1.entryMap.count("until"), 1);
|
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
repeat f f@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac2 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac2.entryMap.count("function"), 1);
|
|
|
|
CHECK_EQ(ac2.entryMap.count("until"), 1);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
repeat
|
2021-11-05 02:34:35 +00:00
|
|
|
u@1
|
2021-10-29 21:25:12 +01:00
|
|
|
until
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac3 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac3.entryMap.count("until"), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "local_function")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local f@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac1 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac1.entryMap.size(), 1);
|
|
|
|
CHECK_EQ(ac1.entryMap.count("function"), 1);
|
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local f@1, cd
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac2 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac2.entryMap.empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "local_function")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local function @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.empty());
|
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local function @1s@2
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.empty());
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('2');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.empty());
|
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local function @1()@2
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.empty());
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('2');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("end"));
|
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local function something@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.empty());
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local tbl = {}
|
2021-11-05 02:34:35 +00:00
|
|
|
function tbl.something@1() end
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "local_function_params")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local function @1a@2bc(@3d@4ef)@5 @6
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
CHECK(autocomplete('1').entryMap.empty());
|
|
|
|
CHECK(autocomplete('2').entryMap.empty());
|
|
|
|
CHECK(autocomplete('3').entryMap.empty());
|
|
|
|
CHECK(autocomplete('4').entryMap.empty());
|
|
|
|
CHECK(!autocomplete('5').entryMap.empty());
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
CHECK(!autocomplete('6').entryMap.empty());
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local function abc(def)
|
2021-11-05 02:34:35 +00:00
|
|
|
@1 end
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
|
|
|
for (unsigned int i = 23; i < 31; ++i)
|
|
|
|
{
|
|
|
|
CHECK(autocomplete(1, i).entryMap.empty());
|
|
|
|
}
|
|
|
|
CHECK(!autocomplete(1, 32).entryMap.empty());
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac2 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac2.entryMap.count("abc"), 1);
|
|
|
|
CHECK_EQ(ac2.entryMap.count("def"), 1);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac2.context, AutocompleteContext::Statement);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local function abc(def, ghi@1)
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac3 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac3.entryMap.empty());
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac3.context, AutocompleteContext::Unknown);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "global_function_params")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
function abc(def)
|
|
|
|
)");
|
|
|
|
|
|
|
|
for (unsigned int i = 17; i < 25; ++i)
|
|
|
|
{
|
|
|
|
CHECK(autocomplete(1, i).entryMap.empty());
|
|
|
|
}
|
|
|
|
CHECK(!autocomplete(1, 26).entryMap.empty());
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
function abc(def)
|
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
|
|
|
for (unsigned int i = 17; i < 25; ++i)
|
|
|
|
{
|
|
|
|
CHECK(autocomplete(1, i).entryMap.empty());
|
|
|
|
}
|
|
|
|
CHECK(!autocomplete(1, 26).entryMap.empty());
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
function abc(def)
|
2021-11-05 02:34:35 +00:00
|
|
|
@1
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac2 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac2.entryMap.count("abc"), 1);
|
|
|
|
CHECK_EQ(ac2.entryMap.count("def"), 1);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac2.context, AutocompleteContext::Statement);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
function abc(def, ghi@1)
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac3 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac3.entryMap.empty());
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac3.context, AutocompleteContext::Unknown);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "arguments_to_global_lambda")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
abc = function(def, ghi@1)
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "function_expr_params")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
abc = function(def) @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
|
|
|
for (unsigned int i = 20; i < 27; ++i)
|
|
|
|
{
|
|
|
|
CHECK(autocomplete(1, i).entryMap.empty());
|
|
|
|
}
|
2021-11-05 02:34:35 +00:00
|
|
|
CHECK(!autocomplete('1').entryMap.empty());
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
abc = function(def) @1
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
|
|
|
for (unsigned int i = 20; i < 27; ++i)
|
|
|
|
{
|
|
|
|
CHECK(autocomplete(1, i).entryMap.empty());
|
|
|
|
}
|
2021-11-05 02:34:35 +00:00
|
|
|
CHECK(!autocomplete('1').entryMap.empty());
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
|
|
|
abc = function(def)
|
2021-11-05 02:34:35 +00:00
|
|
|
@1
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac2 = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac2.entryMap.count("def"), 1);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac2.context, AutocompleteContext::Statement);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "local_initializer")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local a = t@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(ac.entryMap.count("table"), 1);
|
|
|
|
CHECK_EQ(ac.entryMap.count("true"), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "local_initializer_2")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local a=@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("table"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "get_member_completions")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local a = 12.@13
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "sometimes_the_metatable_is_an_error")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local T = {}
|
|
|
|
T.__index = T
|
|
|
|
|
|
|
|
function T.new()
|
|
|
|
return setmetatable({x=6}, X) -- oops!
|
|
|
|
end
|
|
|
|
local t = T.new()
|
2021-11-05 02:34:35 +00:00
|
|
|
t. @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
// Don't crash!
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "local_types_builtin")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local a: n@1
|
2021-10-29 21:25:12 +01:00
|
|
|
local b: string = "don't trip"
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("nil"));
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Type);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "private_types")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
do
|
|
|
|
type num = number
|
2021-11-05 02:34:35 +00:00
|
|
|
local a: n@1u
|
|
|
|
local b: nu@2m
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
2021-11-05 02:34:35 +00:00
|
|
|
local a: nu@3
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("num"));
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('2');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("num"));
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('3');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(!ac.entryMap.count("num"));
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "type_scoping_easy")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
type Table = { a: number, b: number }
|
|
|
|
do
|
|
|
|
type Table = { x: string, y: string }
|
2021-11-05 02:34:35 +00:00
|
|
|
local a: T@1
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
REQUIRE(ac.entryMap.count("Table"));
|
|
|
|
REQUIRE(ac.entryMap["Table"].type);
|
2023-01-04 20:53:17 +00:00
|
|
|
const TableType* tv = get<TableType>(follow(*ac.entryMap["Table"].type));
|
2021-10-29 21:25:12 +01:00
|
|
|
REQUIRE(tv);
|
|
|
|
CHECK(tv->props.count("x"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "modules_with_types")
|
|
|
|
{
|
|
|
|
fileResolver.source["Module/A"] = R"(
|
|
|
|
export type A = { x: number, y: number }
|
|
|
|
export type B = { z: number, w: number }
|
|
|
|
return {}
|
|
|
|
)";
|
|
|
|
|
|
|
|
LUAU_REQUIRE_NO_ERRORS(frontend.check("Module/A"));
|
|
|
|
|
|
|
|
fileResolver.source["Module/B"] = R"(
|
|
|
|
local aaa = require(script.Parent.A)
|
|
|
|
local a: aa
|
|
|
|
)";
|
|
|
|
|
|
|
|
frontend.check("Module/B");
|
|
|
|
|
|
|
|
auto ac = Luau::autocomplete(frontend, "Module/B", Position{2, 11}, nullCallback);
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("aaa"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Type);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "module_type_members")
|
|
|
|
{
|
|
|
|
fileResolver.source["Module/A"] = R"(
|
|
|
|
export type A = { x: number, y: number }
|
|
|
|
export type B = { z: number, w: number }
|
|
|
|
return {}
|
|
|
|
)";
|
|
|
|
|
|
|
|
LUAU_REQUIRE_NO_ERRORS(frontend.check("Module/A"));
|
|
|
|
|
|
|
|
fileResolver.source["Module/B"] = R"(
|
|
|
|
local aaa = require(script.Parent.A)
|
|
|
|
local a: aaa.
|
|
|
|
)";
|
|
|
|
|
|
|
|
frontend.check("Module/B");
|
|
|
|
|
|
|
|
auto ac = Luau::autocomplete(frontend, "Module/B", Position{2, 13}, nullCallback);
|
|
|
|
|
|
|
|
CHECK_EQ(2, ac.entryMap.size());
|
|
|
|
CHECK(ac.entryMap.count("A"));
|
|
|
|
CHECK(ac.entryMap.count("B"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Type);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "argument_types")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local function f(a: n@1
|
2021-10-29 21:25:12 +01:00
|
|
|
local b: string = "don't trip"
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("nil"));
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Type);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "return_types")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local function f(a: number): n@1
|
2021-10-29 21:25:12 +01:00
|
|
|
local b: string = "don't trip"
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("nil"));
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Type);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "as_types")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local a: any = 5
|
2021-11-05 02:34:35 +00:00
|
|
|
local b: number = (a :: n@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("nil"));
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Type);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "function_type_types")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local a: (n@1
|
|
|
|
local b: (number, (n@2
|
|
|
|
local c: (number, (number) -> n@3
|
|
|
|
local d: (number, (number) -> (number, n@4
|
|
|
|
local e: (n: n@5
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("nil"));
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('2');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("nil"));
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('3');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("nil"));
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('4');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("nil"));
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('5');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("nil"));
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "generic_types")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
function f<Tee, Use>(a: T@1
|
2021-10-29 21:25:12 +01:00
|
|
|
local b: string = "don't trip"
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("Tee"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Type);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "type_correct_suggestion_in_argument")
|
|
|
|
{
|
|
|
|
// local
|
|
|
|
check(R"(
|
|
|
|
local function target(a: number, b: string) return a + #b end
|
|
|
|
|
|
|
|
local one = 4
|
|
|
|
local two = "hello"
|
2021-11-05 02:34:35 +00:00
|
|
|
return target(o@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("one"));
|
|
|
|
CHECK(ac.entryMap["one"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
CHECK(ac.entryMap["two"].typeCorrect == TypeCorrectKind::None);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local function target(a: number, b: string) return a + #b end
|
|
|
|
|
|
|
|
local one = 4
|
|
|
|
local two = "hello"
|
2021-11-05 02:34:35 +00:00
|
|
|
return target(one, t@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("two"));
|
|
|
|
CHECK(ac.entryMap["two"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
CHECK(ac.entryMap["one"].typeCorrect == TypeCorrectKind::None);
|
|
|
|
|
|
|
|
// member
|
|
|
|
check(R"(
|
|
|
|
local function target(a: number, b: string) return a + #b end
|
|
|
|
|
|
|
|
local a = { one = 4, two = "hello" }
|
2021-11-05 02:34:35 +00:00
|
|
|
return target(a.@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("one"));
|
|
|
|
CHECK(ac.entryMap["one"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
CHECK(ac.entryMap["two"].typeCorrect == TypeCorrectKind::None);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local function target(a: number, b: string) return a + #b end
|
|
|
|
|
|
|
|
local a = { one = 4, two = "hello" }
|
2021-11-05 02:34:35 +00:00
|
|
|
return target(a.one, a.@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("two"));
|
|
|
|
CHECK(ac.entryMap["two"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
CHECK(ac.entryMap["one"].typeCorrect == TypeCorrectKind::None);
|
|
|
|
|
|
|
|
// union match
|
|
|
|
check(R"(
|
|
|
|
local function target(a: string?) return #b end
|
|
|
|
|
|
|
|
local a = { one = 4, two = "hello" }
|
2021-11-05 02:34:35 +00:00
|
|
|
return target(a.@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("two"));
|
|
|
|
CHECK(ac.entryMap["two"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
CHECK(ac.entryMap["one"].typeCorrect == TypeCorrectKind::None);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "type_correct_suggestion_in_table")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
type Foo = { a: number, b: string }
|
|
|
|
local a = { one = 4, two = "hello" }
|
2021-11-05 02:34:35 +00:00
|
|
|
local b: Foo = { a = a.@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("one"));
|
|
|
|
CHECK(ac.entryMap["one"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
CHECK(ac.entryMap["two"].typeCorrect == TypeCorrectKind::None);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
|
|
|
type Foo = { a: number, b: string }
|
|
|
|
local a = { one = 4, two = "hello" }
|
2021-11-05 02:34:35 +00:00
|
|
|
local b: Foo = { b = a.@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("two"));
|
|
|
|
CHECK(ac.entryMap["two"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
CHECK(ac.entryMap["one"].typeCorrect == TypeCorrectKind::None);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "type_correct_function_return_types")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local function target(a: number, b: string) return a + #b end
|
|
|
|
local function bar1(a: number) return -a end
|
2022-01-06 23:26:14 +00:00
|
|
|
local function bar2(a: string) return a .. 'x' end
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
return target(b@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("bar1"));
|
|
|
|
CHECK(ac.entryMap["bar1"].typeCorrect == TypeCorrectKind::CorrectFunctionResult);
|
|
|
|
CHECK(ac.entryMap["bar2"].typeCorrect == TypeCorrectKind::None);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local function target(a: number, b: string) return a + #b end
|
|
|
|
local function bar1(a: number) return -a end
|
|
|
|
local function bar2(a: string) return a .. 'x' end
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
return target(bar1, b@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("bar2"));
|
|
|
|
CHECK(ac.entryMap["bar2"].typeCorrect == TypeCorrectKind::CorrectFunctionResult);
|
|
|
|
CHECK(ac.entryMap["bar1"].typeCorrect == TypeCorrectKind::None);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local function target(a: number, b: string) return a + #b end
|
|
|
|
local function bar1(a: number): (...number) return -a, a end
|
2022-01-06 23:26:14 +00:00
|
|
|
local function bar2(a: string) return a .. 'x' end
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
return target(b@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("bar1"));
|
|
|
|
CHECK(ac.entryMap["bar1"].typeCorrect == TypeCorrectKind::CorrectFunctionResult);
|
|
|
|
CHECK(ac.entryMap["bar2"].typeCorrect == TypeCorrectKind::None);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "type_correct_local_type_suggestion")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local b: s@1 = "str"
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("string"));
|
|
|
|
CHECK(ac.entryMap["string"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local function f() return "str" end
|
2021-11-05 02:34:35 +00:00
|
|
|
local b: s@1 = f()
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("string"));
|
|
|
|
CHECK(ac.entryMap["string"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local b: s@1, c: n@2 = "str", 2
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("string"));
|
|
|
|
CHECK(ac.entryMap["string"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('2');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap["number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local function f() return 1, "str", 3 end
|
2021-11-05 02:34:35 +00:00
|
|
|
local a: b@1, b: n@2, c: s@3, d: n@4 = false, f()
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("boolean"));
|
|
|
|
CHECK(ac.entryMap["boolean"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('2');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap["number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('3');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("string"));
|
|
|
|
CHECK(ac.entryMap["string"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('4');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap["number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local function f(): ...number return 1, 2, 3 end
|
2021-11-05 02:34:35 +00:00
|
|
|
local a: boolean, b: n@1 = false, f()
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap["number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "type_correct_function_type_suggestion")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local b: (n@1) -> number = function(a: number, b: string) return a + #b end
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap["number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local b: (number, s@1 = function(a: number, b: string) return a + #b end
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("string"));
|
|
|
|
CHECK(ac.entryMap["string"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local b: (number, string) -> b@1 = function(a: number, b: string): boolean return a + #b == 0 end
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("boolean"));
|
|
|
|
CHECK(ac.entryMap["boolean"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local b: (number, ...s@1) = function(a: number, ...: string) return a end
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("string"));
|
|
|
|
CHECK(ac.entryMap["string"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local b: (number) -> ...s@1 = function(a: number): ...string return "a", "b", "c" end
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("string"));
|
|
|
|
CHECK(ac.entryMap["string"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "type_correct_full_type_suggestion")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local b:@1 @2= "str"
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("string"));
|
|
|
|
CHECK(ac.entryMap["string"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('2');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("string"));
|
|
|
|
CHECK(ac.entryMap["string"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local b: @1= function(a: number) return -a end
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("(number) -> number"));
|
|
|
|
CHECK(ac.entryMap["(number) -> number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "type_correct_argument_type_suggestion")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local function target(a: number, b: string) return a + #b end
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
local function d(a: n@1, b)
|
2021-11-05 15:47:21 +00:00
|
|
|
return target(a, b)
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap["number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local function target(a: number, b: string) return a + #b end
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
local function d(a, b: s@1)
|
2021-11-05 15:47:21 +00:00
|
|
|
return target(a, b)
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("string"));
|
|
|
|
CHECK(ac.entryMap["string"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local function target(a: number, b: string) return a + #b end
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
local function d(a:@1 @2, b)
|
2021-11-05 15:47:21 +00:00
|
|
|
return target(a, b)
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap["number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('2');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap["number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local function target(a: number, b: string) return a + #b end
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
local function d(a, b: @1)@2: number
|
2021-11-05 15:47:21 +00:00
|
|
|
return target(a, b)
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("string"));
|
|
|
|
CHECK(ac.entryMap["string"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('2');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap["string"].typeCorrect == TypeCorrectKind::None);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "type_correct_expected_argument_type_suggestion")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local function target(callback: (a: number, b: string) -> number) return callback(4, "hello") end
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
local x = target(function(a: @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap["number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local function target(callback: (a: number, b: string) -> number) return callback(4, "hello") end
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
local x = target(function(a: n@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap["number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local function target(callback: (a: number, b: string) -> number) return callback(4, "hello") end
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
local x = target(function(a: n@1, b: @2)
|
2021-11-05 15:47:21 +00:00
|
|
|
return a + #b
|
2021-10-29 21:25:12 +01:00
|
|
|
end)
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap["number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('2');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("string"));
|
|
|
|
CHECK(ac.entryMap["string"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local function target(callback: (...number) -> number) return callback(1, 2, 3) end
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
local x = target(function(a: n@1)
|
2021-11-05 15:47:21 +00:00
|
|
|
return a
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap["number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "type_correct_expected_argument_type_pack_suggestion")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local function target(callback: (...number) -> number) return callback(1, 2, 3) end
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
local x = target(function(...:n@1)
|
2021-11-05 15:47:21 +00:00
|
|
|
return a
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap["number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local function target(callback: (...number) -> number) return callback(1, 2, 3) end
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
local x = target(function(a:number, b:number, ...:@1)
|
2021-11-05 15:47:21 +00:00
|
|
|
return a + b
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap["number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "type_correct_expected_return_type_suggestion")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local function target(callback: () -> number) return callback() end
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
local x = target(function(): n@1
|
2021-11-05 15:47:21 +00:00
|
|
|
return 1
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap["number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local function target(callback: () -> (number, number)) return callback() end
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
local x = target(function(): (number, n@1
|
2021-11-05 15:47:21 +00:00
|
|
|
return 1, 2
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap["number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "type_correct_expected_return_type_pack_suggestion")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local function target(callback: () -> ...number) return callback() end
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
local x = target(function(): ...n@1
|
2021-11-05 15:47:21 +00:00
|
|
|
return 1, 2, 3
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap["number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local function target(callback: () -> ...number) return callback() end
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
local x = target(function(): (number, number, ...n@1
|
2021-11-05 15:47:21 +00:00
|
|
|
return 1, 2, 3
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap["number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "type_correct_expected_argument_type_suggestion_optional")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local function target(callback: nil | (a: number, b: string) -> number) return callback(4, "hello") end
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
local x = target(function(a: @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap["number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "type_correct_expected_argument_type_suggestion_self")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local t = {}
|
|
|
|
t.x = 5
|
|
|
|
function t:target(callback: (a: number, b: string) -> number) return callback(self.x, "hello") end
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
local x = t:target(function(a: @1, b:@2 ) end)
|
|
|
|
local y = t.target(t, function(a: number, b: @3) end)
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap["number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('2');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("string"));
|
|
|
|
CHECK(ac.entryMap["string"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('3');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("string"));
|
|
|
|
CHECK(ac.entryMap["string"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "do_not_suggest_internal_module_type")
|
|
|
|
{
|
|
|
|
fileResolver.source["Module/A"] = R"(
|
|
|
|
type done = { x: number, y: number }
|
|
|
|
local function a(a: (done) -> number) return a({x=1, y=2}) end
|
|
|
|
local function b(a: ((done) -> number) -> number) return a(function(done) return 1 end) end
|
|
|
|
return {a = a, b = b}
|
|
|
|
)";
|
|
|
|
|
|
|
|
LUAU_REQUIRE_NO_ERRORS(frontend.check("Module/A"));
|
|
|
|
|
|
|
|
fileResolver.source["Module/B"] = R"(
|
|
|
|
local ex = require(script.Parent.A)
|
|
|
|
ex.a(function(x:
|
|
|
|
)";
|
|
|
|
|
|
|
|
frontend.check("Module/B");
|
|
|
|
|
|
|
|
auto ac = Luau::autocomplete(frontend, "Module/B", Position{2, 16}, nullCallback);
|
|
|
|
|
|
|
|
CHECK(!ac.entryMap.count("done"));
|
|
|
|
|
|
|
|
fileResolver.source["Module/C"] = R"(
|
|
|
|
local ex = require(script.Parent.A)
|
|
|
|
ex.b(function(x:
|
|
|
|
)";
|
|
|
|
|
|
|
|
frontend.check("Module/C");
|
|
|
|
|
|
|
|
ac = Luau::autocomplete(frontend, "Module/C", Position{2, 16}, nullCallback);
|
|
|
|
|
|
|
|
CHECK(!ac.entryMap.count("(done) -> number"));
|
|
|
|
}
|
|
|
|
|
2022-05-13 20:36:37 +01:00
|
|
|
TEST_CASE_FIXTURE(ACBuiltinsFixture, "suggest_external_module_type")
|
2021-10-29 21:25:12 +01:00
|
|
|
{
|
|
|
|
fileResolver.source["Module/A"] = R"(
|
|
|
|
export type done = { x: number, y: number }
|
|
|
|
local function a(a: (done) -> number) return a({x=1, y=2}) end
|
|
|
|
local function b(a: ((done) -> number) -> number) return a(function(done) return 1 end) end
|
|
|
|
return {a = a, b = b}
|
|
|
|
)";
|
|
|
|
|
|
|
|
LUAU_REQUIRE_NO_ERRORS(frontend.check("Module/A"));
|
|
|
|
|
|
|
|
fileResolver.source["Module/B"] = R"(
|
|
|
|
local ex = require(script.Parent.A)
|
|
|
|
ex.a(function(x:
|
|
|
|
)";
|
|
|
|
|
|
|
|
frontend.check("Module/B");
|
|
|
|
|
|
|
|
auto ac = Luau::autocomplete(frontend, "Module/B", Position{2, 16}, nullCallback);
|
|
|
|
|
|
|
|
CHECK(!ac.entryMap.count("done"));
|
|
|
|
CHECK(ac.entryMap.count("ex.done"));
|
|
|
|
CHECK(ac.entryMap["ex.done"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
|
|
|
fileResolver.source["Module/C"] = R"(
|
|
|
|
local ex = require(script.Parent.A)
|
|
|
|
ex.b(function(x:
|
|
|
|
)";
|
|
|
|
|
|
|
|
frontend.check("Module/C");
|
|
|
|
|
|
|
|
ac = Luau::autocomplete(frontend, "Module/C", Position{2, 16}, nullCallback);
|
|
|
|
|
|
|
|
CHECK(!ac.entryMap.count("(done) -> number"));
|
|
|
|
CHECK(ac.entryMap.count("(ex.done) -> number"));
|
|
|
|
CHECK(ac.entryMap["(ex.done) -> number"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "do_not_suggest_synthetic_table_name")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local foo = { a = 1, b = 2 }
|
2021-11-05 02:34:35 +00:00
|
|
|
local bar: @1= foo
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(!ac.entryMap.count("foo"));
|
|
|
|
}
|
|
|
|
|
2022-03-11 16:55:02 +00:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "type_correct_function_no_parenthesis")
|
2021-10-29 21:25:12 +01:00
|
|
|
{
|
2022-03-11 16:55:02 +00:00
|
|
|
check(R"(
|
2021-10-29 21:25:12 +01:00
|
|
|
local function target(a: (number) -> number) return a(4) end
|
|
|
|
local function bar1(a: number) return -a end
|
2022-01-06 23:26:14 +00:00
|
|
|
local function bar2(a: string) return a .. 'x' end
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
return target(b@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2022-03-11 16:55:02 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("bar1"));
|
|
|
|
CHECK(ac.entryMap["bar1"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
CHECK(ac.entryMap["bar1"].parens == ParenthesesRecommendation::None);
|
|
|
|
CHECK(ac.entryMap["bar2"].typeCorrect == TypeCorrectKind::None);
|
|
|
|
}
|
|
|
|
|
2021-12-03 06:41:04 +00:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "function_in_assignment_has_parentheses")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local function bar(a: number) return -a end
|
|
|
|
local abc = b@1
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("bar"));
|
|
|
|
CHECK(ac.entryMap["bar"].parens == ParenthesesRecommendation::CursorInside);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "function_result_passed_to_function_has_parentheses")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local function foo() return 1 end
|
|
|
|
local function bar(a: number) return -a end
|
2022-08-04 23:35:33 +01:00
|
|
|
local abc = bar(@1)
|
2021-12-03 06:41:04 +00:00
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("foo"));
|
|
|
|
CHECK(ac.entryMap["foo"].parens == ParenthesesRecommendation::CursorAfter);
|
|
|
|
}
|
|
|
|
|
2021-10-29 21:25:12 +01:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "type_correct_sealed_table")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local function f(a: { x: number, y: number }) return a.x + a.y end
|
2021-11-05 02:34:35 +00:00
|
|
|
local fp: @1= f
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2022-06-17 02:05:14 +01:00
|
|
|
REQUIRE_EQ("({| x: number, y: number |}) -> number", toString(requireType("f")));
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("({ x: number, y: number }) -> number"));
|
|
|
|
}
|
|
|
|
|
2022-03-11 16:55:02 +00:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "type_correct_keywords")
|
2021-10-29 21:25:12 +01:00
|
|
|
{
|
2022-03-11 16:55:02 +00:00
|
|
|
check(R"(
|
2021-10-29 21:25:12 +01:00
|
|
|
local function a(x: boolean) end
|
|
|
|
local function b(x: number?) end
|
|
|
|
local function c(x: (number) -> string) end
|
|
|
|
local function d(x: ((number) -> string)?) end
|
|
|
|
local function e(x: ((number) -> string) & ((boolean) -> number)) end
|
|
|
|
|
|
|
|
local tru = {}
|
|
|
|
local ni = false
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
local ac = a(t@1)
|
|
|
|
local bc = b(n@2)
|
|
|
|
local cc = c(f@3)
|
|
|
|
local dc = d(f@4)
|
|
|
|
local ec = e(f@5)
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2022-03-11 16:55:02 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("tru"));
|
|
|
|
CHECK(ac.entryMap["tru"].typeCorrect == TypeCorrectKind::None);
|
|
|
|
CHECK(ac.entryMap["true"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
CHECK(ac.entryMap["false"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
2022-03-11 16:55:02 +00:00
|
|
|
ac = autocomplete('2');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("ni"));
|
|
|
|
CHECK(ac.entryMap["ni"].typeCorrect == TypeCorrectKind::None);
|
|
|
|
CHECK(ac.entryMap["nil"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
2022-03-11 16:55:02 +00:00
|
|
|
ac = autocomplete('3');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("false"));
|
|
|
|
CHECK(ac.entryMap["false"].typeCorrect == TypeCorrectKind::None);
|
|
|
|
CHECK(ac.entryMap["function"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
2022-03-11 16:55:02 +00:00
|
|
|
ac = autocomplete('4');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap["function"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
2022-03-11 16:55:02 +00:00
|
|
|
ac = autocomplete('5');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap["function"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "type_correct_suggestion_for_overloads")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local target: ((number) -> string) & ((string) -> number))
|
|
|
|
|
|
|
|
local one = 4
|
|
|
|
local two = "hello"
|
2021-11-05 02:34:35 +00:00
|
|
|
return target(o@1)
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("one"));
|
|
|
|
CHECK(ac.entryMap["one"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
CHECK(ac.entryMap["two"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local target: ((number) -> string) & ((number) -> number))
|
|
|
|
|
|
|
|
local one = 4
|
|
|
|
local two = "hello"
|
2021-11-05 02:34:35 +00:00
|
|
|
return target(o@1)
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("one"));
|
|
|
|
CHECK(ac.entryMap["one"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
CHECK(ac.entryMap["two"].typeCorrect == TypeCorrectKind::None);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local target: ((number, number) -> string) & ((string) -> number))
|
|
|
|
|
|
|
|
local one = 4
|
|
|
|
local two = "hello"
|
2021-11-05 02:34:35 +00:00
|
|
|
return target(1, o@1)
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("one"));
|
|
|
|
CHECK(ac.entryMap["one"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
CHECK(ac.entryMap["two"].typeCorrect == TypeCorrectKind::None);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "optional_members")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local a = { x = 2, y = 3 }
|
|
|
|
type A = typeof(a)
|
|
|
|
local b: A? = a
|
2021-11-05 02:34:35 +00:00
|
|
|
return b.@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK_EQ(2, ac.entryMap.size());
|
|
|
|
CHECK(ac.entryMap.count("x"));
|
|
|
|
CHECK(ac.entryMap.count("y"));
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local a = { x = 2, y = 3 }
|
|
|
|
type A = typeof(a)
|
|
|
|
local b: nil | A = a
|
2021-11-05 02:34:35 +00:00
|
|
|
return b.@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK_EQ(2, ac.entryMap.size());
|
|
|
|
CHECK(ac.entryMap.count("x"));
|
|
|
|
CHECK(ac.entryMap.count("y"));
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local b: nil | nil
|
2021-11-05 02:34:35 +00:00
|
|
|
return b.@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK_EQ(0, ac.entryMap.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "no_function_name_suggestions")
|
|
|
|
{
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
function na@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.empty());
|
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local function @1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.empty());
|
|
|
|
|
|
|
|
check(R"(
|
2021-11-05 02:34:35 +00:00
|
|
|
local function na@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(ac.entryMap.empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "skip_current_local")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local other = 1
|
2021-11-05 02:34:35 +00:00
|
|
|
local name = na@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(!ac.entryMap.count("name"));
|
|
|
|
CHECK(ac.entryMap.count("other"));
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local other = 1
|
2021-11-05 02:34:35 +00:00
|
|
|
local name, test = na@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK(!ac.entryMap.count("name"));
|
|
|
|
CHECK(!ac.entryMap.count("test"));
|
|
|
|
CHECK(ac.entryMap.count("other"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "keyword_members")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local a = { done = 1, forever = 2 }
|
2021-11-05 02:34:35 +00:00
|
|
|
local b = a.do@1
|
|
|
|
local c = a.for@2
|
|
|
|
local d = a.@3
|
2021-10-29 21:25:12 +01:00
|
|
|
do
|
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK_EQ(2, ac.entryMap.size());
|
|
|
|
CHECK(ac.entryMap.count("done"));
|
|
|
|
CHECK(ac.entryMap.count("forever"));
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('2');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK_EQ(2, ac.entryMap.size());
|
|
|
|
CHECK(ac.entryMap.count("done"));
|
|
|
|
CHECK(ac.entryMap.count("forever"));
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('3');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK_EQ(2, ac.entryMap.size());
|
|
|
|
CHECK(ac.entryMap.count("done"));
|
|
|
|
CHECK(ac.entryMap.count("forever"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "keyword_methods")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local a = {}
|
|
|
|
function a:done() end
|
2021-11-05 02:34:35 +00:00
|
|
|
local b = a:do@1
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
CHECK_EQ(1, ac.entryMap.size());
|
|
|
|
CHECK(ac.entryMap.count("done"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "keyword_types")
|
|
|
|
{
|
|
|
|
fileResolver.source["Module/A"] = R"(
|
|
|
|
export type done = { x: number, y: number }
|
|
|
|
export type other = { z: number, w: number }
|
|
|
|
return {}
|
|
|
|
)";
|
|
|
|
|
|
|
|
LUAU_REQUIRE_NO_ERRORS(frontend.check("Module/A"));
|
|
|
|
|
|
|
|
fileResolver.source["Module/B"] = R"(
|
|
|
|
local aaa = require(script.Parent.A)
|
|
|
|
local a: aaa.do
|
|
|
|
)";
|
|
|
|
|
|
|
|
frontend.check("Module/B");
|
|
|
|
|
|
|
|
auto ac = Luau::autocomplete(frontend, "Module/B", Position{2, 15}, nullCallback);
|
|
|
|
|
|
|
|
CHECK_EQ(2, ac.entryMap.size());
|
|
|
|
CHECK(ac.entryMap.count("done"));
|
|
|
|
CHECK(ac.entryMap.count("other"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-14 23:52:26 +01:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "comments")
|
2021-10-29 21:25:12 +01:00
|
|
|
{
|
2022-07-14 23:52:26 +01:00
|
|
|
fileResolver.source["Comments"] = "--!str";
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2022-07-14 23:52:26 +01:00
|
|
|
auto ac = Luau::autocomplete(frontend, "Comments", Position{0, 6}, nullCallback);
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK_EQ(0, ac.entryMap.size());
|
|
|
|
}
|
|
|
|
|
2022-05-13 20:36:37 +01:00
|
|
|
TEST_CASE_FIXTURE(ACBuiltinsFixture, "autocompleteProp_index_function_metamethod_is_variadic")
|
2021-10-29 21:25:12 +01:00
|
|
|
{
|
2022-07-14 23:52:26 +01:00
|
|
|
fileResolver.source["Module/A"] = R"(
|
2021-10-29 21:25:12 +01:00
|
|
|
type Foo = {x: number}
|
|
|
|
local t = {}
|
|
|
|
setmetatable(t, {
|
|
|
|
__index = function(index: string): ...Foo
|
|
|
|
return {x = 1}, {x = 2}
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
local a = t. -- Line 9
|
|
|
|
-- | Column 20
|
|
|
|
)";
|
|
|
|
|
2022-07-14 23:52:26 +01:00
|
|
|
auto ac = Luau::autocomplete(frontend, "Module/A", Position{9, 20}, nullCallback);
|
2021-10-29 21:25:12 +01:00
|
|
|
REQUIRE_EQ(1, ac.entryMap.size());
|
|
|
|
CHECK(ac.entryMap.count("x"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "if_then_else_full_keywords")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local thenceforth = false
|
|
|
|
local elsewhere = false
|
|
|
|
local doover = false
|
|
|
|
local endurance = true
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
if 1 then@1
|
|
|
|
else@2
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
while false do@3
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
repeat@4
|
2021-10-29 21:25:12 +01:00
|
|
|
until
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.size() == 1);
|
|
|
|
CHECK(ac.entryMap.count("then"));
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('2');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("else"));
|
|
|
|
CHECK(ac.entryMap.count("elseif"));
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('3');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("do"));
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('4');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("do"));
|
|
|
|
|
|
|
|
// FIXME: ideally we want to handle start and end of all statements as well
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "if_then_else_elseif_completions")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local elsewhere = false
|
|
|
|
|
|
|
|
if true then
|
|
|
|
return 1
|
2021-11-05 02:34:35 +00:00
|
|
|
el@1
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("else"));
|
|
|
|
CHECK(ac.entryMap.count("elseif"));
|
|
|
|
CHECK(ac.entryMap.count("elsewhere") == 0);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local elsewhere = false
|
|
|
|
|
|
|
|
if true then
|
|
|
|
return 1
|
|
|
|
else
|
|
|
|
return 2
|
2021-11-05 02:34:35 +00:00
|
|
|
el@1
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("else") == 0);
|
|
|
|
CHECK(ac.entryMap.count("elseif") == 0);
|
|
|
|
CHECK(ac.entryMap.count("elsewhere"));
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local elsewhere = false
|
|
|
|
|
|
|
|
if true then
|
|
|
|
print("1")
|
|
|
|
elif true then
|
|
|
|
print("2")
|
2021-11-05 02:34:35 +00:00
|
|
|
el@1
|
2021-10-29 21:25:12 +01:00
|
|
|
end
|
|
|
|
)");
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("else"));
|
|
|
|
CHECK(ac.entryMap.count("elseif"));
|
|
|
|
CHECK(ac.entryMap.count("elsewhere"));
|
|
|
|
}
|
|
|
|
|
2022-07-14 23:52:26 +01:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "not_the_var_we_are_defining")
|
2021-10-29 21:25:12 +01:00
|
|
|
{
|
2022-07-14 23:52:26 +01:00
|
|
|
fileResolver.source["Module/A"] = "abc,de";
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2022-07-14 23:52:26 +01:00
|
|
|
auto ac = Luau::autocomplete(frontend, "Module/A", Position{0, 6}, nullCallback);
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(!ac.entryMap.count("de"));
|
|
|
|
}
|
|
|
|
|
2022-07-14 23:52:26 +01:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "recursive_function_global")
|
2021-10-29 21:25:12 +01:00
|
|
|
{
|
2022-07-14 23:52:26 +01:00
|
|
|
fileResolver.source["global"] = R"(function abc()
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
end
|
|
|
|
)";
|
|
|
|
|
2022-07-14 23:52:26 +01:00
|
|
|
auto ac = Luau::autocomplete(frontend, "global", Position{1, 0}, nullCallback);
|
|
|
|
CHECK(ac.entryMap.count("abc"));
|
|
|
|
}
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2022-07-14 23:52:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "recursive_function_local")
|
|
|
|
{
|
|
|
|
fileResolver.source["local"] = R"(local function abc()
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
end
|
|
|
|
)";
|
|
|
|
|
2022-07-14 23:52:26 +01:00
|
|
|
auto ac = Luau::autocomplete(frontend, "local", Position{1, 0}, nullCallback);
|
|
|
|
CHECK(ac.entryMap.count("abc"));
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "suggest_table_keys")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
type Test = { first: number, second: number }
|
2021-11-05 02:34:35 +00:00
|
|
|
local t: Test = { f@1 }
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("first"));
|
|
|
|
CHECK(ac.entryMap.count("second"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
// Intersection
|
|
|
|
check(R"(
|
|
|
|
type Test = { first: number } & { second: number }
|
2021-11-05 02:34:35 +00:00
|
|
|
local t: Test = { f@1 }
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("first"));
|
|
|
|
CHECK(ac.entryMap.count("second"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
// Union
|
|
|
|
check(R"(
|
|
|
|
type Test = { first: number, second: number } | { second: number, third: number }
|
2021-11-05 02:34:35 +00:00
|
|
|
local t: Test = { s@1 }
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("second"));
|
|
|
|
CHECK(!ac.entryMap.count("first"));
|
|
|
|
CHECK(!ac.entryMap.count("third"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
// No parenthesis suggestion
|
|
|
|
check(R"(
|
|
|
|
type Test = { first: (number) -> number, second: number }
|
2021-11-05 02:34:35 +00:00
|
|
|
local t: Test = { f@1 }
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("first"));
|
|
|
|
CHECK(ac.entryMap["first"].parens == ParenthesesRecommendation::None);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
// When key is changed
|
|
|
|
check(R"(
|
|
|
|
type Test = { first: number, second: number }
|
2021-11-05 02:34:35 +00:00
|
|
|
local t: Test = { f@1 = 2 }
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("first"));
|
|
|
|
CHECK(ac.entryMap.count("second"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
// Alternative key syntax
|
|
|
|
check(R"(
|
|
|
|
type Test = { first: number, second: number }
|
2021-11-05 02:34:35 +00:00
|
|
|
local t: Test = { ["f@1"] }
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("first"));
|
|
|
|
CHECK(ac.entryMap.count("second"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
// Not an alternative key syntax
|
|
|
|
check(R"(
|
|
|
|
type Test = { first: number, second: number }
|
2021-11-05 02:34:35 +00:00
|
|
|
local t: Test = { "f@1" }
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(!ac.entryMap.count("first"));
|
|
|
|
CHECK(!ac.entryMap.count("second"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::String);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
// Skip keys that are already defined
|
|
|
|
check(R"(
|
|
|
|
type Test = { first: number, second: number }
|
2021-11-05 02:34:35 +00:00
|
|
|
local t: Test = { first = 2, s@1 }
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(!ac.entryMap.count("first"));
|
|
|
|
CHECK(ac.entryMap.count("second"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
// Don't skip active key
|
|
|
|
check(R"(
|
|
|
|
type Test = { first: number, second: number }
|
2021-11-05 02:34:35 +00:00
|
|
|
local t: Test = { first@1 }
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("first"));
|
|
|
|
CHECK(ac.entryMap.count("second"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
// Inference after first key
|
|
|
|
check(R"(
|
|
|
|
local t = {
|
|
|
|
{ first = 5, second = 10 },
|
2021-11-05 02:34:35 +00:00
|
|
|
{ f@1 }
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("first"));
|
|
|
|
CHECK(ac.entryMap.count("second"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local t = {
|
|
|
|
[2] = { first = 5, second = 10 },
|
2021-11-05 02:34:35 +00:00
|
|
|
[5] = { f@1 }
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
)");
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
CHECK(ac.entryMap.count("first"));
|
|
|
|
CHECK(ac.entryMap.count("second"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Property);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
2022-04-07 22:29:01 +01:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_documentation_symbols")
|
2021-10-29 21:25:12 +01:00
|
|
|
{
|
2022-03-11 16:55:02 +00:00
|
|
|
loadDefinition(R"(
|
2021-10-29 21:25:12 +01:00
|
|
|
declare y: {
|
|
|
|
x: number,
|
|
|
|
}
|
|
|
|
)");
|
|
|
|
|
2022-04-07 22:29:01 +01:00
|
|
|
check(R"(
|
|
|
|
local a = y.@1
|
|
|
|
)");
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2022-04-07 22:29:01 +01:00
|
|
|
auto ac = autocomplete('1');
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
REQUIRE(ac.entryMap.count("x"));
|
|
|
|
CHECK_EQ(ac.entryMap["x"].documentationSymbol, "@test/global/y.x");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_ifelse_expressions")
|
|
|
|
{
|
2022-02-04 16:45:57 +00:00
|
|
|
check(R"(
|
2021-10-29 21:25:12 +01:00
|
|
|
local temp = false
|
|
|
|
local even = true;
|
|
|
|
local a = true
|
2021-11-05 02:34:35 +00:00
|
|
|
a = if t@1emp then t
|
|
|
|
a = if temp t@2
|
|
|
|
a = if temp then e@3
|
|
|
|
a = if temp then even e@4
|
|
|
|
a = if temp then even elseif t@5
|
|
|
|
a = if temp then even elseif true t@6
|
|
|
|
a = if temp then even elseif true then t@7
|
|
|
|
a = if temp then even elseif true then temp e@8
|
|
|
|
a = if temp then even elseif true then temp else e@9
|
2021-10-29 21:25:12 +01:00
|
|
|
)");
|
|
|
|
|
2022-02-04 16:45:57 +00:00
|
|
|
auto ac = autocomplete('1');
|
|
|
|
CHECK(ac.entryMap.count("temp"));
|
|
|
|
CHECK(ac.entryMap.count("true"));
|
|
|
|
CHECK(ac.entryMap.count("then") == 0);
|
|
|
|
CHECK(ac.entryMap.count("else") == 0);
|
|
|
|
CHECK(ac.entryMap.count("elseif") == 0);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Expression);
|
2022-02-04 16:45:57 +00:00
|
|
|
|
|
|
|
ac = autocomplete('2');
|
|
|
|
CHECK(ac.entryMap.count("temp") == 0);
|
|
|
|
CHECK(ac.entryMap.count("true") == 0);
|
|
|
|
CHECK(ac.entryMap.count("then"));
|
|
|
|
CHECK(ac.entryMap.count("else") == 0);
|
|
|
|
CHECK(ac.entryMap.count("elseif") == 0);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Keyword);
|
2022-02-04 16:45:57 +00:00
|
|
|
|
|
|
|
ac = autocomplete('3');
|
|
|
|
CHECK(ac.entryMap.count("even"));
|
|
|
|
CHECK(ac.entryMap.count("then") == 0);
|
|
|
|
CHECK(ac.entryMap.count("else") == 0);
|
|
|
|
CHECK(ac.entryMap.count("elseif") == 0);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Expression);
|
2022-02-04 16:45:57 +00:00
|
|
|
|
|
|
|
ac = autocomplete('4');
|
|
|
|
CHECK(ac.entryMap.count("even") == 0);
|
|
|
|
CHECK(ac.entryMap.count("then") == 0);
|
|
|
|
CHECK(ac.entryMap.count("else"));
|
|
|
|
CHECK(ac.entryMap.count("elseif"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Keyword);
|
2022-02-04 16:45:57 +00:00
|
|
|
|
|
|
|
ac = autocomplete('5');
|
|
|
|
CHECK(ac.entryMap.count("temp"));
|
|
|
|
CHECK(ac.entryMap.count("true"));
|
|
|
|
CHECK(ac.entryMap.count("then") == 0);
|
|
|
|
CHECK(ac.entryMap.count("else") == 0);
|
|
|
|
CHECK(ac.entryMap.count("elseif") == 0);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Expression);
|
2022-02-04 16:45:57 +00:00
|
|
|
|
|
|
|
ac = autocomplete('6');
|
|
|
|
CHECK(ac.entryMap.count("temp") == 0);
|
|
|
|
CHECK(ac.entryMap.count("true") == 0);
|
|
|
|
CHECK(ac.entryMap.count("then"));
|
|
|
|
CHECK(ac.entryMap.count("else") == 0);
|
|
|
|
CHECK(ac.entryMap.count("elseif") == 0);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Keyword);
|
2022-02-04 16:45:57 +00:00
|
|
|
|
|
|
|
ac = autocomplete('7');
|
|
|
|
CHECK(ac.entryMap.count("temp"));
|
|
|
|
CHECK(ac.entryMap.count("true"));
|
|
|
|
CHECK(ac.entryMap.count("then") == 0);
|
|
|
|
CHECK(ac.entryMap.count("else") == 0);
|
|
|
|
CHECK(ac.entryMap.count("elseif") == 0);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Expression);
|
2022-02-04 16:45:57 +00:00
|
|
|
|
|
|
|
ac = autocomplete('8');
|
|
|
|
CHECK(ac.entryMap.count("even") == 0);
|
|
|
|
CHECK(ac.entryMap.count("then") == 0);
|
|
|
|
CHECK(ac.entryMap.count("else"));
|
|
|
|
CHECK(ac.entryMap.count("elseif"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Keyword);
|
2022-02-04 16:45:57 +00:00
|
|
|
|
|
|
|
ac = autocomplete('9');
|
|
|
|
CHECK(ac.entryMap.count("then") == 0);
|
|
|
|
CHECK(ac.entryMap.count("else") == 0);
|
|
|
|
CHECK(ac.entryMap.count("elseif") == 0);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Expression);
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
2022-02-18 01:18:01 +00:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_if_else_regression")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local abcdef = 0;
|
|
|
|
local temp = false
|
|
|
|
local even = true;
|
|
|
|
local a
|
|
|
|
a = if temp then even else@1
|
|
|
|
a = if temp then even else @2
|
|
|
|
a = if temp then even else abc@3
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
CHECK(ac.entryMap.count("else") == 0);
|
|
|
|
ac = autocomplete('2');
|
|
|
|
CHECK(ac.entryMap.count("else") == 0);
|
|
|
|
ac = autocomplete('3');
|
|
|
|
CHECK(ac.entryMap.count("abcdef"));
|
|
|
|
}
|
|
|
|
|
2022-11-16 18:15:01 +00:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_interpolated_string_constant")
|
2022-08-24 20:01:00 +01:00
|
|
|
{
|
2022-11-16 18:15:01 +00:00
|
|
|
check(R"(f(`@1`))");
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
CHECK(ac.entryMap.empty());
|
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::String);
|
|
|
|
|
|
|
|
check(R"(f(`@1 {"a"}`))");
|
|
|
|
ac = autocomplete('1');
|
|
|
|
CHECK(ac.entryMap.empty());
|
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::String);
|
|
|
|
|
|
|
|
check(R"(f(`{"a"} @1`))");
|
|
|
|
ac = autocomplete('1');
|
|
|
|
CHECK(ac.entryMap.empty());
|
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::String);
|
|
|
|
|
|
|
|
check(R"(f(`{"a"} @1 {"b"}`))");
|
|
|
|
ac = autocomplete('1');
|
|
|
|
CHECK(ac.entryMap.empty());
|
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::String);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_interpolated_string_expression")
|
|
|
|
{
|
2022-08-24 20:01:00 +01:00
|
|
|
check(R"(f(`expression = {@1}`))");
|
2022-11-16 18:15:01 +00:00
|
|
|
auto ac = autocomplete('1');
|
|
|
|
CHECK(ac.entryMap.count("table"));
|
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Expression);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_interpolated_string_expression_with_comments")
|
|
|
|
{
|
|
|
|
check(R"(f(`expression = {--[[ bla bla bla ]]@1`))");
|
2022-08-24 20:01:00 +01:00
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
CHECK(ac.entryMap.count("table"));
|
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Expression);
|
2022-11-16 18:15:01 +00:00
|
|
|
|
|
|
|
check(R"(f(`expression = {@1 --[[ bla bla bla ]]`))");
|
|
|
|
ac = autocomplete('1');
|
|
|
|
CHECK(!ac.entryMap.empty());
|
|
|
|
CHECK(ac.entryMap.count("table"));
|
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Expression);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_interpolated_string_as_singleton")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
--!strict
|
|
|
|
local function f(a: "cat" | "dog") end
|
|
|
|
|
|
|
|
f(`@1`)
|
|
|
|
f(`uhhh{'try'}@2`)
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
CHECK(ac.entryMap.count("cat"));
|
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::String);
|
|
|
|
|
|
|
|
ac = autocomplete('2');
|
|
|
|
CHECK(ac.entryMap.empty());
|
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::String);
|
2022-08-24 20:01:00 +01:00
|
|
|
}
|
|
|
|
|
2021-11-05 02:34:35 +00:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_explicit_type_pack")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
type A<T...> = () -> T...
|
|
|
|
local a: A<(number, s@1>
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap.count("string"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Type);
|
2021-11-05 02:34:35 +00:00
|
|
|
}
|
|
|
|
|
2021-12-10 22:05:05 +00:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_first_function_arg_expected_type")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local function foo1() return 1 end
|
|
|
|
local function foo2() return "1" end
|
|
|
|
|
|
|
|
local function bar0() return "got" .. a end
|
|
|
|
local function bar1(a: number) return "got " .. a end
|
|
|
|
local function bar2(a: number, b: string) return "got " .. a .. b end
|
|
|
|
|
|
|
|
local t = {}
|
|
|
|
function t:bar1(a: number) return "got " .. a end
|
|
|
|
|
|
|
|
local r1 = bar0(@1)
|
|
|
|
local r2 = bar1(@2)
|
|
|
|
local r3 = bar2(@3)
|
|
|
|
local r4 = t:bar1(@4)
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
REQUIRE(ac.entryMap.count("foo1"));
|
|
|
|
CHECK(ac.entryMap["foo1"].typeCorrect == TypeCorrectKind::None);
|
|
|
|
REQUIRE(ac.entryMap.count("foo2"));
|
|
|
|
CHECK(ac.entryMap["foo2"].typeCorrect == TypeCorrectKind::None);
|
|
|
|
|
|
|
|
ac = autocomplete('2');
|
|
|
|
|
|
|
|
REQUIRE(ac.entryMap.count("foo1"));
|
|
|
|
CHECK(ac.entryMap["foo1"].typeCorrect == TypeCorrectKind::CorrectFunctionResult);
|
|
|
|
REQUIRE(ac.entryMap.count("foo2"));
|
|
|
|
CHECK(ac.entryMap["foo2"].typeCorrect == TypeCorrectKind::None);
|
|
|
|
|
|
|
|
ac = autocomplete('3');
|
|
|
|
|
|
|
|
REQUIRE(ac.entryMap.count("foo1"));
|
|
|
|
CHECK(ac.entryMap["foo1"].typeCorrect == TypeCorrectKind::CorrectFunctionResult);
|
|
|
|
REQUIRE(ac.entryMap.count("foo2"));
|
|
|
|
CHECK(ac.entryMap["foo2"].typeCorrect == TypeCorrectKind::None);
|
|
|
|
|
|
|
|
ac = autocomplete('4');
|
|
|
|
|
|
|
|
REQUIRE(ac.entryMap.count("foo1"));
|
|
|
|
CHECK(ac.entryMap["foo1"].typeCorrect == TypeCorrectKind::CorrectFunctionResult);
|
|
|
|
REQUIRE(ac.entryMap.count("foo2"));
|
|
|
|
CHECK(ac.entryMap["foo2"].typeCorrect == TypeCorrectKind::None);
|
|
|
|
}
|
|
|
|
|
2022-01-14 16:20:09 +00:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_default_type_parameters")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
type A<T = @1> = () -> T
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap.count("string"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Type);
|
2022-01-14 16:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_default_type_pack_parameters")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
type A<T... = ...@1> = () -> T
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("number"));
|
|
|
|
CHECK(ac.entryMap.count("string"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Type);
|
2022-01-14 16:20:09 +00:00
|
|
|
}
|
|
|
|
|
2022-05-13 20:36:37 +01:00
|
|
|
TEST_CASE_FIXTURE(ACBuiltinsFixture, "autocomplete_oop_implicit_self")
|
2022-01-14 16:20:09 +00:00
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
--!strict
|
|
|
|
local Class = {}
|
|
|
|
Class.__index = Class
|
|
|
|
type Class = typeof(setmetatable({} :: { x: number }, Class))
|
|
|
|
function Class.new(x: number): Class
|
2022-05-13 20:36:37 +01:00
|
|
|
return setmetatable({x = x}, Class)
|
2022-01-14 16:20:09 +00:00
|
|
|
end
|
|
|
|
function Class.getx(self: Class)
|
2022-05-13 20:36:37 +01:00
|
|
|
return self.x
|
2022-01-14 16:20:09 +00:00
|
|
|
end
|
|
|
|
function test()
|
2022-05-13 20:36:37 +01:00
|
|
|
local c = Class.new(42)
|
|
|
|
local n = c:@1
|
|
|
|
print(n)
|
2022-01-14 16:20:09 +00:00
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("getx"));
|
|
|
|
}
|
|
|
|
|
2022-05-13 20:36:37 +01:00
|
|
|
TEST_CASE_FIXTURE(ACBuiltinsFixture, "autocomplete_on_string_singletons")
|
2022-01-27 23:46:05 +00:00
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
--!strict
|
|
|
|
local foo: "hello" | "bye" = "hello"
|
|
|
|
foo:@1
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("format"));
|
|
|
|
}
|
|
|
|
|
2022-04-07 22:29:01 +01:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_string_singletons")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
type tag = "cat" | "dog"
|
|
|
|
local function f(a: tag) end
|
|
|
|
f("@1")
|
|
|
|
f(@2)
|
|
|
|
local x: tag = "@3"
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("cat"));
|
|
|
|
CHECK(ac.entryMap.count("dog"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::String);
|
2022-04-07 22:29:01 +01:00
|
|
|
|
|
|
|
ac = autocomplete('2');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("\"cat\""));
|
|
|
|
CHECK(ac.entryMap.count("\"dog\""));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Expression);
|
2022-04-07 22:29:01 +01:00
|
|
|
|
|
|
|
ac = autocomplete('3');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("cat"));
|
|
|
|
CHECK(ac.entryMap.count("dog"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::String);
|
2022-04-07 22:29:01 +01:00
|
|
|
|
|
|
|
check(R"(
|
|
|
|
type tagged = {tag:"cat", fieldx:number} | {tag:"dog", fieldy:number}
|
|
|
|
local x: tagged = {tag="@4"}
|
|
|
|
)");
|
|
|
|
|
|
|
|
ac = autocomplete('4');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("cat"));
|
|
|
|
CHECK(ac.entryMap.count("dog"));
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::String);
|
2022-04-07 22:29:01 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 19:57:01 +00:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "string_singleton_as_table_key")
|
|
|
|
{
|
|
|
|
ScopedFastFlag sff{"LuauCompleteTableKeysBetter", true};
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
type Direction = "up" | "down"
|
|
|
|
|
|
|
|
local a: {[Direction]: boolean} = {[@1] = true}
|
|
|
|
local b: {[Direction]: boolean} = {["@2"] = true}
|
|
|
|
local c: {[Direction]: boolean} = {u@3 = true}
|
|
|
|
local d: {[Direction]: boolean} = {[u@4] = true}
|
|
|
|
|
|
|
|
local e: {[Direction]: boolean} = {[@5]}
|
|
|
|
local f: {[Direction]: boolean} = {["@6"]}
|
|
|
|
local g: {[Direction]: boolean} = {u@7}
|
|
|
|
local h: {[Direction]: boolean} = {[u@8]}
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("\"up\""));
|
|
|
|
CHECK(ac.entryMap.count("\"down\""));
|
|
|
|
|
|
|
|
ac = autocomplete('2');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("up"));
|
|
|
|
CHECK(ac.entryMap.count("down"));
|
|
|
|
|
|
|
|
ac = autocomplete('3');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("up"));
|
|
|
|
CHECK(ac.entryMap.count("down"));
|
|
|
|
|
|
|
|
ac = autocomplete('4');
|
|
|
|
|
|
|
|
CHECK(!ac.entryMap.count("up"));
|
|
|
|
CHECK(!ac.entryMap.count("down"));
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("\"up\""));
|
|
|
|
CHECK(ac.entryMap.count("\"down\""));
|
|
|
|
|
|
|
|
ac = autocomplete('5');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("\"up\""));
|
|
|
|
CHECK(ac.entryMap.count("\"down\""));
|
|
|
|
|
|
|
|
ac = autocomplete('6');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("up"));
|
|
|
|
CHECK(ac.entryMap.count("down"));
|
|
|
|
|
|
|
|
ac = autocomplete('7');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("up"));
|
|
|
|
CHECK(ac.entryMap.count("down"));
|
|
|
|
|
|
|
|
ac = autocomplete('8');
|
|
|
|
|
|
|
|
CHECK(!ac.entryMap.count("up"));
|
|
|
|
CHECK(!ac.entryMap.count("down"));
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("\"up\""));
|
|
|
|
CHECK(ac.entryMap.count("\"down\""));
|
|
|
|
}
|
|
|
|
|
2022-04-07 22:29:01 +01:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_string_singleton_equality")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
type tagged = {tag:"cat", fieldx:number} | {tag:"dog", fieldy:number}
|
|
|
|
local x: tagged = {tag="cat", fieldx=2}
|
|
|
|
if x.tag == "@1" or "@2" ~= x.tag then end
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("cat"));
|
|
|
|
CHECK(ac.entryMap.count("dog"));
|
|
|
|
|
|
|
|
ac = autocomplete('2');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("cat"));
|
|
|
|
CHECK(ac.entryMap.count("dog"));
|
|
|
|
|
|
|
|
// CLI-48823: assignment to x.tag should also autocomplete, but union l-values are not supported yet
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_boolean_singleton")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local function f(x: true) end
|
|
|
|
f(@1)
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
REQUIRE(ac.entryMap.count("true"));
|
|
|
|
CHECK(ac.entryMap["true"].typeCorrect == TypeCorrectKind::Correct);
|
|
|
|
REQUIRE(ac.entryMap.count("false"));
|
|
|
|
CHECK(ac.entryMap["false"].typeCorrect == TypeCorrectKind::None);
|
2022-08-10 21:04:08 +01:00
|
|
|
CHECK_EQ(ac.context, AutocompleteContext::Expression);
|
2022-04-07 22:29:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_string_singleton_escape")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
type tag = "strange\t\"cat\"" | 'nice\t"dog"'
|
|
|
|
local function f(x: tag) end
|
|
|
|
f(@1)
|
|
|
|
f("@2")
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("\"strange\\t\\\"cat\\\"\""));
|
|
|
|
CHECK(ac.entryMap.count("\"nice\\t\\\"dog\\\"\""));
|
|
|
|
|
|
|
|
ac = autocomplete('2');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("strange\\t\\\"cat\\\""));
|
|
|
|
CHECK(ac.entryMap.count("nice\\t\\\"dog\\\""));
|
|
|
|
}
|
|
|
|
|
2022-01-27 23:46:05 +00:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "function_in_assignment_has_parentheses_2")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local bar: ((number) -> number) & (number, number) -> number)
|
|
|
|
local abc = b@1
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("bar"));
|
|
|
|
CHECK(ac.entryMap["bar"].parens == ParenthesesRecommendation::CursorInside);
|
|
|
|
}
|
|
|
|
|
2022-03-18 00:46:04 +00:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "no_incompatible_self_calls_on_class")
|
|
|
|
{
|
|
|
|
loadDefinition(R"(
|
|
|
|
declare class Foo
|
|
|
|
function one(self): number
|
|
|
|
two: () -> number
|
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local t: Foo
|
|
|
|
t:@1
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
REQUIRE(ac.entryMap.count("one"));
|
|
|
|
REQUIRE(ac.entryMap.count("two"));
|
|
|
|
CHECK(!ac.entryMap["one"].wrongIndexType);
|
|
|
|
CHECK(ac.entryMap["two"].wrongIndexType);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local t: Foo
|
|
|
|
t.@1
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
REQUIRE(ac.entryMap.count("one"));
|
|
|
|
REQUIRE(ac.entryMap.count("two"));
|
|
|
|
CHECK(ac.entryMap["one"].wrongIndexType);
|
|
|
|
CHECK(!ac.entryMap["two"].wrongIndexType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-03 20:21:14 +00:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "simple")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local t = {}
|
|
|
|
function t:m() end
|
|
|
|
t:m()
|
|
|
|
)");
|
|
|
|
|
|
|
|
// auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
// REQUIRE(ac.entryMap.count("m"));
|
|
|
|
// CHECK(!ac.entryMap["m"].wrongIndexType);
|
|
|
|
}
|
|
|
|
|
2022-07-29 05:24:07 +01:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "do_compatible_self_calls")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local t = {}
|
|
|
|
function t:m() end
|
|
|
|
t:@1
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
REQUIRE(ac.entryMap.count("m"));
|
|
|
|
CHECK(!ac.entryMap["m"].wrongIndexType);
|
|
|
|
}
|
|
|
|
|
2022-03-18 00:46:04 +00:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "no_incompatible_self_calls")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local t = {}
|
|
|
|
function t.m() end
|
|
|
|
t:@1
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
REQUIRE(ac.entryMap.count("m"));
|
|
|
|
CHECK(ac.entryMap["m"].wrongIndexType);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "no_incompatible_self_calls_2")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local f: (() -> number) & ((number) -> number) = function(x: number?) return 2 end
|
|
|
|
local t = {}
|
|
|
|
t.f = f
|
|
|
|
t:@1
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
REQUIRE(ac.entryMap.count("f"));
|
|
|
|
CHECK(ac.entryMap["f"].wrongIndexType);
|
|
|
|
}
|
|
|
|
|
2022-07-29 05:24:07 +01:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "do_wrong_compatible_self_calls")
|
2022-03-18 00:46:04 +00:00
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local t = {}
|
|
|
|
function t.m(x: typeof(t)) end
|
|
|
|
t:@1
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
REQUIRE(ac.entryMap.count("m"));
|
|
|
|
// We can make changes to mark this as a wrong way to call even though it's compatible
|
|
|
|
CHECK(!ac.entryMap["m"].wrongIndexType);
|
|
|
|
}
|
|
|
|
|
2022-07-29 05:24:07 +01:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "no_wrong_compatible_self_calls_with_generics")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local t = {}
|
|
|
|
function t.m<T>(a: T) end
|
|
|
|
t:@1
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
REQUIRE(ac.entryMap.count("m"));
|
|
|
|
// While this call is compatible with the type, this requires instantiation of a generic type which we don't perform
|
|
|
|
CHECK(ac.entryMap["m"].wrongIndexType);
|
|
|
|
}
|
|
|
|
|
2022-03-18 00:46:04 +00:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "string_prim_self_calls_are_fine")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local s = "hello"
|
|
|
|
s:@1
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
REQUIRE(ac.entryMap.count("byte"));
|
|
|
|
CHECK(ac.entryMap["byte"].wrongIndexType == false);
|
|
|
|
REQUIRE(ac.entryMap.count("char"));
|
|
|
|
CHECK(ac.entryMap["char"].wrongIndexType == true);
|
|
|
|
REQUIRE(ac.entryMap.count("sub"));
|
|
|
|
CHECK(ac.entryMap["sub"].wrongIndexType == false);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ACFixture, "string_prim_non_self_calls_are_avoided")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local s = "hello"
|
|
|
|
s.@1
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
REQUIRE(ac.entryMap.count("char"));
|
|
|
|
CHECK(ac.entryMap["char"].wrongIndexType == false);
|
|
|
|
REQUIRE(ac.entryMap.count("sub"));
|
|
|
|
CHECK(ac.entryMap["sub"].wrongIndexType == true);
|
|
|
|
}
|
|
|
|
|
2022-06-10 17:58:21 +01:00
|
|
|
TEST_CASE_FIXTURE(ACBuiltinsFixture, "library_non_self_calls_are_fine")
|
2022-03-18 00:46:04 +00:00
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
string.@1
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
REQUIRE(ac.entryMap.count("byte"));
|
|
|
|
CHECK(ac.entryMap["byte"].wrongIndexType == false);
|
|
|
|
REQUIRE(ac.entryMap.count("char"));
|
|
|
|
CHECK(ac.entryMap["char"].wrongIndexType == false);
|
|
|
|
REQUIRE(ac.entryMap.count("sub"));
|
|
|
|
CHECK(ac.entryMap["sub"].wrongIndexType == false);
|
2022-06-10 17:58:21 +01:00
|
|
|
|
|
|
|
check(R"(
|
|
|
|
table.@1
|
|
|
|
)");
|
|
|
|
|
|
|
|
ac = autocomplete('1');
|
|
|
|
|
|
|
|
REQUIRE(ac.entryMap.count("remove"));
|
|
|
|
CHECK(ac.entryMap["remove"].wrongIndexType == false);
|
|
|
|
REQUIRE(ac.entryMap.count("getn"));
|
|
|
|
CHECK(ac.entryMap["getn"].wrongIndexType == false);
|
|
|
|
REQUIRE(ac.entryMap.count("insert"));
|
|
|
|
CHECK(ac.entryMap["insert"].wrongIndexType == false);
|
2022-03-18 00:46:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-10 17:58:21 +01:00
|
|
|
TEST_CASE_FIXTURE(ACBuiltinsFixture, "library_self_calls_are_invalid")
|
2022-03-18 00:46:04 +00:00
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
string:@1
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
REQUIRE(ac.entryMap.count("byte"));
|
|
|
|
CHECK(ac.entryMap["byte"].wrongIndexType == true);
|
|
|
|
REQUIRE(ac.entryMap.count("char"));
|
|
|
|
CHECK(ac.entryMap["char"].wrongIndexType == true);
|
2022-07-29 05:24:07 +01:00
|
|
|
|
|
|
|
// We want the next test to evaluate to 'true', but we have to allow function defined with 'self' to be callable with ':'
|
|
|
|
// We may change the definition of the string metatable to not use 'self' types in the future (like byte/char/pack/unpack)
|
2022-03-18 00:46:04 +00:00
|
|
|
REQUIRE(ac.entryMap.count("sub"));
|
2022-07-29 05:24:07 +01:00
|
|
|
CHECK(ac.entryMap["sub"].wrongIndexType == false);
|
2022-03-18 00:46:04 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 22:44:27 +01:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "source_module_preservation_and_invalidation")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local a = { x = 2, y = 4 }
|
|
|
|
a.@1
|
|
|
|
)");
|
|
|
|
|
|
|
|
frontend.clear();
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("x"));
|
|
|
|
CHECK(ac.entryMap.count("y"));
|
|
|
|
|
|
|
|
frontend.check("MainModule", {});
|
|
|
|
|
|
|
|
ac = autocomplete('1');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("x"));
|
|
|
|
CHECK(ac.entryMap.count("y"));
|
|
|
|
|
|
|
|
frontend.markDirty("MainModule", nullptr);
|
|
|
|
|
|
|
|
ac = autocomplete('1');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("x"));
|
|
|
|
CHECK(ac.entryMap.count("y"));
|
|
|
|
|
|
|
|
frontend.check("MainModule", {});
|
|
|
|
|
|
|
|
ac = autocomplete('1');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("x"));
|
|
|
|
CHECK(ac.entryMap.count("y"));
|
|
|
|
}
|
|
|
|
|
2022-08-18 22:32:08 +01:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "globals_are_order_independent")
|
|
|
|
{
|
|
|
|
check(R"(
|
|
|
|
local myLocal = 4
|
|
|
|
function abc0()
|
|
|
|
local myInnerLocal = 1
|
|
|
|
@1
|
|
|
|
end
|
|
|
|
|
|
|
|
function abc1()
|
|
|
|
local myInnerLocal = 1
|
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
CHECK(ac.entryMap.count("myLocal"));
|
|
|
|
CHECK(ac.entryMap.count("myInnerLocal"));
|
|
|
|
CHECK(ac.entryMap.count("abc0"));
|
|
|
|
CHECK(ac.entryMap.count("abc1"));
|
|
|
|
}
|
|
|
|
|
2023-01-06 21:14:35 +00:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "type_reduction_is_hooked_up_to_autocomplete")
|
|
|
|
{
|
Sync to upstream/release/562 (#828)
* Fixed rare use-after-free in analysis during table unification
A lot of work these past months went into two new Luau components:
* A near full rewrite of the typechecker using a new deferred constraint
resolution system
* Native code generation for AoT/JiT compilation of VM bytecode into x64
(avx)/arm64 instructions
Both of these components are far from finished and we don't provide
documentation on building and using them at this point.
However, curious community members expressed interest in learning about
changes that go into these components each week, so we are now listing
them here in the 'sync' pull request descriptions.
---
New typechecker can be enabled by setting
DebugLuauDeferredConstraintResolution flag to 'true'.
It is considered unstable right now, so try it at your own risk.
Even though it already provides better type inference than the current
one in some cases, our main goal right now is to reach feature parity
with current typechecker.
Features which improve over the capabilities of the current typechecker
are marked as '(NEW)'.
Changes to new typechecker:
* Regular for loop index and parameters are now typechecked
* Invalid type annotations on local variables are ignored to improve
autocomplete
* Fixed missing autocomplete type suggestions for function arguments
* Type reduction is now performed to produce simpler types to be
presented to the user (error messages, custom LSPs)
* Internally, complex types like '((number | string) & ~(false?)) |
string' can be produced, which is just 'string | number' when simplified
* Fixed spots where support for unknown and never types was missing
* (NEW) Length operator '#' is now valid to use on top table type, this
type comes up when doing typeof(x) == "table" guards and isn't available
in current typechecker
---
Changes to native code generation:
* Additional math library fast calls are now lowered to x64: math.ldexp,
math.round, math.frexp, math.modf, math.sign and math.clamp
2023-02-03 19:26:13 +00:00
|
|
|
ScopedFastFlag sff{"DebugLuauDeferredConstraintResolution", true};
|
|
|
|
|
2023-01-06 21:14:35 +00:00
|
|
|
check(R"(
|
|
|
|
type T = { x: (number & string)? }
|
|
|
|
|
|
|
|
function f(thingamabob: T)
|
|
|
|
thingamabob.@1
|
|
|
|
end
|
|
|
|
|
|
|
|
function g(thingamabob: T)
|
|
|
|
thingama@2
|
|
|
|
end
|
|
|
|
)");
|
|
|
|
|
|
|
|
ToStringOptions opts;
|
|
|
|
opts.exhaustive = true;
|
|
|
|
|
|
|
|
auto ac1 = autocomplete('1');
|
|
|
|
REQUIRE(ac1.entryMap.count("x"));
|
|
|
|
std::optional<TypeId> ty1 = ac1.entryMap.at("x").type;
|
|
|
|
REQUIRE(ty1);
|
Sync to upstream/release/562 (#828)
* Fixed rare use-after-free in analysis during table unification
A lot of work these past months went into two new Luau components:
* A near full rewrite of the typechecker using a new deferred constraint
resolution system
* Native code generation for AoT/JiT compilation of VM bytecode into x64
(avx)/arm64 instructions
Both of these components are far from finished and we don't provide
documentation on building and using them at this point.
However, curious community members expressed interest in learning about
changes that go into these components each week, so we are now listing
them here in the 'sync' pull request descriptions.
---
New typechecker can be enabled by setting
DebugLuauDeferredConstraintResolution flag to 'true'.
It is considered unstable right now, so try it at your own risk.
Even though it already provides better type inference than the current
one in some cases, our main goal right now is to reach feature parity
with current typechecker.
Features which improve over the capabilities of the current typechecker
are marked as '(NEW)'.
Changes to new typechecker:
* Regular for loop index and parameters are now typechecked
* Invalid type annotations on local variables are ignored to improve
autocomplete
* Fixed missing autocomplete type suggestions for function arguments
* Type reduction is now performed to produce simpler types to be
presented to the user (error messages, custom LSPs)
* Internally, complex types like '((number | string) & ~(false?)) |
string' can be produced, which is just 'string | number' when simplified
* Fixed spots where support for unknown and never types was missing
* (NEW) Length operator '#' is now valid to use on top table type, this
type comes up when doing typeof(x) == "table" guards and isn't available
in current typechecker
---
Changes to native code generation:
* Additional math library fast calls are now lowered to x64: math.ldexp,
math.round, math.frexp, math.modf, math.sign and math.clamp
2023-02-03 19:26:13 +00:00
|
|
|
CHECK("nil" == toString(*ty1, opts));
|
2023-01-06 21:14:35 +00:00
|
|
|
|
|
|
|
auto ac2 = autocomplete('2');
|
|
|
|
REQUIRE(ac2.entryMap.count("thingamabob"));
|
|
|
|
std::optional<TypeId> ty2 = ac2.entryMap.at("thingamabob").type;
|
|
|
|
REQUIRE(ty2);
|
Sync to upstream/release/562 (#828)
* Fixed rare use-after-free in analysis during table unification
A lot of work these past months went into two new Luau components:
* A near full rewrite of the typechecker using a new deferred constraint
resolution system
* Native code generation for AoT/JiT compilation of VM bytecode into x64
(avx)/arm64 instructions
Both of these components are far from finished and we don't provide
documentation on building and using them at this point.
However, curious community members expressed interest in learning about
changes that go into these components each week, so we are now listing
them here in the 'sync' pull request descriptions.
---
New typechecker can be enabled by setting
DebugLuauDeferredConstraintResolution flag to 'true'.
It is considered unstable right now, so try it at your own risk.
Even though it already provides better type inference than the current
one in some cases, our main goal right now is to reach feature parity
with current typechecker.
Features which improve over the capabilities of the current typechecker
are marked as '(NEW)'.
Changes to new typechecker:
* Regular for loop index and parameters are now typechecked
* Invalid type annotations on local variables are ignored to improve
autocomplete
* Fixed missing autocomplete type suggestions for function arguments
* Type reduction is now performed to produce simpler types to be
presented to the user (error messages, custom LSPs)
* Internally, complex types like '((number | string) & ~(false?)) |
string' can be produced, which is just 'string | number' when simplified
* Fixed spots where support for unknown and never types was missing
* (NEW) Length operator '#' is now valid to use on top table type, this
type comes up when doing typeof(x) == "table" guards and isn't available
in current typechecker
---
Changes to native code generation:
* Additional math library fast calls are now lowered to x64: math.ldexp,
math.round, math.frexp, math.modf, math.sign and math.clamp
2023-02-03 19:26:13 +00:00
|
|
|
CHECK("{| x: nil |}" == toString(*ty2, opts));
|
2023-01-06 21:14:35 +00:00
|
|
|
}
|
|
|
|
|
2023-01-11 16:28:11 +00:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "string_contents_is_available_to_callback")
|
|
|
|
{
|
|
|
|
loadDefinition(R"(
|
|
|
|
declare function require(path: string): any
|
|
|
|
)");
|
|
|
|
|
|
|
|
std::optional<Binding> require = frontend.typeCheckerForAutocomplete.globalScope->linearSearchForBinding("require");
|
|
|
|
REQUIRE(require);
|
|
|
|
Luau::unfreeze(frontend.typeCheckerForAutocomplete.globalTypes);
|
|
|
|
attachTag(require->typeId, "RequireCall");
|
|
|
|
Luau::freeze(frontend.typeCheckerForAutocomplete.globalTypes);
|
|
|
|
|
|
|
|
check(R"(
|
|
|
|
local x = require("testing/@1")
|
|
|
|
)");
|
|
|
|
|
|
|
|
bool isCorrect = false;
|
2023-01-20 20:27:03 +00:00
|
|
|
auto ac1 = autocomplete(
|
|
|
|
'1', [&isCorrect](std::string, std::optional<const ClassType*>, std::optional<std::string> contents) -> std::optional<AutocompleteEntryMap> {
|
|
|
|
isCorrect = contents && *contents == "testing/";
|
2023-01-11 16:28:11 +00:00
|
|
|
return std::nullopt;
|
|
|
|
});
|
|
|
|
|
|
|
|
CHECK(isCorrect);
|
|
|
|
}
|
|
|
|
|
2023-03-03 20:21:14 +00:00
|
|
|
TEST_CASE_FIXTURE(ACFixture, "autocomplete_response_perf1" * doctest::timeout(0.5))
|
|
|
|
{
|
|
|
|
ScopedFastFlag luauAutocompleteSkipNormalization{"LuauAutocompleteSkipNormalization", true};
|
|
|
|
|
|
|
|
// Build a function type with a large overload set
|
|
|
|
const int parts = 100;
|
|
|
|
std::string source;
|
|
|
|
|
|
|
|
for (int i = 0; i < parts; i++)
|
|
|
|
formatAppend(source, "type T%d = { f%d: number }\n", i, i);
|
|
|
|
|
|
|
|
source += "type Instance = { new: (('s0', extra: Instance?) -> T0)";
|
|
|
|
|
|
|
|
for (int i = 1; i < parts; i++)
|
|
|
|
formatAppend(source, " & (('s%d', extra: Instance?) -> T%d)", i, i);
|
|
|
|
|
|
|
|
source += " }\n";
|
|
|
|
|
|
|
|
source += "local Instance: Instance = {} :: any\n";
|
|
|
|
source += "local function c(): boolean return t@1 end\n";
|
|
|
|
|
|
|
|
check(source);
|
|
|
|
|
|
|
|
auto ac = autocomplete('1');
|
|
|
|
|
|
|
|
CHECK(ac.entryMap.count("true"));
|
|
|
|
CHECK(ac.entryMap.count("Instance"));
|
|
|
|
}
|
|
|
|
|
2021-10-29 21:25:12 +01:00
|
|
|
TEST_SUITE_END();
|