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

Customizable Globals #888

Open
seancroach opened this issue Jan 3, 2025 · 1 comment
Open

Customizable Globals #888

seancroach opened this issue Jan 3, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@seancroach
Copy link

I love this project, but I've encountered a minor annoyance and can't find any guidance on this issue online, so I can only assume this behavior hasn't been implemented yet.

I'm using mlua embedded in a Rust application for plugin support. In general, luau-lsp works excellent with the following .vscode/settings.json:

{
    "luau-lsp.platform.type": "standard",
    "luau-lsp.sourcemap.enabled": false,
    "luau-lsp.types.definitionFiles": [
        // path to file with new globals
    ]
}

mlua, wonderfully, supports a StdLib structure to opt in or out of various globals by default. This is generally fine, and things can be selectively torn apart and re-implemented when initializing a Lua VM. But! To my knowledge, it's impossible to tell luau-lsp what globals don't exist. While I recognize this is a niche problem, it would be incredibly helpful if there was at least some way to achieve this behavior. (After all, disabling getfenv and setfenv isn't that much of a stretch for embedded Luau outside of Roblox, among other things.)

@JohnnyMorganz
Copy link
Owner

Thanks! Yup, there is currently no way to disable builtin globals right now, but it would be useful to support. This was also requested in #700.

Luau's analysis system has a set of hardcoded global definitions for builtins (https://github.com/luau-lang/luau/blob/master/Analysis/src/EmbeddedBuiltinDefinitions.cpp). We end up registering these for the LSP:

Luau::registerBuiltinGlobals(frontend, frontend.globals);

We could potentially make this optional, and allow a user to disable all builtin globals. They could then write out the ones that are still relevant in their own definitions file. However, some of the builtin definitions have "magic behaviour" attached to them, and that would be lost (https://github.com/luau-lang/luau/blob/9a102e2aff99ecaf2ad1e5ca59fc1c893d5e9b7c/Analysis/src/BuiltinDefinitions.cpp#L293).

We might be able to hack around this and accept a list of luau-lsp.types.disabledGlobals (similar to luau-lang/luau#1538), then still register all globals but delete the ones we don't care about after they were already registered from frontend.globalScope. For global variables / functions, this should be OK, but this would be problematic for global types due to dangling references (but luckily there are no global types defined right now, so we don't have to worry about that just yet!)

@JohnnyMorganz JohnnyMorganz added the enhancement New feature or request label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants