2021-10-30 04:25:12 +08: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"
|
|
|
|
#include "Luau/Documentation.h"
|
2023-10-21 09:10:30 +08:00
|
|
|
#include "Luau/TypeFwd.h"
|
2021-10-30 04:25:12 +08:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
|
|
|
|
struct Binding;
|
|
|
|
struct SourceModule;
|
|
|
|
struct Module;
|
|
|
|
|
|
|
|
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>{});
|
|
|
|
}
|
2022-01-28 07:46:05 +08:00
|
|
|
std::optional<AstName> getName()
|
|
|
|
{
|
|
|
|
if (expr)
|
|
|
|
{
|
|
|
|
if (AstName name = getIdentifier(expr); name.value)
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (local)
|
|
|
|
{
|
|
|
|
return local->name;
|
|
|
|
}
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
2021-10-30 04:25:12 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
AstExpr* expr = nullptr;
|
|
|
|
AstLocal* local = nullptr;
|
|
|
|
};
|
|
|
|
|
2024-07-27 01:47:49 +08:00
|
|
|
struct FindFullAncestry final : public AstVisitor
|
|
|
|
{
|
|
|
|
std::vector<AstNode*> nodes;
|
|
|
|
Position pos;
|
|
|
|
Position documentEnd;
|
|
|
|
bool includeTypes = false;
|
|
|
|
|
|
|
|
explicit FindFullAncestry(Position pos, Position documentEnd, bool includeTypes = false);
|
|
|
|
|
|
|
|
bool visit(AstType* type) override;
|
|
|
|
|
|
|
|
bool visit(AstStatFunction* node) override;
|
|
|
|
|
|
|
|
bool visit(AstNode* node) override;
|
|
|
|
};
|
|
|
|
|
2022-07-08 09:22:39 +08:00
|
|
|
std::vector<AstNode*> findAncestryAtPositionForAutocomplete(const SourceModule& source, Position pos);
|
2023-04-15 02:06:22 +08:00
|
|
|
std::vector<AstNode*> findAncestryAtPositionForAutocomplete(AstStatBlock* root, Position pos);
|
2023-01-21 04:27:03 +08:00
|
|
|
std::vector<AstNode*> findAstAncestryOfPosition(const SourceModule& source, Position pos, bool includeTypes = false);
|
2023-04-15 02:06:22 +08:00
|
|
|
std::vector<AstNode*> findAstAncestryOfPosition(AstStatBlock* root, Position pos, bool includeTypes = false);
|
2021-10-30 04:25:12 +08:00
|
|
|
AstNode* findNodeAtPosition(const SourceModule& source, Position pos);
|
2023-04-15 02:06:22 +08:00
|
|
|
AstNode* findNodeAtPosition(AstStatBlock* root, Position pos);
|
2021-10-30 04:25:12 +08:00
|
|
|
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
|