Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split Roblox-specific functionality into dedicated interface #505

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
10c2a63
Split Roblox-specific functionality into dedicated interface
voidedWarranties Nov 30, 2023
76e7aff
Merge branch 'main' of https://github.com/JohnnyMorganz/luau-lsp into…
JohnnyMorganz Dec 26, 2023
d3e5402
Fix frontend reference
JohnnyMorganz Dec 31, 2023
de6591f
Merge branch 'main' of https://github.com/JohnnyMorganz/luau-lsp into…
voidedWarranties Dec 31, 2023
901d216
Address initial review items
voidedWarranties Jan 1, 2024
a5319d2
Split RobloxPlatform into multiple files
voidedWarranties Jan 2, 2024
fbce308
Move some WorkspaceFileResolver functions into LSPPlatform
voidedWarranties Jan 6, 2024
9d762b7
Merge branch 'main' of https://github.com/JohnnyMorganz/luau-lsp into…
voidedWarranties Jan 6, 2024
77526ed
Fix MSVC build
voidedWarranties Jan 14, 2024
aff460b
Address review items
voidedWarranties Jan 20, 2024
9e72f06
Merge branch 'main' of https://github.com/JohnnyMorganz/luau-lsp into…
voidedWarranties Feb 23, 2024
63fdaf9
Initial extension split
voidedWarranties Feb 23, 2024
2a58485
Update extension config and config usage
voidedWarranties Feb 23, 2024
cfb8ba6
Merge branch 'main' of https://github.com/JohnnyMorganz/luau-lsp into…
voidedWarranties Apr 9, 2024
02ecb58
Resolve some issues
voidedWarranties Apr 9, 2024
7e16b8d
Merge branch 'main' of https://github.com/JohnnyMorganz/luau-lsp into…
JohnnyMorganz May 18, 2024
a60b248
Remove unused client config changes
JohnnyMorganz May 18, 2024
6b63e9a
Simplify readSourceCode
JohnnyMorganz May 18, 2024
de52f22
Merge branch 'main' into platform-specific-split
JohnnyMorganz May 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Deprecated
voidedWarranties marked this conversation as resolved.
Show resolved Hide resolved

- Deprecated `luau-lsp.types.roblox` setting in favour of `luau-lsp.platform.platform`
- Deprecated `luau-lsp.types.roblox` setting in favour of `luau-lsp.platform.type`
- Deprecated `luau-lsp.completion.imports.suggestServices` setting in favour of `luau-lsp.platform.roblox.suggestServices`
- Deprecated `luau-lsp.sourcemap.*` settings in favour of `luau-lsp.platform.roblox.sourcemap.*`

### Added

- Added `luau-lsp.platform.platform` to separate platform-specific functionality from the main LSP
- Added `luau-lsp.platform.type` to separate platform-specific functionality from the main LSP

### Fixed

- Switched to memory-efficient implementation of workspace diagnostics (currently behind FFlag `LuauStacklessTypeClone3`)
- Improved handling of configuration info received from non-VSCode clients

## [1.27.0] - 2023-12-25

Expand Down
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ target_sources(Luau.LanguageServer PRIVATE
src/Uri.cpp
src/WorkspaceFileResolver.cpp
src/Workspace.cpp
src/Sourcemap.cpp
src/TextDocument.cpp
src/Client.cpp
src/DocumentationParser.cpp
Expand All @@ -24,7 +23,15 @@ target_sources(Luau.LanguageServer PRIVATE
src/Utils.cpp
src/CliConfigurationParser.cpp
src/platform/LSPPlatform.cpp
src/platform/RobloxPlatform.cpp
src/platform/roblox/RobloxCodeAction.cpp
src/platform/roblox/RobloxColorProvider.cpp
src/platform/roblox/RobloxCompletion.cpp
src/platform/roblox/RobloxFileResolver.cpp
src/platform/roblox/RobloxLanguageServer.cpp
src/platform/roblox/RobloxLuauExt.cpp
src/platform/roblox/RobloxSourcemap.cpp
src/platform/roblox/RobloxSourceNode.cpp
src/platform/roblox/RobloxStudioPlugin.cpp
src/operations/Diagnostics.cpp
src/operations/Completion.cpp
src/operations/DocumentSymbol.cpp
Expand Down
64 changes: 56 additions & 8 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@
],
"scope": "resource"
},
"luau-lsp.platform.platform": {
"luau-lsp.platform.type": {
"markdownDescription": "Platform-specific support features",
"type": "string",
"enum": [
"vanilla",
"standard",
"roblox"
],
"scope": "window",
Expand All @@ -158,27 +158,67 @@
"markdownDescription": "Whether Rojo sourcemap parsing is enabled",
"type": "boolean",
"default": true,
"scope": "resource"
"scope": "resource",
"markdownDeprecationMessage": "**Deprecated**: Please use `#luau-lsp.platform.roblox.sourcemap.enabled#` instead.",
"deprecationMessage": "Deprecated: Please use luau-lsp.platform.roblox.sourcemap.enabled instead."
},
"luau-lsp.sourcemap.autogenerate": {
"markdownDescription": "Automatically run the `rojo sourcemap` command to regenerate sourcemaps on changes",
"type": "boolean",
"default": true,
"scope": "resource"
"scope": "resource",
"markdownDeprecationMessage": "**Deprecated**: Please use `#luau-lsp.platform.roblox.sourcemap.autogenerate#` instead.",
"deprecationMessage": "Deprecated: Please use luau-lsp.platform.roblox.sourcemap.autogenerate instead."
},
"luau-lsp.sourcemap.rojoPath": {
"markdownDescription": "Path to the Rojo executable. If not provided, attempts to run `rojo` in the workspace directory, so it must be available on the PATH",
"type": "string",
"default": null,
"scope": "resource"
"scope": "resource",
"markdownDeprecationMessage": "**Deprecated**: Please use `#luau-lsp.platform.roblox.sourcemap.rojoPath#` instead.",
"deprecationMessage": "Deprecated: Please use luau-lsp.platform.roblox.sourcemap.rojoPath instead."
},
"luau-lsp.sourcemap.rojoProjectFile": {
"markdownDescription": "The name of the Rojo project file to generate a sourcemap for.\nOnly applies if `#luau-lsp.sourcemap.autogenerate#` is enabled",
"type": "string",
"default": "default.project.json",
"scope": "resource"
"scope": "resource",
"markdownDeprecationMessage": "**Deprecated**: Please use `#luau-lsp.platform.roblox.sourcemap.rojoProjectFile#` instead.",
"deprecationMessage": "Deprecated: Please use luau-lsp.platform.roblox.sourcemap.rojoProjectFile instead."
},
"luau-lsp.sourcemap.includeNonScripts": {
"markdownDescription": "Include non-script instances in the generated sourcemap",
"type": "boolean",
"default": true,
"scope": "resource",
"markdownDeprecationMessage": "**Deprecated**: Please use `#luau-lsp.platform.roblox.sourcemap.includeNonScripts#` instead.",
"deprecationMessage": "Deprecated: Please use luau-lsp.platform.roblox.sourcemap.includeNonScripts instead."
},
"luau-lsp.platform.roblox.sourcemap.enabled": {
"markdownDescription": "Whether Rojo sourcemap parsing is enabled",
"type": "boolean",
"default": true,
"scope": "resource"
},
"luau-lsp.platform.roblox.sourcemap.autogenerate": {
"markdownDescription": "Automatically run the `rojo sourcemap` command to regenerate sourcemaps on changes",
"type": "boolean",
"default": true,
"scope": "resource"
},
"luau-lsp.platform.roblox.sourcemap.rojoPath": {
"markdownDescription": "Path to the Rojo executable. If not provided, attempts to run `rojo` in the workspace directory, so it must be available on the PATH",
"type": "string",
"default": null,
"scope": "resource"
},
"luau-lsp.platform.roblox.sourcemap.rojoProjectFile": {
"markdownDescription": "The name of the Rojo project file to generate a sourcemap for.\nOnly applies if `#luau-lsp.sourcemap.autogenerate#` is enabled",
"type": "string",
"default": "default.project.json",
"scope": "resource"
},
"luau-lsp.platform.roblox.sourcemap.includeNonScripts": {
"markdownDescription": "Include non-script instances in the generated sourcemap",
"type": "boolean",
"default": true,
Expand Down Expand Up @@ -221,6 +261,14 @@
"scope": "resource"
},
"luau-lsp.diagnostics.strictDatamodelTypes": {
"markdownDescription": "Use strict DataModel types in diagnostics. When on, this is equivalent to the more expressive autocompletion types. When this is off, `game`/`script`/`workspace` (and their members) are all typed as `any`, and helps to prevent false positives. [Read More](https://github.com/JohnnyMorganz/luau-lsp/issues/83#issuecomment-1192865024)",
"type": "boolean",
"default": false,
"scope": "resource",
"markdownDeprecationMessage": "**Deprecated**: Please use `#luau-lsp.platform.roblox.diagnostics.strictDatamodelTypes#` instead.",
"deprecationMessage": "Deprecated: Please use luau-lsp.platform.roblox.diagnostics.strictDatamodelTypes instead."
},
"luau-lsp.platform.roblox.diagnostics.strictDatamodelTypes": {
"markdownDescription": "Use strict DataModel types in diagnostics. When on, this is equivalent to the more expressive autocompletion types. When this is off, `game`/`script`/`workspace` (and their members) are all typed as `any`, and helps to prevent false positives. [Read More](https://github.com/JohnnyMorganz/luau-lsp/issues/83#issuecomment-1192865024)",
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -252,8 +300,8 @@
"tags": [
"usesOnlineServices"
],
"markdownDeprecationMessage": "**Deprecated**: Please use `#luau-lsp.platform.platform#` instead.",
"deprecationMessage": "Deprecated: Please use luau-lsp.platform.platform instead."
"markdownDeprecationMessage": "**Deprecated**: Please use `#luau-lsp.platform.type#` instead.",
"deprecationMessage": "Deprecated: Please use luau-lsp.platform.type instead."
},
"luau-lsp.types.robloxSecurityLevel": {
"markdownDescription": "Security Level to use in the Roblox API definitions",
Expand Down
42 changes: 29 additions & 13 deletions src/AnalyzeCli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include "Analyze/CliConfigurationParser.hpp"
#include "Analyze/CliClient.hpp"

#include "LSP/ClientConfiguration.hpp"
#include "Platform/LSPPlatform.hpp"
#include "Platform/RobloxPlatform.hpp"
#include "Luau/ModuleResolver.h"
#include "Luau/BuiltinDefinitions.h"
#include "Luau/Frontend.h"
Expand Down Expand Up @@ -73,11 +75,11 @@ static bool reportError(
{
auto* fileResolver = static_cast<WorkspaceFileResolver*>(frontend.fileResolver);
std::filesystem::path rootUriPath = fileResolver->rootUri.fsPath();
auto path = fileResolver->resolveToRealPath(error.moduleName);
auto path = fileResolver->platform->resolveToRealPath(error.moduleName);

// For consistency, we want to map the error.moduleName to a relative path (if it is a real path)
Luau::ModuleName errorFriendlyName = error.moduleName;
if (!fileResolver->isVirtualPath(error.moduleName))
if (!fileResolver->platform->isVirtualPath(error.moduleName))
errorFriendlyName = std::filesystem::proximate(*path, rootUriPath).generic_string();

std::string humanReadableName = fileResolver->getHumanReadableModuleName(errorFriendlyName);
Expand Down Expand Up @@ -258,8 +260,6 @@ int startAnalyze(const argparse::ArgumentParser& program)
}
}

std::unique_ptr<LSPPlatform> platform = LSPPlatform::getPlatform(client.configuration);

WorkspaceFileResolver fileResolver;
if (baseLuaurc)
{
Expand All @@ -283,16 +283,21 @@ int startAnalyze(const argparse::ArgumentParser& program)

fileResolver.rootUri = Uri::file(std::filesystem::current_path());
fileResolver.client = std::make_shared<CliClient>(client);
Luau::Frontend frontend(&fileResolver, &fileResolver, frontendOptions);

if (sourcemapPath)
if (auto platformArg = program.present("--platform"))
{
if (auto sourceMapContents = readFile(*sourcemapPath))
{
fileResolver.updateSourceMap(sourceMapContents.value());
}
if (platformArg == "standard")
client.configuration.platform.type = LSPPlatformConfig::Standard;
else if (platformArg == "roblox")
client.configuration.platform.type = LSPPlatformConfig::Roblox;
}

std::unique_ptr<LSPPlatform> platform = LSPPlatform::getPlatform(client.configuration, &fileResolver);

fileResolver.platform = platform.get();

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

Luau::registerBuiltinGlobals(frontend, frontend.globals, /* typeCheckForAutocomplete = */ false);
Luau::registerBuiltinGlobals(frontend, frontend.globalsForAutocomplete, /* typeCheckForAutocomplete = */ true);

Expand Down Expand Up @@ -332,11 +337,22 @@ int startAnalyze(const argparse::ArgumentParser& program)
return 1;
}

platform->handleRegisterDefinitions(frontend.globals, types::parseDefinitionsFileMetadata(*definitionsContents));
platform->mutateRegisteredDefinitions(frontend.globals, types::parseDefinitionsFileMetadata(*definitionsContents));
}

platform->handleSourcemapUpdate(
frontend, frontend.globals, fileResolver, !program.is_used("--no-strict-dm-types") && client.configuration.diagnostics.strictDatamodelTypes);
if (sourcemapPath && client.configuration.platform.type == LSPPlatformConfig::Roblox)
voidedWarranties marked this conversation as resolved.
Show resolved Hide resolved
{
auto robloxPlatform = dynamic_cast<RobloxPlatform*>(platform.get());

if (auto sourceMapContents = readFile(*sourcemapPath))
{
robloxPlatform->updateSourceNodeMap(sourceMapContents.value());

robloxPlatform->handleSourcemapUpdate(frontend, frontend.globals,
!program.is_used("--no-strict-dm-types") && client.configuration.diagnostics.strictDatamodelTypes &&
client.configuration.platform.roblox.diagnostics.strictDatamodelTypes);
}
}

Luau::freeze(frontend.globals.globalTypes);
Luau::freeze(frontend.globalsForAutocomplete.globalTypes);
Expand Down
Loading
Loading