Skip to content

Commit cba7d65

Browse files
Refactor for new solver (#783)
* Fix type registration with solver v2 * fix review * fix waitforchild magic function * review fix * Sync to Luau master, enable Luau fixes * fix fflags for test suite * requested changes * revert inlay hints changes to split off * latest luau * fix flags * sync * Fix doctest integration with IDE * Revert sync to 0.651 --------- Co-authored-by: JohnnyMorganz <[email protected]>
1 parent 7b47ec4 commit cba7d65

File tree

17 files changed

+221
-91
lines changed

17 files changed

+221
-91
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ jobs:
5353
cmake ..
5454
cmake --build . --target Luau.LanguageServer.Test -j 3
5555
56-
- name: Run Tests
56+
- name: Run Tests (Old Solver)
5757
run: ${{ matrix.test-path }}
5858

59+
- name: Run Tests (New Solver)
60+
run: ${{ matrix.test-path }} --new-solver
61+
5962
types_smoketest:
6063
name: Types Smoketest
6164
runs-on: ubuntu-20.04

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/build
22
.vscode/settings.json
33
/.vs
4+
out/
45
.cache
56
.idea
67
.DS_Store

CHANGELOG.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1010

1111
- Sync to upstream Luau 0.650
1212

13+
### Fixed
14+
15+
- Fixed autocompletion, type registration, hover types/documentation, and some crashes for cases where the new solver is enabled
16+
1317
## [1.34.0] - 2024-10-27
1418

1519
### Changed
@@ -117,7 +121,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
117121
### Changed
118122

119123
- Sync to upstream Luau 0.632
120-
- Language clients are recommended to send configuration during intializationOptions (see https://github.com/JohnnyMorganz/luau-lsp/blob/main/editors/README.md for details)
124+
- Language clients are recommended to send configuration during intializationOptions (see <https://github.com/JohnnyMorganz/luau-lsp/blob/main/editors/README.md> for details)
121125
- Removed need for postponing requests whilst waiting for platform configuration (relies on clients sending config in intializationOptions)
122126

123127
### Fixed
@@ -150,7 +154,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
150154
### Changed
151155

152156
- Sync to upstream Luau 0.631
153-
- An indexed expression will no longer show an inlay hint if the index matches the parameter name (i.e., `call(other.value)` won't add `value: ` inlay hint) ([#618](https://github.com/JohnnyMorganz/luau-lsp/issues/618))
157+
- An indexed expression will no longer show an inlay hint if the index matches the parameter name (i.e., `call(other.value)` won't add `value:` inlay hint) ([#618](https://github.com/JohnnyMorganz/luau-lsp/issues/618))
154158
- Studio Plugin will now perform Gzip compression on sent requests
155159

156160
### Fixed
@@ -182,7 +186,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
182186

183187
- Sync to upstream Luau 0.625
184188
- Improved memory usage of document and workspace diagnostics by no longer storing type graphs
185-
- Rewritten the Luau grammar syntax: https://github.com/JohnnyMorganz/Luau.tmLanguage
189+
- Rewritten the Luau grammar syntax: <https://github.com/JohnnyMorganz/Luau.tmLanguage>
186190

187191
### Fixed
188192

@@ -604,7 +608,7 @@ local DATA = {
604608

605609
--- Doc comment
606610
type Contents = {
607-
...
611+
...
608612
}
609613
```
610614

@@ -763,7 +767,7 @@ local y = tbl.data -- Should give "This is some special information"
763767
- Provide autocomplete for class names in `Instance:IsA("ClassName")` and errors when ClassName is unknown
764768
- Provide autocomplete for properties in `Instance:GetPropertyChangedSignal("Property")` and errors when Property is unknown
765769
- Provide autocomplete for enums in `EnumItem:IsA("enum")` and errors when Enum is unknown
766-
- Added support for moonwave-style documentation comments! Currently only supports comments attached to functions directly. See https://eryn.io/moonwave for how to write doc comments
770+
- Added support for moonwave-style documentation comments! Currently only supports comments attached to functions directly. See <https://eryn.io/moonwave> for how to write doc comments
767771
- Added command line flag `--ignore=GLOB` to `luau-lsp analyze` allowing you to provide glob patterns to ignore diagnostics, similar to `luau-lsp.ignoreGlobs`. Repeat the flag multiple times for multiple patterns
768772

769773
### Changed
@@ -981,7 +985,7 @@ local y = tbl.data -- Should give "This is some special information"
981985
- Fixed regression where diagnostics are not cleared when you close an ignored file
982986
- Fixed errors sometimes occuring when you index `script`/`workspace`/`game` for children
983987
- Fixed internal error caused by `:Clone()` calls when called on an expression which isn't an Lvalue (e.g., `inst:FindFirstChild(name):Clone()`)
984-
- Fixed bug where `_: ` would not be removed as the name of function arguments. `function foo(_: number, _: number)` will now show as `function foo(number, number)`
988+
- Fixed bug where `_:` would not be removed as the name of function arguments. `function foo(_: number, _: number)` will now show as `function foo(number, number)`
985989
- Fixed analyze mode not exiting with a non-zero exit code when there are errors
986990
- Fixed excessive whitespace in document symbols for expr-named function defintions
987991
- Fixed hover for global functions and local variables
@@ -1147,7 +1151,7 @@ local y = tbl.data -- Should give "This is some special information"
11471151

11481152
- Hover over definitions will now try to give more expressive types
11491153
- `self` will now no longer show up in hover/signature help if it has already been implicitly provided
1150-
- `_: ` will no longer show up in hover/signature help for unnamed function parameters
1154+
- `_:` will no longer show up in hover/signature help for unnamed function parameters
11511155

11521156
### Fixed
11531157

luau

Submodule luau updated from a251bc6 to 26b2307

src/AnalyzeCli.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <vector>
2323

2424
LUAU_FASTFLAG(DebugLuauTimeTracing)
25+
LUAU_FASTFLAG(LuauSolverV2)
2526

2627
enum class ReportFormat
2728
{
@@ -174,7 +175,7 @@ int startAnalyze(const argparse::ArgumentParser& program)
174175
if (std::filesystem::is_directory(path))
175176
{
176177
for (std::filesystem::recursive_directory_iterator next(path, std::filesystem::directory_options::skip_permission_denied), end;
177-
next != end; ++next)
178+
next != end; ++next)
178179
{
179180
try
180181
{
@@ -307,8 +308,9 @@ int startAnalyze(const argparse::ArgumentParser& program)
307308

308309
Luau::Frontend frontend(&fileResolver, &fileResolver, frontendOptions);
309310

310-
Luau::registerBuiltinGlobals(frontend, frontend.globals, /* typeCheckForAutocomplete = */ false);
311-
Luau::registerBuiltinGlobals(frontend, frontend.globalsForAutocomplete, /* typeCheckForAutocomplete = */ true);
311+
Luau::registerBuiltinGlobals(frontend, frontend.globals);
312+
if (!FFlag::LuauSolverV2)
313+
Luau::registerBuiltinGlobals(frontend, frontend.globalsForAutocomplete);
312314

313315
for (auto& definitionsPath : definitionsPaths)
314316
{
@@ -325,7 +327,7 @@ int startAnalyze(const argparse::ArgumentParser& program)
325327
return 1;
326328
}
327329

328-
auto loadResult = types::registerDefinitions(frontend, frontend.globals, *definitionsContents, /* typeCheckForAutocomplete = */ false);
330+
auto loadResult = types::registerDefinitions(frontend, frontend.globals, *definitionsContents);
329331
if (!loadResult.success)
330332
{
331333
fprintf(stderr, "Failed to load definitions\n");
@@ -359,8 +361,9 @@ int startAnalyze(const argparse::ArgumentParser& program)
359361
{
360362
robloxPlatform->updateSourceNodeMap(sourceMapContents.value());
361363

362-
robloxPlatform->handleSourcemapUpdate(
363-
frontend, frontend.globals, !program.is_used("--no-strict-dm-types") && client.configuration.diagnostics.strictDatamodelTypes);
364+
bool expressiveTypes =
365+
(program.is_used("--no-strict-dm-types") && client.configuration.diagnostics.strictDatamodelTypes) || FFlag::LuauSolverV2;
366+
robloxPlatform->handleSourcemapUpdate(frontend, frontend.globals, expressiveTypes);
364367
}
365368
}
366369
else
@@ -371,7 +374,8 @@ int startAnalyze(const argparse::ArgumentParser& program)
371374
}
372375

373376
Luau::freeze(frontend.globals.globalTypes);
374-
Luau::freeze(frontend.globalsForAutocomplete.globalTypes);
377+
if (!FFlag::LuauSolverV2)
378+
Luau::freeze(frontend.globalsForAutocomplete.globalTypes);
375379

376380
int failed = 0;
377381

src/LuauExt.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
#include <optional>
12
#include <utility>
23

4+
#include "Luau/Type.h"
35
#include "Platform/LSPPlatform.hpp"
46
#include "Luau/BuiltinDefinitions.h"
57
#include "Luau/ToString.h"
@@ -51,11 +53,10 @@ std::optional<nlohmann::json> parseDefinitionsFileMetadata(const std::string& de
5153
return std::nullopt;
5254
}
5355

54-
Luau::LoadDefinitionFileResult registerDefinitions(
55-
Luau::Frontend& frontend, Luau::GlobalTypes& globals, const std::string& definitions, bool typeCheckForAutocomplete)
56+
Luau::LoadDefinitionFileResult registerDefinitions(Luau::Frontend& frontend, Luau::GlobalTypes& globals, const std::string& definitions)
5657
{
5758
// TODO: packageName shouldn't just be "@roblox"
58-
return frontend.loadDefinitionFile(globals, globals.globalScope, definitions, "@roblox", /* captureComments = */ false, typeCheckForAutocomplete);
59+
return frontend.loadDefinitionFile(globals, globals.globalScope, definitions, "@roblox", /* captureComments = */ false);
5960
}
6061

6162
using NameOrExpr = std::variant<std::string, Luau::AstExpr*>;

src/Workspace.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,12 @@ void WorkspaceFolder::registerTypes()
285285
{
286286
LUAU_TIMETRACE_SCOPE("WorkspaceFolder::initialize", "LSP");
287287
client->sendTrace("workspace initialization: registering Luau globals");
288-
Luau::registerBuiltinGlobals(frontend, frontend.globals, /* typeCheckForAutocomplete = */ false);
289-
Luau::registerBuiltinGlobals(frontend, frontend.globalsForAutocomplete, /* typeCheckForAutocomplete = */ true);
288+
Luau::registerBuiltinGlobals(frontend, frontend.globals);
289+
if (!FFlag::LuauSolverV2)
290+
Luau::registerBuiltinGlobals(frontend, frontend.globalsForAutocomplete);
290291

291-
Luau::attachTag(Luau::getGlobalBinding(frontend.globalsForAutocomplete, "require"), "Require");
292+
auto& tagRegisterGlobals = FFlag::LuauSolverV2 ? frontend.globals : frontend.globalsForAutocomplete;
293+
Luau::attachTag(Luau::getGlobalBinding(tagRegisterGlobals, "require"), "Require");
292294

293295
if (client->definitionsFiles.empty())
294296
client->sendLogMessage(lsp::MessageType::Warning, "No definitions file provided by client");
@@ -314,8 +316,9 @@ void WorkspaceFolder::registerTypes()
314316
client->sendTrace("workspace initialization: parsing definitions file metadata COMPLETED", json(definitionsFileMetadata).dump());
315317

316318
client->sendTrace("workspace initialization: registering types definition");
317-
auto result = types::registerDefinitions(frontend, frontend.globals, *definitionsContents, /* typeCheckForAutocomplete = */ false);
318-
types::registerDefinitions(frontend, frontend.globalsForAutocomplete, *definitionsContents, /* typeCheckForAutocomplete = */ true);
319+
auto result = types::registerDefinitions(frontend, frontend.globals, *definitionsContents);
320+
if (!FFlag::LuauSolverV2)
321+
types::registerDefinitions(frontend, frontend.globalsForAutocomplete, *definitionsContents);
319322
client->sendTrace("workspace initialization: registering types definition COMPLETED");
320323

321324
client->sendTrace("workspace: applying platform mutations on definitions");
@@ -347,7 +350,8 @@ void WorkspaceFolder::registerTypes()
347350
}
348351
}
349352
Luau::freeze(frontend.globals.globalTypes);
350-
Luau::freeze(frontend.globalsForAutocomplete.globalTypes);
353+
if (!FFlag::LuauSolverV2)
354+
Luau::freeze(frontend.globalsForAutocomplete.globalTypes);
351355
}
352356

353357
void WorkspaceFolder::setupWithConfiguration(const ClientConfiguration& configuration)

src/include/LSP/LuauExt.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ bool isMetamethod(const Luau::Name& name);
1818

1919
std::optional<nlohmann::json> parseDefinitionsFileMetadata(const std::string& definitions);
2020

21-
Luau::LoadDefinitionFileResult registerDefinitions(
22-
Luau::Frontend& frontend, Luau::GlobalTypes& globals, const std::string& definitions, bool typeCheckForAutocomplete = false);
21+
Luau::LoadDefinitionFileResult registerDefinitions(Luau::Frontend& frontend, Luau::GlobalTypes& globals, const std::string& definitions);
2322

2423
using NameOrExpr = std::variant<std::string, Luau::AstExpr*>;
2524

src/operations/Completion.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "LSP/LuauExt.hpp"
1414
#include "LSP/DocumentationParser.hpp"
1515

16+
LUAU_FASTFLAG(LuauSolverV2)
17+
1618
void WorkspaceFolder::endAutocompletion(const lsp::CompletionParams& params)
1719
{
1820
auto moduleName = fileResolver.getModuleName(params.textDocument.uri);
@@ -256,8 +258,8 @@ static const char* sortText(const Luau::Frontend& frontend, const std::string& n
256258
return SortText::AutoImports;
257259

258260
// If the entry is `loadstring`, deprioritise it
259-
if (auto it = frontend.globalsForAutocomplete.globalScope->bindings.find(Luau::AstName("loadstring"));
260-
it != frontend.globalsForAutocomplete.globalScope->bindings.end())
261+
auto& completionGlobals = FFlag::LuauSolverV2 ? frontend.globals : frontend.globalsForAutocomplete;
262+
if (auto it = completionGlobals.globalScope->bindings.find(Luau::AstName("loadstring")); it != completionGlobals.globalScope->bindings.end())
261263
{
262264
if (entry.type == it->second.typeId)
263265
return SortText::Deprioritized;
@@ -371,10 +373,11 @@ std::optional<std::string> WorkspaceFolder::getDocumentationForAutocompleteEntry
371373
if (parentTy)
372374
{
373375
// parentTy might be an intersected type, find the actual base ttv
374-
if (auto propInformation = lookupProp(*parentTy, name))
376+
auto followedTy = Luau::follow(*parentTy);
377+
if (auto propInformation = lookupProp(followedTy, name))
375378
definitionModuleName = Luau::getDefinitionModuleName(propInformation->first);
376379
else
377-
definitionModuleName = Luau::getDefinitionModuleName(*parentTy);
380+
definitionModuleName = Luau::getDefinitionModuleName(followedTy);
378381
}
379382
}
380383
}

src/platform/roblox/RobloxCompletion.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "LSP/Completion.hpp"
44
#include "LSP/Workspace.hpp"
55

6+
LUAU_FASTFLAG(LuauSolverV2)
7+
68
static constexpr const char* COMMON_SERVICES[] = {
79
"Players",
810
"ReplicatedStorage",
@@ -254,7 +256,8 @@ const char* RobloxPlatform::handleSortText(
254256
return SortText::PrioritisedSuggestion;
255257

256258
// If calling a property on ServiceProvider, then prioritise these properties
257-
if (auto dataModelType = frontend.globalsForAutocomplete.globalScope->lookupType("ServiceProvider");
259+
auto& completionGlobals = FFlag::LuauSolverV2 ? frontend.globals : frontend.globalsForAutocomplete;
260+
if (auto dataModelType = completionGlobals.globalScope->lookupType("ServiceProvider");
258261
dataModelType && Luau::get<Luau::ClassType>(dataModelType->type) && entry.containingClass &&
259262
Luau::isSubclass(entry.containingClass.value(), Luau::get<Luau::ClassType>(dataModelType->type)) && !entry.wrongIndexType)
260263
{
@@ -264,9 +267,9 @@ const char* RobloxPlatform::handleSortText(
264267
}
265268

266269
// If calling a property on an Instance, then prioritise these properties
267-
else if (auto instanceType = frontend.globalsForAutocomplete.globalScope->lookupType("Instance");
268-
instanceType && Luau::get<Luau::ClassType>(instanceType->type) && entry.containingClass &&
269-
Luau::isSubclass(entry.containingClass.value(), Luau::get<Luau::ClassType>(instanceType->type)) && !entry.wrongIndexType)
270+
else if (auto instanceType = completionGlobals.globalScope->lookupType("Instance");
271+
instanceType && Luau::get<Luau::ClassType>(instanceType->type) && entry.containingClass &&
272+
Luau::isSubclass(entry.containingClass.value(), Luau::get<Luau::ClassType>(instanceType->type)) && !entry.wrongIndexType)
270273
{
271274
if (auto it = std::find(std::begin(COMMON_INSTANCE_PROPERTIES), std::end(COMMON_INSTANCE_PROPERTIES), name);
272275
it != std::end(COMMON_INSTANCE_PROPERTIES))

0 commit comments

Comments
 (0)