luau/Analysis/src/Autocomplete.cpp
Vighnesh-V e190754565
Sync to upstream/release/680 (#1894)
# What's Changed?

This week includes many changes to bring the behaviours of the Old and
New Luau Type Solver more in line.
* The old solver now stringifies tables identically to the new solver.
Sealed tables are stringified as `{ ... }` and unsealed tables are
represented by `{| ... |}`, regardless of your choice of solver.


## New Type Solver

* Miscellaneous fixes to make the Luau Frontend able to dynamically
toggle which solve is used.
* Small fixes to reduce instances of nondeterminism of the New Type
Solver.
* Issue an error when a function that has multiple non-viable overloads
is used.
* Subtyping now returns more information about the generics for type
inference to consume.
* Stop stuck type-functions from blocking type inference. This should
lead to fewer instances of 'type inference failed to complete'.

## Fragment Autocomplete
* Fixed a bug where incremental autocomplete wouldn't be able to provide
results directly on a required module script.
`require(script.Module).{request completions here}` will now recommend
the properties returned by the required object.

---
Co-authored-by: Andy Friesen <afriesen@roblox.com>
Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com>
Co-authored-by: Sora Kanosue <skanosue@roblox.com>
Co-authored-by: Talha Pathan <tpathan@roblox.com>
Co-authored-by: Vighnesh Vijay <vvijay@roblox.com>
2025-06-27 13:14:36 -07:00

52 lines
1.7 KiB
C++

// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
#include "Luau/Autocomplete.h"
#include "Luau/AstQuery.h"
#include "Luau/TimeTrace.h"
#include "Luau/TypeArena.h"
#include "Luau/Module.h"
#include "Luau/Frontend.h"
#include "AutocompleteCore.h"
LUAU_FASTFLAG(LuauSolverV2)
namespace Luau
{
AutocompleteResult autocomplete(Frontend& frontend, const ModuleName& moduleName, Position position, StringCompletionCallback callback)
{
LUAU_TIMETRACE_SCOPE("Luau::autocomplete", "Autocomplete");
LUAU_TIMETRACE_ARGUMENT("name", moduleName.c_str());
const SourceModule* sourceModule = frontend.getSourceModule(moduleName);
if (!sourceModule)
return {};
ModulePtr module;
if (frontend.getLuauSolverMode() == SolverMode::New)
module = frontend.moduleResolver.getModule(moduleName);
else
module = frontend.moduleResolverForAutocomplete.getModule(moduleName);
if (!module)
return {};
NotNull<BuiltinTypes> builtinTypes = frontend.builtinTypes;
Scope* globalScope;
if (frontend.getLuauSolverMode() == SolverMode::New)
globalScope = frontend.globals.globalScope.get();
else
globalScope = frontend.globalsForAutocomplete.globalScope.get();
TypeArena typeArena;
if (isWithinComment(*sourceModule, position))
return {};
std::vector<AstNode*> ancestry = findAncestryAtPositionForAutocomplete(*sourceModule, position);
LUAU_ASSERT(!ancestry.empty());
ScopePtr startScope = findScopeAtPosition(*module, position);
return autocomplete_(module, builtinTypes, &typeArena, ancestry, globalScope, startScope, position, frontend.fileResolver, std::move(callback));
}
} // namespace Luau