mirror of
https://github.com/luau-lang/luau.git
synced 2024-12-13 05:20:38 +00:00
2f989fc049
- Improve refinement support for unions, in particular it's now possible to implement tagged unions as a union of tables where individual branches use a string literal type for one of the fields. - Fix `string.split` type information - Optimize `select(_, ...)` to run in constant time (~2.7x faster on VariadicSelect benchmark) - Improve debug line information for multi-line assignments - Improve compilation of table literals when table keys are constant expressions/variables - Use forward GC barrier for `setmetatable` which slightly accelerates GC progress
78 lines
2.1 KiB
C++
78 lines
2.1 KiB
C++
// 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"
|
|
#include "Luau/Documentation.h"
|
|
|
|
#include <memory>
|
|
|
|
namespace Luau
|
|
{
|
|
|
|
struct Binding;
|
|
struct SourceModule;
|
|
struct Module;
|
|
|
|
struct TypeVar;
|
|
using TypeId = const TypeVar*;
|
|
|
|
using ScopePtr = std::shared_ptr<struct Scope>;
|
|
|
|
struct ExprOrLocal
|
|
{
|
|
AstExpr* getExpr()
|
|
{
|
|
return expr;
|
|
}
|
|
AstLocal* getLocal()
|
|
{
|
|
return local;
|
|
}
|
|
void setExpr(AstExpr* newExpr)
|
|
{
|
|
expr = newExpr;
|
|
local = nullptr;
|
|
}
|
|
void setLocal(AstLocal* newLocal)
|
|
{
|
|
local = newLocal;
|
|
expr = nullptr;
|
|
}
|
|
std::optional<Location> getLocation()
|
|
{
|
|
return expr ? expr->location : (local ? local->location : std::optional<Location>{});
|
|
}
|
|
std::optional<AstName> getName()
|
|
{
|
|
if (expr)
|
|
{
|
|
if (AstName name = getIdentifier(expr); name.value)
|
|
{
|
|
return name;
|
|
}
|
|
}
|
|
else if (local)
|
|
{
|
|
return local->name;
|
|
}
|
|
return std::nullopt;
|
|
}
|
|
|
|
private:
|
|
AstExpr* expr = nullptr;
|
|
AstLocal* local = nullptr;
|
|
};
|
|
|
|
std::vector<AstNode*> findAstAncestryOfPosition(const SourceModule& source, Position pos);
|
|
AstNode* findNodeAtPosition(const SourceModule& source, Position pos);
|
|
AstExpr* findExprAtPosition(const SourceModule& source, Position pos);
|
|
ScopePtr findScopeAtPosition(const Module& module, Position pos);
|
|
std::optional<Binding> findBindingAtPosition(const Module& module, const SourceModule& source, Position pos);
|
|
ExprOrLocal findExprOrLocalAtPosition(const SourceModule& source, Position pos);
|
|
|
|
std::optional<TypeId> findTypeAtPosition(const Module& module, const SourceModule& sourceModule, Position pos);
|
|
std::optional<TypeId> findExpectedTypeAtPosition(const Module& module, const SourceModule& sourceModule, Position pos);
|
|
|
|
std::optional<DocumentationSymbol> getDocumentationSymbolAtPosition(const SourceModule& source, const Module& module, Position position);
|
|
|
|
} // namespace Luau
|