This repository has been archived by the owner on Jun 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
RequireResolver.h
42 lines (35 loc) · 1.73 KB
/
RequireResolver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once
#include <optional>
#include <string>
#include <functional>
#include <vector>
#include <memory>
#include <unordered_map>
#include <filesystem>
#include "Luau/FileResolver.h"
using SourceNodePtr = std::shared_ptr<struct SourceNode>;
struct SourceNode
{
std::string name;
std::optional<std::string> className; // TODO: make no longer optional when removing project file parsing
std::vector<std::filesystem::path> filePaths;
std::vector<SourceNodePtr> children;
};
struct ResolvedSourceMap
{
SourceNodePtr root; // The resolved root
std::unordered_map<std::string, std::string> realPathToVirtualMap; // Map between real (canonical) file paths and virtual Rojo paths
};
namespace RojoResolver
{
std::optional<ResolvedSourceMap> parseProjectFile(const std::filesystem::path& projectFilePath);
std::optional<ResolvedSourceMap> parseSourceMap(const std::filesystem::path& projectFilePath);
std::optional<SourceNodePtr> resolveRequireToSourceNode(const std::string& requirePath, const SourceNodePtr& root);
std::optional<std::filesystem::path> resolveRequireToRealPath(const std::string& requirePath, const SourceNodePtr& root);
std::optional<std::filesystem::path> getRelevantFilePath(const SourceNode& node);
std::optional<SourceNodePtr> findChildWithName(const SourceNode& node, const std::string_view& name);
Luau::SourceCode::Type sourceCodeTypeFromClassName(const std::string& className);
Luau::SourceCode::Type sourceCodeTypeFromPath(const std::filesystem::path& path);
std::optional<std::string> resolveRealPathToVirtual(const ResolvedSourceMap& sourceMap, const std::filesystem::path& filePath);
}; // namespace RojoResolver
void dumpSourceMap(const SourceNode& root, int level);