mirror of
https://github.com/luau-lang/luau.git
synced 2024-12-13 05:20:38 +00:00
Merge remote-tracking branch 'upstream/master' into merge
This commit is contained in:
commit
dbedb3c859
3 changed files with 102 additions and 27 deletions
2
.github/workflows/benchmark.yml
vendored
2
.github/workflows/benchmark.yml
vendored
|
@ -73,9 +73,11 @@ jobs:
|
|||
valgrind --tool=callgrind ./luau --compile=null -O0 bench/other/LuauPolyfillMap.lua 2>&1 | filter map-O0 | tee -a compile-output.txt
|
||||
valgrind --tool=callgrind ./luau --compile=null -O1 bench/other/LuauPolyfillMap.lua 2>&1 | filter map-O1 | tee -a compile-output.txt
|
||||
valgrind --tool=callgrind ./luau --compile=null -O2 bench/other/LuauPolyfillMap.lua 2>&1 | filter map-O2 | tee -a compile-output.txt
|
||||
valgrind --tool=callgrind ./luau --compile=codegennull -O2 bench/other/LuauPolyfillMap.lua 2>&1 | filter map-O2-codegen | tee -a compile-output.txt
|
||||
valgrind --tool=callgrind ./luau --compile=null -O0 bench/other/regex.lua 2>&1 | filter regex-O0 | tee -a compile-output.txt
|
||||
valgrind --tool=callgrind ./luau --compile=null -O1 bench/other/regex.lua 2>&1 | filter regex-O1 | tee -a compile-output.txt
|
||||
valgrind --tool=callgrind ./luau --compile=null -O2 bench/other/regex.lua 2>&1 | filter regex-O2 | tee -a compile-output.txt
|
||||
valgrind --tool=callgrind ./luau --compile=codegennull -O2 bench/other/regex.lua 2>&1 | filter regex-O2-codegen | tee -a compile-output.txt
|
||||
|
||||
- name: Checkout benchmark results
|
||||
uses: actions/checkout@v3
|
||||
|
|
|
@ -427,19 +427,14 @@ ExprOrLocal findExprOrLocalAtPosition(const SourceModule& source, Position pos)
|
|||
return findVisitor.result;
|
||||
}
|
||||
|
||||
std::optional<DocumentationSymbol> getDocumentationSymbolAtPosition(const SourceModule& source, const Module& module, Position position)
|
||||
static std::optional<DocumentationSymbol> checkOverloadedDocumentationSymbol(
|
||||
const Module& module, const TypeId ty, const AstExpr* parentExpr, const std::optional<DocumentationSymbol> documentationSymbol)
|
||||
{
|
||||
std::vector<AstNode*> ancestry = findAstAncestryOfPosition(source, position);
|
||||
if (!documentationSymbol)
|
||||
return std::nullopt;
|
||||
|
||||
AstExpr* targetExpr = ancestry.size() >= 1 ? ancestry[ancestry.size() - 1]->asExpr() : nullptr;
|
||||
AstExpr* parentExpr = ancestry.size() >= 2 ? ancestry[ancestry.size() - 2]->asExpr() : nullptr;
|
||||
|
||||
if (std::optional<Binding> binding = findBindingAtPosition(module, source, position))
|
||||
{
|
||||
if (binding->documentationSymbol)
|
||||
{
|
||||
// This might be an overloaded function binding.
|
||||
if (get<IntersectionTypeVar>(follow(binding->typeId)))
|
||||
// This might be an overloaded function.
|
||||
if (get<IntersectionTypeVar>(follow(ty)))
|
||||
{
|
||||
TypeId matchingOverload = nullptr;
|
||||
if (parentExpr && parentExpr->is<AstExprCall>())
|
||||
|
@ -452,15 +447,26 @@ std::optional<DocumentationSymbol> getDocumentationSymbolAtPosition(const Source
|
|||
|
||||
if (matchingOverload)
|
||||
{
|
||||
std::string overloadSymbol = *binding->documentationSymbol + "/overload/";
|
||||
std::string overloadSymbol = *documentationSymbol + "/overload/";
|
||||
// Default toString options are fine for this purpose.
|
||||
overloadSymbol += toString(matchingOverload);
|
||||
return overloadSymbol;
|
||||
}
|
||||
}
|
||||
|
||||
return documentationSymbol;
|
||||
}
|
||||
|
||||
return binding->documentationSymbol;
|
||||
std::optional<DocumentationSymbol> getDocumentationSymbolAtPosition(const SourceModule& source, const Module& module, Position position)
|
||||
{
|
||||
std::vector<AstNode*> ancestry = findAstAncestryOfPosition(source, position);
|
||||
|
||||
AstExpr* targetExpr = ancestry.size() >= 1 ? ancestry[ancestry.size() - 1]->asExpr() : nullptr;
|
||||
AstExpr* parentExpr = ancestry.size() >= 2 ? ancestry[ancestry.size() - 2]->asExpr() : nullptr;
|
||||
|
||||
if (std::optional<Binding> binding = findBindingAtPosition(module, source, position))
|
||||
{
|
||||
return checkOverloadedDocumentationSymbol(module, binding->typeId, parentExpr, binding->documentationSymbol);
|
||||
}
|
||||
|
||||
if (targetExpr)
|
||||
|
@ -474,14 +480,14 @@ std::optional<DocumentationSymbol> getDocumentationSymbolAtPosition(const Source
|
|||
{
|
||||
if (auto propIt = ttv->props.find(indexName->index.value); propIt != ttv->props.end())
|
||||
{
|
||||
return propIt->second.documentationSymbol;
|
||||
return checkOverloadedDocumentationSymbol(module, propIt->second.type, parentExpr, propIt->second.documentationSymbol);
|
||||
}
|
||||
}
|
||||
else if (const ClassTypeVar* ctv = get<ClassTypeVar>(parentTy))
|
||||
{
|
||||
if (auto propIt = ctv->props.find(indexName->index.value); propIt != ctv->props.end())
|
||||
{
|
||||
return propIt->second.documentationSymbol;
|
||||
return checkOverloadedDocumentationSymbol(module, propIt->second.type, parentExpr, propIt->second.documentationSymbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,6 +72,73 @@ TEST_CASE_FIXTURE(DocumentationSymbolFixture, "overloaded_fn")
|
|||
CHECK_EQ(symbol, "@test/global/foo/overload/(string) -> number");
|
||||
}
|
||||
|
||||
TEST_CASE_FIXTURE(DocumentationSymbolFixture, "class_method")
|
||||
{
|
||||
loadDefinition(R"(
|
||||
declare class Foo
|
||||
function bar(self, x: string): number
|
||||
end
|
||||
)");
|
||||
|
||||
std::optional<DocumentationSymbol> symbol = getDocSymbol(R"(
|
||||
local x: Foo
|
||||
x:bar("asdf")
|
||||
)",
|
||||
Position(2, 11));
|
||||
|
||||
CHECK_EQ(symbol, "@test/globaltype/Foo.bar");
|
||||
}
|
||||
|
||||
TEST_CASE_FIXTURE(DocumentationSymbolFixture, "overloaded_class_method")
|
||||
{
|
||||
loadDefinition(R"(
|
||||
declare class Foo
|
||||
function bar(self, x: string): number
|
||||
function bar(self, x: number): string
|
||||
end
|
||||
)");
|
||||
|
||||
std::optional<DocumentationSymbol> symbol = getDocSymbol(R"(
|
||||
local x: Foo
|
||||
x:bar("asdf")
|
||||
)",
|
||||
Position(2, 11));
|
||||
|
||||
CHECK_EQ(symbol, "@test/globaltype/Foo.bar/overload/(Foo, string) -> number");
|
||||
}
|
||||
|
||||
TEST_CASE_FIXTURE(DocumentationSymbolFixture, "table_function_prop")
|
||||
{
|
||||
loadDefinition(R"(
|
||||
declare Foo: {
|
||||
new: (number) -> string
|
||||
}
|
||||
)");
|
||||
|
||||
std::optional<DocumentationSymbol> symbol = getDocSymbol(R"(
|
||||
Foo.new("asdf")
|
||||
)",
|
||||
Position(1, 13));
|
||||
|
||||
CHECK_EQ(symbol, "@test/global/Foo.new");
|
||||
}
|
||||
|
||||
TEST_CASE_FIXTURE(DocumentationSymbolFixture, "table_overloaded_function_prop")
|
||||
{
|
||||
loadDefinition(R"(
|
||||
declare Foo: {
|
||||
new: ((number) -> string) & ((string) -> number)
|
||||
}
|
||||
)");
|
||||
|
||||
std::optional<DocumentationSymbol> symbol = getDocSymbol(R"(
|
||||
Foo.new("asdf")
|
||||
)",
|
||||
Position(1, 13));
|
||||
|
||||
CHECK_EQ(symbol, "@test/global/Foo.new/overload/(string) -> number");
|
||||
}
|
||||
|
||||
TEST_SUITE_END();
|
||||
|
||||
TEST_SUITE_BEGIN("AstQuery");
|
||||
|
|
Loading…
Reference in a new issue