mirror of
https://github.com/luau-lang/luau.git
synced 2024-11-15 14:25:44 +08:00
76f67e0733
Type checker/autocomplete: * `Luau::autocomplete` no longer performs typechecking internally, make sure to run `Frontend::check` before performing autocomplete requests * Autocomplete string suggestions without "" are now only suggested inside the "" * Autocomplete suggestions now include `function (anonymous autofilled)` key with a full suggestion for the function expression (with arguments included) stored in `AutocompleteEntry::insertText` * `AutocompleteEntry::indexedWithSelf` is provided for function call suggestions made with `:` * Cyclic modules now see each other type exports as `any` to prevent memory use-after-free (similar to module return type) Runtime: * Updated inline/loop unroll cost model to better handle assignments (Fixes https://github.com/Roblox/luau/issues/978) * `math.noise` speed was improved by ~30% * `table.concat` speed was improved by ~5-7% * `tonumber` and `tostring` now have fastcall paths that execute ~1.5x and ~2.5x faster respectively (fixes #777) * Fixed crash in `luaL_typename` when index refers to a non-existing value * Fixed potential out of memory scenario when using `string.sub` or `string.char` in a loop * Fixed behavior of some fastcall builtins when called without arguments under -O2 to match original functions * Support for native code execution in VM is now enabled by default (note: native code still has to be generated explicitly) * `Codegen::compile` now accepts `CodeGen_OnlyNativeModules` flag. When set, only modules that have a `--!native` hot-comment at the top will be compiled to native code In our new typechecker: * Generic type packs are no longer considered to be variadic during unification * Timeout and cancellation now works in new solver * Fixed false positive errors around 'table' and 'function' type refinements * Table literals now use covariant unification rules. This is sound since literal has no type specified and has no aliases * Fixed issues with blocked types escaping the constraint solver * Fixed more places where error messages that should've been suppressed were still reported * Fixed errors when iterating over a top table type In our native code generation (jit): * 'DebugLuauAbortingChecks' flag is now supported on A64 * LOP_NEWCLOSURE has been translated to IR
105 lines
2.6 KiB
C++
105 lines
2.6 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/Location.h"
|
|
#include "Luau/Type.h"
|
|
|
|
#include <unordered_map>
|
|
#include <string>
|
|
#include <memory>
|
|
#include <optional>
|
|
|
|
namespace Luau
|
|
{
|
|
|
|
struct Frontend;
|
|
struct SourceModule;
|
|
struct Module;
|
|
struct TypeChecker;
|
|
|
|
using ModulePtr = std::shared_ptr<Module>;
|
|
|
|
enum class AutocompleteContext
|
|
{
|
|
Unknown,
|
|
Expression,
|
|
Statement,
|
|
Property,
|
|
Type,
|
|
Keyword,
|
|
String,
|
|
};
|
|
|
|
enum class AutocompleteEntryKind
|
|
{
|
|
Property,
|
|
Binding,
|
|
Keyword,
|
|
String,
|
|
Type,
|
|
Module,
|
|
GeneratedFunction,
|
|
};
|
|
|
|
enum class ParenthesesRecommendation
|
|
{
|
|
None,
|
|
CursorAfter,
|
|
CursorInside,
|
|
};
|
|
|
|
enum class TypeCorrectKind
|
|
{
|
|
None,
|
|
Correct,
|
|
CorrectFunctionResult,
|
|
};
|
|
|
|
struct AutocompleteEntry
|
|
{
|
|
AutocompleteEntryKind kind = AutocompleteEntryKind::Property;
|
|
// Nullopt if kind is Keyword
|
|
std::optional<TypeId> type = std::nullopt;
|
|
bool deprecated = false;
|
|
// Only meaningful if kind is Property.
|
|
bool wrongIndexType = false;
|
|
// Set if this suggestion matches the type expected in the context
|
|
TypeCorrectKind typeCorrect = TypeCorrectKind::None;
|
|
|
|
std::optional<const ClassType*> containingClass = std::nullopt;
|
|
std::optional<const Property*> prop = std::nullopt;
|
|
std::optional<std::string> documentationSymbol = std::nullopt;
|
|
Tags tags;
|
|
ParenthesesRecommendation parens = ParenthesesRecommendation::None;
|
|
std::optional<std::string> insertText;
|
|
|
|
// Only meaningful if kind is Property.
|
|
bool indexedWithSelf = false;
|
|
};
|
|
|
|
using AutocompleteEntryMap = std::unordered_map<std::string, AutocompleteEntry>;
|
|
struct AutocompleteResult
|
|
{
|
|
AutocompleteEntryMap entryMap;
|
|
std::vector<AstNode*> ancestry;
|
|
AutocompleteContext context = AutocompleteContext::Unknown;
|
|
|
|
AutocompleteResult() = default;
|
|
AutocompleteResult(AutocompleteEntryMap entryMap, std::vector<AstNode*> ancestry, AutocompleteContext context)
|
|
: entryMap(std::move(entryMap))
|
|
, ancestry(std::move(ancestry))
|
|
, context(context)
|
|
{
|
|
}
|
|
};
|
|
|
|
using ModuleName = std::string;
|
|
using StringCompletionCallback =
|
|
std::function<std::optional<AutocompleteEntryMap>(std::string tag, std::optional<const ClassType*> ctx, std::optional<std::string> contents)>;
|
|
|
|
AutocompleteResult autocomplete(Frontend& frontend, const ModuleName& moduleName, Position position, StringCompletionCallback callback);
|
|
|
|
constexpr char kGeneratedAnonymousFunctionEntryName[] = "function (anonymous autofilled)";
|
|
|
|
} // namespace Luau
|