Skip to content

Commit

Permalink
Sync to Luau master, enable Luau fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
checkraisefold committed Nov 6, 2024
1 parent 5f3aa97 commit 8cdf34a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 66 deletions.
2 changes: 1 addition & 1 deletion luau
Submodule luau updated from db8093 to 47543e
11 changes: 11 additions & 0 deletions src/Flags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

#include <iostream>

LUAU_FASTFLAG(LuauSolverV2)
LUAU_FASTFLAG(LuauNewSolverPopulateTableLocations)
LUAU_FASTFLAG(LuauNewSolverPrePopulateClasses)

void registerFastFlags(std::unordered_map<std::string, std::string>& fastFlags, ErrorCallback onError, ErrorCallback onWarning)
{
for (Luau::FValue<bool>* flag = Luau::FValue<bool>::list; flag; flag = flag->next)
Expand Down Expand Up @@ -50,6 +54,13 @@ void registerFastFlags(std::unordered_map<std::string, std::string>& fastFlags,
{
onWarning(std::string("Unknown FFlag: ") + key);
}

// These are required flags for internal functionality.
if (FFlag::LuauSolverV2)
{
FFlag::LuauNewSolverPopulateTableLocations.value = true;
FFlag::LuauNewSolverPrePopulateClasses.value = true;
}
}

void registerFastFlagsCLI(std::unordered_map<std::string, std::string>& fastFlags)
Expand Down
33 changes: 0 additions & 33 deletions src/LuauExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,39 +429,6 @@ lsp::Diagnostic createParseErrorDiagnostic(const Luau::ParseError& error, const
return diagnostic;
}

// TODO: Dirty hack for invalid definitionModuleName on type aliases for solver v2!
// Remove after https://github.com/luau-lang/luau/issues/1441 is closed!
std::optional<Luau::ModuleName> lookupTypeDefinitionModule(Luau::TypeId type)
{
if (!FFlag::LuauSolverV2)
{
return Luau::getDefinitionModuleName(type);
}

type = Luau::follow(type);
if (auto ttv = Luau::get<Luau::TableType>(type); ttv && ttv->definitionModuleName.empty())
{
if (type->owningArena && type->owningArena->owningModule)
return type->owningArena->owningModule->name;
}

return Luau::getDefinitionModuleName(type);
}

std::optional<Luau::Location> lookupTypeDefinitionModuleLocation(Luau::TypeId type, Luau::ModulePtr module)
{
type = Luau::follow(type);
auto types = module->astResolvedTypes;
for (auto it = types.begin(); it != types.end(); ++it)
{
if (it->second == type)
{
return it->first->location;
}
}
return std::nullopt;
}

// Based on upstream, except we use containsClosed
struct FindExprOrLocalClosed : public Luau::AstVisitor
{
Expand Down
3 changes: 0 additions & 3 deletions src/include/LSP/LuauExt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ bool isRequire(const Luau::AstExpr* expr);
bool isMethod(const Luau::FunctionType* ftv);
bool isOverloadedMethod(Luau::TypeId ty);

std::optional<Luau::ModuleName> lookupTypeDefinitionModule(Luau::TypeId type);
std::optional<Luau::Location> lookupTypeDefinitionModuleLocation(Luau::TypeId type, Luau::ModulePtr module);

struct FindImportsVisitor : public Luau::AstVisitor
{
private:
Expand Down
4 changes: 2 additions & 2 deletions src/operations/Completion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ std::optional<std::string> WorkspaceFolder::getDocumentationForAutocompleteEntry
// parentTy might be an intersected type, find the actual base ttv
auto followedTy = Luau::follow(*parentTy);
if (auto propInformation = lookupProp(followedTy, name))
definitionModuleName = lookupTypeDefinitionModule(propInformation->first);
definitionModuleName = Luau::getDefinitionModuleName(propInformation->first);
else
definitionModuleName = lookupTypeDefinitionModule(followedTy);
definitionModuleName = Luau::getDefinitionModuleName(followedTy);
}
}
}
Expand Down
30 changes: 3 additions & 27 deletions src/operations/Hover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,6 @@ std::optional<lsp::Hover> WorkspaceFolder::hover(const lsp::HoverParams& params)
if (!typeFun)
return std::nullopt;

// TODO: Dirty hack for invalid definitionModuleName on type aliases for solver v2!
// Remove after https://github.com/luau-lang/luau/issues/1441 is closed!
if (FFlag::LuauSolverV2 && typeFun->type)
{
auto followedType = Luau::follow(typeFun->type);
auto name = lookupTypeDefinitionModule(followedType);
auto location = lookupTypeDefinitionModuleLocation(followedType, module);
if (name && location)
documentationLocation = {name.value(), location.value()};
}

typeAliasInformation = std::make_pair(typeName, *typeFun);
type = typeFun->type;
}
Expand All @@ -189,7 +178,7 @@ std::optional<lsp::Hover> WorkspaceFolder::hover(const lsp::HoverParams& params)
if (prop.location.containsClosed(position))
{
auto parentType = Luau::follow(*tableTy);
if (auto definitionModuleName = lookupTypeDefinitionModule(parentType))
if (auto definitionModuleName = Luau::getDefinitionModuleName(parentType))
documentationLocation = {definitionModuleName.value(), prop.location};
auto resolvedProperty = lookupProp(parentType, prop.name.value);
if (resolvedProperty)
Expand All @@ -209,20 +198,7 @@ std::optional<lsp::Hover> WorkspaceFolder::hover(const lsp::HoverParams& params)
else if (auto local = exprOrLocal.getLocal()) // TODO: can we just use node here instead of also calling exprOrLocal?
{
type = scope->lookup(local);
// TODO: Dirty hack for invalid definitionModuleName on type aliases for solver v2!
// Remove after https://github.com/luau-lang/luau/issues/1441 is closed!
if (FFlag::LuauSolverV2 && type)
{
auto followedType = Luau::follow(*type);
auto name = lookupTypeDefinitionModule(followedType);
auto location = lookupTypeDefinitionModuleLocation(followedType, module);
if (name && location)
documentationLocation = {name.value(), location.value()};
else
documentationLocation = {moduleName, local->location};
}
else
documentationLocation = {moduleName, local->location};
documentationLocation = {moduleName, local->location};
}
else if (auto expr = exprOrLocal.getExpr())
{
Expand Down Expand Up @@ -258,7 +234,7 @@ std::optional<lsp::Hover> WorkspaceFolder::hover(const lsp::HoverParams& params)
{
auto [baseTy, prop] = propInformation.value();
type = prop.type();
if (auto definitionModuleName = lookupTypeDefinitionModule(baseTy))
if (auto definitionModuleName = Luau::getDefinitionModuleName(baseTy))
{
if (prop.location)
documentationLocation = {definitionModuleName.value(), prop.location.value()};
Expand Down

0 comments on commit 8cdf34a

Please sign in to comment.