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/Location.h"
|
2023-01-04 01:33:19 +08:00
|
|
|
#include "Luau/Type.h"
|
2021-10-30 04:25:12 +08:00
|
|
|
|
|
|
|
#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>;
|
|
|
|
|
2022-08-12 04:42:54 +08:00
|
|
|
enum class AutocompleteContext
|
|
|
|
{
|
|
|
|
Unknown,
|
|
|
|
Expression,
|
|
|
|
Statement,
|
|
|
|
Property,
|
|
|
|
Type,
|
|
|
|
Keyword,
|
|
|
|
String,
|
|
|
|
};
|
|
|
|
|
2021-10-30 04:25:12 +08:00
|
|
|
enum class AutocompleteEntryKind
|
|
|
|
{
|
|
|
|
Property,
|
|
|
|
Binding,
|
|
|
|
Keyword,
|
|
|
|
String,
|
|
|
|
Type,
|
|
|
|
Module,
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2023-01-04 01:33:19 +08:00
|
|
|
std::optional<const ClassType*> containingClass = std::nullopt;
|
2021-10-30 04:25:12 +08:00
|
|
|
std::optional<const Property*> prop = std::nullopt;
|
|
|
|
std::optional<std::string> documentationSymbol = std::nullopt;
|
|
|
|
Tags tags;
|
|
|
|
ParenthesesRecommendation parens = ParenthesesRecommendation::None;
|
|
|
|
};
|
|
|
|
|
|
|
|
using AutocompleteEntryMap = std::unordered_map<std::string, AutocompleteEntry>;
|
|
|
|
struct AutocompleteResult
|
|
|
|
{
|
|
|
|
AutocompleteEntryMap entryMap;
|
|
|
|
std::vector<AstNode*> ancestry;
|
2022-08-12 04:42:54 +08:00
|
|
|
AutocompleteContext context = AutocompleteContext::Unknown;
|
2021-10-30 04:25:12 +08:00
|
|
|
|
|
|
|
AutocompleteResult() = default;
|
2022-08-12 04:42:54 +08:00
|
|
|
AutocompleteResult(AutocompleteEntryMap entryMap, std::vector<AstNode*> ancestry, AutocompleteContext context)
|
2021-10-30 04:25:12 +08:00
|
|
|
: entryMap(std::move(entryMap))
|
|
|
|
, ancestry(std::move(ancestry))
|
2022-08-12 04:42:54 +08:00
|
|
|
, context(context)
|
2021-10-30 04:25:12 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
using ModuleName = std::string;
|
2023-01-20 20:02:39 +08:00
|
|
|
using StringCompletionCallback =
|
|
|
|
std::function<std::optional<AutocompleteEntryMap>(std::string tag, std::optional<const ClassType*> ctx, std::optional<std::string> contents)>;
|
2021-10-30 04:25:12 +08:00
|
|
|
|
|
|
|
AutocompleteResult autocomplete(Frontend& frontend, const ModuleName& moduleName, Position position, StringCompletionCallback callback);
|
2022-02-12 02:43:14 +08:00
|
|
|
|
2021-10-30 04:25:12 +08:00
|
|
|
} // namespace Luau
|