// 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 "Luau/TypeFwd.h" #include namespace Luau { struct Binding; struct SourceModule; struct Module; using ScopePtr = std::shared_ptr; 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 getLocation() { return expr ? expr->location : (local ? local->location : std::optional{}); } std::optional 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 findAncestryAtPositionForAutocomplete(const SourceModule& source, Position pos); std::vector findAncestryAtPositionForAutocomplete(AstStatBlock* root, Position pos); std::vector findAstAncestryOfPosition(const SourceModule& source, Position pos, bool includeTypes = false); std::vector findAstAncestryOfPosition(AstStatBlock* root, Position pos, bool includeTypes = false); AstNode* findNodeAtPosition(const SourceModule& source, Position pos); AstNode* findNodeAtPosition(AstStatBlock* root, Position pos); AstExpr* findExprAtPosition(const SourceModule& source, Position pos); ScopePtr findScopeAtPosition(const Module& module, Position pos); std::optional findBindingAtPosition(const Module& module, const SourceModule& source, Position pos); ExprOrLocal findExprOrLocalAtPosition(const SourceModule& source, Position pos); std::optional findTypeAtPosition(const Module& module, const SourceModule& sourceModule, Position pos); std::optional findExpectedTypeAtPosition(const Module& module, const SourceModule& sourceModule, Position pos); std::optional getDocumentationSymbolAtPosition(const SourceModule& source, const Module& module, Position position); } // namespace Luau