2024-09-27 19:58:21 +01:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Luau/Ast.h"
|
2024-10-18 18:27:15 +01:00
|
|
|
#include "Luau/Parser.h"
|
2024-11-08 21:41:45 +00:00
|
|
|
#include "Luau/AutocompleteTypes.h"
|
2024-10-18 18:27:15 +01:00
|
|
|
#include "Luau/DenseHash.h"
|
|
|
|
#include "Luau/Module.h"
|
2024-11-08 21:41:45 +00:00
|
|
|
#include "Luau/Frontend.h"
|
2024-09-27 19:58:21 +01:00
|
|
|
|
2024-10-18 18:27:15 +01:00
|
|
|
#include <memory>
|
2024-09-27 19:58:21 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Luau
|
|
|
|
{
|
2024-10-25 21:15:01 +01:00
|
|
|
struct FrontendOptions;
|
2024-09-27 19:58:21 +01:00
|
|
|
|
|
|
|
struct FragmentAutocompleteAncestryResult
|
|
|
|
{
|
|
|
|
DenseHashMap<AstName, AstLocal*> localMap{AstName()};
|
|
|
|
std::vector<AstLocal*> localStack;
|
|
|
|
std::vector<AstNode*> ancestry;
|
2024-10-18 18:27:15 +01:00
|
|
|
AstStat* nearestStatement = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FragmentParseResult
|
|
|
|
{
|
|
|
|
std::string fragmentToParse;
|
|
|
|
AstStatBlock* root = nullptr;
|
|
|
|
std::vector<AstNode*> ancestry;
|
2024-11-08 21:41:45 +00:00
|
|
|
AstStat* nearestStatement = nullptr;
|
2024-10-18 18:27:15 +01:00
|
|
|
std::unique_ptr<Allocator> alloc = std::make_unique<Allocator>();
|
2024-09-27 19:58:21 +01:00
|
|
|
};
|
|
|
|
|
2024-10-25 21:15:01 +01:00
|
|
|
struct FragmentTypeCheckResult
|
|
|
|
{
|
|
|
|
ModulePtr incrementalModule = nullptr;
|
2024-11-08 21:41:45 +00:00
|
|
|
ScopePtr freshScope;
|
|
|
|
std::vector<AstNode*> ancestry;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FragmentAutocompleteResult
|
|
|
|
{
|
|
|
|
ModulePtr incrementalModule;
|
|
|
|
Scope* freshScope;
|
|
|
|
TypeArena arenaForAutocomplete;
|
|
|
|
AutocompleteResult acResults;
|
2024-10-25 21:15:01 +01:00
|
|
|
};
|
|
|
|
|
2024-09-27 19:58:21 +01:00
|
|
|
FragmentAutocompleteAncestryResult findAncestryForFragmentParse(AstStatBlock* root, const Position& cursorPos);
|
|
|
|
|
2024-11-15 22:29:30 +00:00
|
|
|
FragmentParseResult parseFragment(
|
|
|
|
const SourceModule& srcModule,
|
|
|
|
std::string_view src,
|
|
|
|
const Position& cursorPos,
|
|
|
|
std::optional<Position> fragmentEndPosition
|
|
|
|
);
|
2024-10-18 18:27:15 +01:00
|
|
|
|
2024-10-25 21:15:01 +01:00
|
|
|
FragmentTypeCheckResult typecheckFragment(
|
|
|
|
Frontend& frontend,
|
|
|
|
const ModuleName& moduleName,
|
|
|
|
const Position& cursorPos,
|
|
|
|
std::optional<FrontendOptions> opts,
|
2024-11-15 22:29:30 +00:00
|
|
|
std::string_view src,
|
|
|
|
std::optional<Position> fragmentEndPosition
|
2024-10-25 21:15:01 +01:00
|
|
|
);
|
|
|
|
|
2024-11-08 21:41:45 +00:00
|
|
|
FragmentAutocompleteResult fragmentAutocomplete(
|
2024-10-18 18:27:15 +01:00
|
|
|
Frontend& frontend,
|
|
|
|
std::string_view src,
|
|
|
|
const ModuleName& moduleName,
|
2024-11-08 21:41:45 +00:00
|
|
|
Position cursorPosition,
|
2024-10-25 21:15:01 +01:00
|
|
|
std::optional<FrontendOptions> opts,
|
2024-11-15 22:29:30 +00:00
|
|
|
StringCompletionCallback callback,
|
|
|
|
std::optional<Position> fragmentEndPosition = std::nullopt
|
2024-10-18 18:27:15 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
2024-09-27 19:58:21 +01:00
|
|
|
} // namespace Luau
|