Skip to content

Commit d01addc

Browse files
zeuxrkaev-convex
andcommitted
Sync to upstream/release/501 (#20)
Co-authored-by: Rodactor <[email protected]>
1 parent 12b2838 commit d01addc

File tree

336 files changed

+118239
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

336 files changed

+118239
-0
lines changed

.clang-format

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
BasedOnStyle: LLVM
2+
3+
AccessModifierOffset: -4
4+
AllowShortBlocksOnASingleLine: Never
5+
AllowShortCaseLabelsOnASingleLine: false
6+
AllowShortFunctionsOnASingleLine: Empty
7+
AllowShortLambdasOnASingleLine: Empty
8+
AllowShortIfStatementsOnASingleLine: Never
9+
AllowShortLoopsOnASingleLine: false
10+
BreakBeforeBraces: Allman
11+
BreakConstructorInitializers: BeforeComma
12+
BreakInheritanceList: BeforeComma
13+
ColumnLimit: 150
14+
IndentCaseLabels: false
15+
SortIncludes: false
16+
IndentWidth: 4
17+
TabWidth: 4
18+
ObjCBlockIndentWidth: 4
19+
AlignAfterOpenBracket: DontAlign
20+
UseTab: Never
21+
PointerAlignment: Left
22+
SpaceAfterTemplateKeyword: false
23+
AlignEscapedNewlines: DontAlign
24+
AlwaysBreakTemplateDeclarations: Yes
25+
MaxEmptyLinesToKeep: 10

Analysis/include/Luau/AstQuery.h

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2+
#pragma once
3+
4+
#include "Luau/Ast.h"
5+
#include "Luau/Documentation.h"
6+
7+
#include <memory>
8+
9+
namespace Luau
10+
{
11+
12+
struct Binding;
13+
struct SourceModule;
14+
struct Module;
15+
16+
struct TypeVar;
17+
using TypeId = const TypeVar*;
18+
19+
using ScopePtr = std::shared_ptr<struct Scope>;
20+
21+
struct ExprOrLocal
22+
{
23+
AstExpr* getExpr()
24+
{
25+
return expr;
26+
}
27+
AstLocal* getLocal()
28+
{
29+
return local;
30+
}
31+
void setExpr(AstExpr* newExpr)
32+
{
33+
expr = newExpr;
34+
local = nullptr;
35+
}
36+
void setLocal(AstLocal* newLocal)
37+
{
38+
local = newLocal;
39+
expr = nullptr;
40+
}
41+
std::optional<Location> getLocation()
42+
{
43+
return expr ? expr->location : (local ? local->location : std::optional<Location>{});
44+
}
45+
46+
private:
47+
AstExpr* expr = nullptr;
48+
AstLocal* local = nullptr;
49+
};
50+
51+
std::vector<AstNode*> findAstAncestryOfPosition(const SourceModule& source, Position pos);
52+
AstNode* findNodeAtPosition(const SourceModule& source, Position pos);
53+
AstExpr* findExprAtPosition(const SourceModule& source, Position pos);
54+
ScopePtr findScopeAtPosition(const Module& module, Position pos);
55+
std::optional<Binding> findBindingAtPosition(const Module& module, const SourceModule& source, Position pos);
56+
ExprOrLocal findExprOrLocalAtPosition(const SourceModule& source, Position pos);
57+
58+
std::optional<TypeId> findTypeAtPosition(const Module& module, const SourceModule& sourceModule, Position pos);
59+
std::optional<TypeId> findExpectedTypeAtPosition(const Module& module, const SourceModule& sourceModule, Position pos);
60+
61+
std::optional<DocumentationSymbol> getDocumentationSymbolAtPosition(const SourceModule& source, const Module& module, Position position);
62+
63+
} // namespace Luau

Analysis/include/Luau/Autocomplete.h

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2+
#pragma once
3+
4+
#include "Luau/Location.h"
5+
#include "Luau/TypeVar.h"
6+
7+
#include <unordered_map>
8+
#include <string>
9+
#include <memory>
10+
#include <optional>
11+
12+
namespace Luau
13+
{
14+
15+
struct Frontend;
16+
struct SourceModule;
17+
struct Module;
18+
struct TypeChecker;
19+
20+
using ModulePtr = std::shared_ptr<Module>;
21+
22+
enum class AutocompleteEntryKind
23+
{
24+
Property,
25+
Binding,
26+
Keyword,
27+
String,
28+
Type,
29+
Module,
30+
};
31+
32+
enum class ParenthesesRecommendation
33+
{
34+
None,
35+
CursorAfter,
36+
CursorInside,
37+
};
38+
39+
enum class TypeCorrectKind
40+
{
41+
None,
42+
Correct,
43+
CorrectFunctionResult,
44+
};
45+
46+
struct AutocompleteEntry
47+
{
48+
AutocompleteEntryKind kind = AutocompleteEntryKind::Property;
49+
// Nullopt if kind is Keyword
50+
std::optional<TypeId> type = std::nullopt;
51+
bool deprecated = false;
52+
// Only meaningful if kind is Property.
53+
bool wrongIndexType = false;
54+
// Set if this suggestion matches the type expected in the context
55+
TypeCorrectKind typeCorrect = TypeCorrectKind::None;
56+
57+
std::optional<const ClassTypeVar*> containingClass = std::nullopt;
58+
std::optional<const Property*> prop = std::nullopt;
59+
std::optional<std::string> documentationSymbol = std::nullopt;
60+
Tags tags;
61+
ParenthesesRecommendation parens = ParenthesesRecommendation::None;
62+
};
63+
64+
using AutocompleteEntryMap = std::unordered_map<std::string, AutocompleteEntry>;
65+
struct AutocompleteResult
66+
{
67+
AutocompleteEntryMap entryMap;
68+
std::vector<AstNode*> ancestry;
69+
70+
AutocompleteResult() = default;
71+
AutocompleteResult(AutocompleteEntryMap entryMap, std::vector<AstNode*> ancestry)
72+
: entryMap(std::move(entryMap))
73+
, ancestry(std::move(ancestry))
74+
{
75+
}
76+
};
77+
78+
using ModuleName = std::string;
79+
using StringCompletionCallback = std::function<std::optional<AutocompleteEntryMap>(std::string tag, std::optional<const ClassTypeVar*> ctx)>;
80+
81+
struct OwningAutocompleteResult
82+
{
83+
AutocompleteResult result;
84+
ModulePtr module;
85+
std::unique_ptr<SourceModule> sourceModule;
86+
};
87+
88+
AutocompleteResult autocomplete(Frontend& frontend, const ModuleName& moduleName, Position position, StringCompletionCallback callback);
89+
OwningAutocompleteResult autocompleteSource(Frontend& frontend, std::string_view source, Position position, StringCompletionCallback callback);
90+
91+
} // namespace Luau
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2+
#pragma once
3+
4+
#include "TypeInfer.h"
5+
6+
namespace Luau
7+
{
8+
9+
void registerBuiltinTypes(TypeChecker& typeChecker);
10+
11+
TypeId makeUnion(TypeArena& arena, std::vector<TypeId>&& types);
12+
TypeId makeIntersection(TypeArena& arena, std::vector<TypeId>&& types);
13+
14+
/** Build an optional 't'
15+
*/
16+
TypeId makeOption(TypeChecker& typeChecker, TypeArena& arena, TypeId t);
17+
18+
/** Small utility function for building up type definitions from C++.
19+
*/
20+
TypeId makeFunction( // Monomorphic
21+
TypeArena& arena, std::optional<TypeId> selfType, std::initializer_list<TypeId> paramTypes, std::initializer_list<TypeId> retTypes);
22+
23+
TypeId makeFunction( // Polymorphic
24+
TypeArena& arena, std::optional<TypeId> selfType, std::initializer_list<TypeId> generics, std::initializer_list<TypePackId> genericPacks,
25+
std::initializer_list<TypeId> paramTypes, std::initializer_list<TypeId> retTypes);
26+
27+
TypeId makeFunction( // Monomorphic
28+
TypeArena& arena, std::optional<TypeId> selfType, std::initializer_list<TypeId> paramTypes, std::initializer_list<std::string> paramNames,
29+
std::initializer_list<TypeId> retTypes);
30+
31+
TypeId makeFunction( // Polymorphic
32+
TypeArena& arena, std::optional<TypeId> selfType, std::initializer_list<TypeId> generics, std::initializer_list<TypePackId> genericPacks,
33+
std::initializer_list<TypeId> paramTypes, std::initializer_list<std::string> paramNames, std::initializer_list<TypeId> retTypes);
34+
35+
void attachMagicFunction(TypeId ty, MagicFunction fn);
36+
void attachFunctionTag(TypeId ty, std::string constraint);
37+
38+
Property makeProperty(TypeId ty, std::optional<std::string> documentationSymbol = std::nullopt);
39+
void assignPropDocumentationSymbols(TableTypeVar::Props& props, const std::string& baseName);
40+
41+
std::string getBuiltinDefinitionSource();
42+
43+
void addGlobalBinding(TypeChecker& typeChecker, const std::string& name, TypeId ty, const std::string& packageName);
44+
void addGlobalBinding(TypeChecker& typeChecker, const std::string& name, Binding binding);
45+
void addGlobalBinding(TypeChecker& typeChecker, const ScopePtr& scope, const std::string& name, TypeId ty, const std::string& packageName);
46+
void addGlobalBinding(TypeChecker& typeChecker, const ScopePtr& scope, const std::string& name, Binding binding);
47+
std::optional<Binding> tryGetGlobalBinding(TypeChecker& typeChecker, const std::string& name);
48+
Binding* tryGetGlobalBindingRef(TypeChecker& typeChecker, const std::string& name);
49+
TypeId getGlobalBinding(TypeChecker& typeChecker, const std::string& name);
50+
51+
} // namespace Luau

Analysis/include/Luau/Config.h

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2+
#pragma once
3+
4+
#include "Luau/Linter.h"
5+
#include "Luau/ParseOptions.h"
6+
7+
#include <string>
8+
#include <optional>
9+
#include <vector>
10+
11+
namespace Luau
12+
{
13+
14+
using ModuleName = std::string;
15+
16+
constexpr const char* kConfigName = ".luaurc";
17+
18+
struct Config
19+
{
20+
Config()
21+
{
22+
enabledLint.setDefaults();
23+
}
24+
25+
Mode mode = Mode::NoCheck;
26+
27+
ParseOptions parseOptions;
28+
29+
LintOptions enabledLint;
30+
LintOptions fatalLint;
31+
32+
bool lintErrors = false;
33+
bool typeErrors = true;
34+
35+
std::vector<std::string> globals;
36+
};
37+
38+
struct ConfigResolver
39+
{
40+
virtual ~ConfigResolver() {}
41+
42+
virtual const Config& getConfig(const ModuleName& name) const = 0;
43+
};
44+
45+
struct NullConfigResolver : ConfigResolver
46+
{
47+
Config defaultConfig;
48+
49+
virtual const Config& getConfig(const ModuleName& name) const override;
50+
};
51+
52+
std::optional<std::string> parseModeString(Mode& mode, const std::string& modeString, bool compat = false);
53+
std::optional<std::string> parseLintRuleString(
54+
LintOptions& enabledLints, LintOptions& fatalLints, const std::string& warningName, const std::string& value, bool compat = false);
55+
56+
std::optional<std::string> parseConfig(const std::string& contents, Config& config, bool compat = false);
57+
58+
} // namespace Luau

Analysis/include/Luau/Documentation.h

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#pragma once
2+
3+
#include "Luau/DenseHash.h"
4+
#include "Luau/Variant.h"
5+
6+
#include <string>
7+
#include <vector>
8+
9+
namespace Luau
10+
{
11+
12+
struct FunctionDocumentation;
13+
struct TableDocumentation;
14+
struct OverloadedFunctionDocumentation;
15+
16+
using Documentation = Luau::Variant<std::string, FunctionDocumentation, TableDocumentation, OverloadedFunctionDocumentation>;
17+
using DocumentationSymbol = std::string;
18+
19+
struct FunctionParameterDocumentation
20+
{
21+
std::string name;
22+
DocumentationSymbol documentation;
23+
};
24+
25+
// Represents documentation for anything callable. This could be a method or a
26+
// callback or a free function.
27+
struct FunctionDocumentation
28+
{
29+
std::string documentation;
30+
std::vector<FunctionParameterDocumentation> parameters;
31+
std::vector<DocumentationSymbol> returns;
32+
};
33+
34+
struct OverloadedFunctionDocumentation
35+
{
36+
// This is a map of function signature to overload symbol name.
37+
Luau::DenseHashMap<std::string, DocumentationSymbol> overloads;
38+
};
39+
40+
// Represents documentation for a table-like item, meaning "anything with keys".
41+
// This could be a table or a class.
42+
struct TableDocumentation
43+
{
44+
std::string documentation;
45+
Luau::DenseHashMap<std::string, DocumentationSymbol> keys;
46+
};
47+
48+
using DocumentationDatabase = Luau::DenseHashMap<DocumentationSymbol, Documentation>;
49+
50+
} // namespace Luau

0 commit comments

Comments
 (0)