Skip to content
This repository has been archived by the owner on Jun 12, 2022. It is now read-only.

Commit

Permalink
Add --exclude-virtual-path option
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyMorganz committed Mar 31, 2022
1 parent ae05583 commit 811f684
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ cmake --build . --target luau-analyze-rojo --config Release
luau-analyze --project=default.project.json --defs=globalTypes.d.lua fileToAnalyse.luau
```

The tool supports all options available in the original `luau-analyze` tool, with these further additions:

- `--project=PATH`: path to the Rojo project file which will be used to resolve the source map
- `--defs=PATH`: path to a definition file containing all global types to load into the type checker.
- `--stdin-filepath=PATH`: the path representation of the code parsed in to stdin. Used to resolve requires

Further options:

- `--dump-source-map`: dumps a map of registered files that the tool has picked up. Useful for debugging
- `--exclude-virtual-path`: don't include the virtual path in the output. Useful when a machine needs to read the output

## Registering global types

Expand Down
16 changes: 14 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ static void displayHelp(const char* argv0)
printf(" --defs=PATH: path to definition file for global types\n");
printf(" --stdin-filepath=PATH: path to file being sent through stdin. Used for require resolution\n");
printf(" --dump-source-map: dump the currently resolved source map\n");
printf(" --exclude-virtual-path: don't include virtual path name in output\n");
}

static int assertionHandler(const char* expr, const char* file, int line, const char* function)
Expand All @@ -132,6 +133,7 @@ struct CliFileResolver : Luau::FileResolver
{
ResolvedSourceMap sourceMap;
std::optional<std::filesystem::path> stdinFilepath;
bool excludeVirtualPath = false;

std::optional<Luau::SourceCode> readSource(const Luau::ModuleName& name) override
{
Expand Down Expand Up @@ -258,9 +260,15 @@ struct CliFileResolver : Luau::FileResolver
{
std::optional<std::filesystem::path> realFilePath = RojoResolver::resolveRequireToRealPath(name, sourceMap.root);
if (realFilePath.has_value())
return realFilePath.value().relative_path().generic_string() + "[" + name + "]";
{
if (excludeVirtualPath)
{

return "<UNKNOWN>[" + name + "]";
return realFilePath.value().relative_path().generic_string();
}
return realFilePath.value().relative_path().generic_string() + "[" + name + "]";
}
return name;
}
else
{
Expand Down Expand Up @@ -368,6 +376,7 @@ int main(int argc, char** argv)
ReportFormat format = ReportFormat::Default;
bool annotate = false;
bool dumpMap = false;
bool excludeVirtualPath = false;
std::optional<std::filesystem::path> projectPath = std::nullopt;
std::optional<std::filesystem::path> globalDefsPath = std::nullopt;
std::optional<std::filesystem::path> stdinFilepath = std::nullopt;
Expand All @@ -387,6 +396,8 @@ int main(int argc, char** argv)
FFlag::DebugLuauTimeTracing.value = true;
else if (strcmp(argv[i], "--dump-source-map") == 0)
dumpMap = true;
else if (strcmp(argv[i], "--exclude-virtual-path") == 0)
excludeVirtualPath = true;
else if (strncmp(argv[i], "--project=", 10) == 0)
projectPath = std::string(argv[i] + 10);
else if (strncmp(argv[i], "--defs=", 7) == 0)
Expand All @@ -407,6 +418,7 @@ int main(int argc, char** argv)
frontendOptions.retainFullTypeGraphs = annotate;

CliFileResolver fileResolver;
fileResolver.excludeVirtualPath = excludeVirtualPath;
fileResolver.stdinFilepath = stdinFilepath;
if (projectPath)
{
Expand Down

0 comments on commit 811f684

Please sign in to comment.