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

luau-analyze: add --definitions=<file> option for loading type definition files #1139

Closed
wants to merge 1 commit into from

Conversation

nurpax
Copy link

@nurpax nurpax commented Jan 5, 2024

Add the ability to load a type definition file before type checking.

This is useful in projects that'd like to declare their own types (such as types declared by their game engine's Luau integration code) and linting their scripts using 'luau-analyze'.

This is modeled to behave similar to the luau-lsp.types.definitionFiles in the Luau LSP project (https://github.com/JohnnyMorganz/luau-lsp).

Usage example:

  luau-analyze --definitions=engine_types.d.luau some_script.luau

I also implemented small example project that motivates why and how to use type definition files. The project declares some functionality in Zig, exposes the Zig functions to Luau, and declares the added object types so that luau-analyze can be used to type check any scripts written against this code: https://github.com/nurpax/luau-zig-example/tree/main/src. Summary of the example source files:

  • Player.zig (first ten lines)
  • types.d.luau
  • main.luau <- this uses the "engine" and this is the file that would be luau-analyzed. Without the --definitions flag, it's hard to lint this file because the engine's types are missing.

…tion files

Add the ability to load a type definition file before type checking.

This is useful in projects that'd like to declare their own types
(such as types declared by their game engine's Luau integration code)
and linting their scripts using 'luau-analyze'.

This is modeled to behave similar to the luau-lsp.types.definitionFiles
in the Luau LSP project (https://github.com/JohnnyMorganz/luau-lsp).

Usage example:

  luau-analyze --definitions=engine_types.d.luau some_script.luau

Note: doesn't introduce new clang-format delta, but the edited
file already deviates from what clang-format produces.

for luau-lang#1140
@vegorov-rbx
Copy link
Collaborator

Thank you for your interest in improving Luau, but we have definition file support in .luaurc files on our roadmap, so we are not going to merge this contribution.
#418

@alexmccord
Copy link
Member

Closing this. I think --definitions=<file> as a command line argument is a little brittle, since it means you have to setup your command line invocations correctly to get type checking to do the right thing. I'd much rather the path to a definition be added in the source tree itself.

@alexmccord alexmccord closed this Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants