44#include " Luau/Error.h"
55#include " Luau/Transpiler.h"
66#include " Luau/TypeAttach.h"
7+ #include " Luau/Require.h"
78
8- static const std::string kLuteDefinitions = R"LUTE_TYPES(
9- -- Net api
10- declare net: {
11- get: (string) -> string,
12- getAsync: (string) -> string,
13- }
14- -- fs api
15- declare class file end
16- declare fs: {
17- -- probably not the correct sig
18- open: (string, "r" | "w" | "a" | "r+" | "w+") -> file,
19- close: (file) -> (),
20- read: (file) -> string,
21- write: (file, string) -> (),
22- readfiletostring : (string) -> string,
23- writestringtofile : (string, string) -> (),
24- -- is this right? I feel like we want a promise type here
25- readasync : (string) -> string,
26- }
27-
28- -- globals
29- declare function spawn(path: string): any
30-
31- )LUTE_TYPES" ;
9+ LUAU_FASTFLAG (LuauSolverV2)
3210
3311struct LuteFileResolver : Luau::FileResolver
3412{
@@ -57,7 +35,21 @@ struct LuteFileResolver : Luau::FileResolver
5735
5836 std::optional<Luau::ModuleInfo> resolveModule (const Luau::ModuleInfo* context, Luau::AstExpr* node) override
5937 {
60- // TODO: Need to handle requires
38+ if (Luau::AstExprConstantString* expr = node->as <Luau::AstExprConstantString>())
39+ {
40+ std::string path{expr->value .data , expr->value .size };
41+
42+ AnalysisRequireContext requireContext{context->name };
43+ AnalysisCacheManager cacheManager;
44+ AnalysisErrorHandler errorHandler;
45+
46+ RequireResolver resolver (path, requireContext, cacheManager, errorHandler);
47+ RequireResolver::ResolvedRequire resolvedRequire = resolver.resolveRequire ();
48+
49+ if (resolvedRequire.status == RequireResolver::ModuleStatus::FileRead)
50+ return {{resolvedRequire.identifier }};
51+ }
52+
6153 return std::nullopt ;
6254 }
6355
@@ -69,7 +61,46 @@ struct LuteFileResolver : Luau::FileResolver
6961 }
7062
7163private:
72- // TODO: add require resolver;
64+ struct AnalysisRequireContext : RequireResolver::RequireContext
65+ {
66+ explicit AnalysisRequireContext (std::string path)
67+ : path(std::move(path))
68+ {
69+ }
70+
71+ std::string getPath () override
72+ {
73+ return path;
74+ }
75+
76+ bool isRequireAllowed () override
77+ {
78+ return true ;
79+ }
80+
81+ bool isStdin () override
82+ {
83+ return path == " -" ;
84+ }
85+
86+ std::string createNewIdentifer (const std::string& path) override
87+ {
88+ return path;
89+ }
90+
91+ private:
92+ std::string path;
93+ };
94+
95+ struct AnalysisCacheManager : public RequireResolver ::CacheManager
96+ {
97+ AnalysisCacheManager () = default ;
98+ };
99+
100+ struct AnalysisErrorHandler : RequireResolver::ErrorHandler
101+ {
102+ AnalysisErrorHandler () = default ;
103+ };
73104};
74105
75106struct LuteConfigResolver : Luau::ConfigResolver
@@ -182,6 +213,9 @@ static bool reportModuleResult(Luau::Frontend& frontend, const Luau::ModuleName&
182213
183214int typecheck (const std::vector<std::string> sourceFiles)
184215{
216+ // Lute only supports the new type solver
217+ FFlag::LuauSolverV2.value = true ;
218+
185219 Luau::Mode mode = Luau::Mode::Strict;
186220 bool annotate = true ;
187221 std::string basePath = " " ;
@@ -195,9 +229,6 @@ int typecheck(const std::vector<std::string> sourceFiles)
195229 Luau::Frontend frontend (&fileResolver, &configResolver, frontendOptions);
196230
197231 Luau::registerBuiltinGlobals (frontend, frontend.globals );
198- Luau::LoadDefinitionFileResult loadResult =
199- frontend.loadDefinitionFile (frontend.globals , frontend.globals .globalScope , kLuteDefinitions , " @luau" , false , false );
200- LUAU_ASSERT (loadResult.success );
201232 Luau::freeze (frontend.globals .globalTypes );
202233
203234 for (const std::string& path : sourceFiles)
0 commit comments