mirror of
https://github.com/luau-lang/luau.git
synced 2025-01-05 19:09:11 +00:00
Include module name for definitions files (#861)
Closes #818
We set the `moduleName` of the source module to the provided
`packageName`.
This then populates the relevant `definitionModuleName`'s on
CTV/FTV/TTVs, so it allows us to lookup where they originated from.
The one place I can see this having an impact inside of Luau code is the
following:
1fa8311a18/Analysis/src/Error.cpp (L70-L90)
Which will potentially change they way error messages are formatted.
Should there be a way to exclude definition files when calling
`getDefinitionModuleName`, so we can preserve this behaviour?
This commit is contained in:
parent
74c532053f
commit
ae53051814
2 changed files with 29 additions and 0 deletions
|
@ -38,6 +38,7 @@ LUAU_FASTFLAGVARIABLE(DebugLuauLogSolverToJson, false)
|
||||||
LUAU_FASTFLAGVARIABLE(DebugLuauReadWriteProperties, false)
|
LUAU_FASTFLAGVARIABLE(DebugLuauReadWriteProperties, false)
|
||||||
LUAU_FASTFLAGVARIABLE(LuauTypecheckLimitControls, false)
|
LUAU_FASTFLAGVARIABLE(LuauTypecheckLimitControls, false)
|
||||||
LUAU_FASTFLAGVARIABLE(CorrectEarlyReturnInMarkDirty, false)
|
LUAU_FASTFLAGVARIABLE(CorrectEarlyReturnInMarkDirty, false)
|
||||||
|
LUAU_FASTFLAGVARIABLE(LuauDefinitionFileSetModuleName, false)
|
||||||
|
|
||||||
namespace Luau
|
namespace Luau
|
||||||
{
|
{
|
||||||
|
@ -165,6 +166,11 @@ LoadDefinitionFileResult Frontend::loadDefinitionFile(GlobalTypes& globals, Scop
|
||||||
LUAU_TIMETRACE_SCOPE("loadDefinitionFile", "Frontend");
|
LUAU_TIMETRACE_SCOPE("loadDefinitionFile", "Frontend");
|
||||||
|
|
||||||
Luau::SourceModule sourceModule;
|
Luau::SourceModule sourceModule;
|
||||||
|
if (FFlag::LuauDefinitionFileSetModuleName)
|
||||||
|
{
|
||||||
|
sourceModule.name = packageName;
|
||||||
|
sourceModule.humanReadableName = packageName;
|
||||||
|
}
|
||||||
Luau::ParseResult parseResult = parseSourceForModule(source, sourceModule, captureComments);
|
Luau::ParseResult parseResult = parseSourceForModule(source, sourceModule, captureComments);
|
||||||
if (parseResult.errors.size() > 0)
|
if (parseResult.errors.size() > 0)
|
||||||
return LoadDefinitionFileResult{false, parseResult, sourceModule, nullptr};
|
return LoadDefinitionFileResult{false, parseResult, sourceModule, nullptr};
|
||||||
|
|
|
@ -441,4 +441,27 @@ TEST_CASE_FIXTURE(Fixture, "class_definitions_reference_other_classes")
|
||||||
REQUIRE(result.success);
|
REQUIRE(result.success);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE_FIXTURE(Fixture, "definition_file_has_source_module_name_set")
|
||||||
|
{
|
||||||
|
ScopedFastFlag sff{"LuauDefinitionFileSetModuleName", true};
|
||||||
|
|
||||||
|
LoadDefinitionFileResult result = loadDefinition(R"(
|
||||||
|
declare class Foo
|
||||||
|
end
|
||||||
|
)");
|
||||||
|
|
||||||
|
REQUIRE(result.success);
|
||||||
|
|
||||||
|
CHECK_EQ(result.sourceModule.name, "@test");
|
||||||
|
CHECK_EQ(result.sourceModule.humanReadableName, "@test");
|
||||||
|
|
||||||
|
std::optional<TypeFun> fooTy = frontend.globals.globalScope->lookupType("Foo");
|
||||||
|
REQUIRE(fooTy);
|
||||||
|
|
||||||
|
const ClassType* ctv = get<ClassType>(fooTy->type);
|
||||||
|
|
||||||
|
REQUIRE(ctv);
|
||||||
|
CHECK_EQ(ctv->definitionModuleName, "@test");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_SUITE_END();
|
TEST_SUITE_END();
|
||||||
|
|
Loading…
Reference in a new issue