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

feat(lua): add basic LuaCATS types for internal lua code #986

Closed
wants to merge 1 commit into from

Conversation

mikavilpas
Copy link
Contributor

This commit adds rudimentary types for the internal lua code. This does not have a big effect on its own, but it can be a part of a bigger effort to add types to the codebase.

The types are only usable within yazi itself and are not published for plugin developers to use (yet).

I only added types for the things that are defined in the lua side of the codebase. This means most of the useful typing is still missing. I want to add that separately, as it would be difficult to keep the types in sync with the actual codebase.

The plan:

  • add lua types for lua code
  • add lua types for rust code with a new tool
  • export both as LuaCATS Language Server Addons (meta files)
  • finally, publish the types for plugin developers to use

See #981 for more discussion.

This commit adds rudimentary types for the internal lua code. This does
not have a big effect on its own, but it can be a part of a bigger
effort to add types to the codebase.

The types are only usable within yazi itself and are not published for
plugin developers to use (yet).

I only added types for the things that are defined in the lua side of
the codebase. This means most of the useful typing is still missing. I
want to add that separately, as it would be difficult to keep the types
in sync with the actual codebase.
@sxyazi
Copy link
Owner

sxyazi commented May 1, 2024

Thanks. I think it's better to extract them into a separate file, similar to TypeScript's .d.ts file for dedicated type definitions. I'm not sure if Lua can do this.

@mikavilpas
Copy link
Contributor Author

I agree, and it's probably the easiest way to accomplish the goal of adding types to yazi. It's actually what I would like to do eventually, but I see I did not explain this very well:

  1. (this PR) generate types for .lua files
    • have them be next to the code so that they are very easy to keep up to date
  2. generate LuaCATS types from rust code and put them into a file
  3. combine both using some tool that extracts the lua types into a separate file

However, for defining the types I think it would be the easiest to define them where they are used. I am a bit worried that by defining the types separately,

  • keeping the lua types up to date will be difficult
  • module private helper functions and variables cannot be typed at all

Is your motivation performance?

@bvr-yr
Copy link

bvr-yr commented May 2, 2024

oh, I suppose that's it? #934

@mikavilpas
Copy link
Contributor Author

@bvr-yr yes, that is exactly what I am after. Although currently I'm just getting some discussion started on a way this could be done. This PR could be part of a larger effort to do it, so this will alone not solve everything 🙂

@bvr-yr
Copy link

bvr-yr commented May 2, 2024

nice then! cause currently I just ignore them in .luarc.json
as I can understand, final goal is to expose all stuff, not only lua presets, like ya.manager_emit and etc for example?

@mikavilpas
Copy link
Contributor Author

Yeah, that's exactly it. Ideally everything would be fully typed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants