nvim-neorocks / nvim-best-practices

Collection of DOs and DON'Ts for modern Neovim Lua plugin development
Creative Commons Zero v1.0 Universal
237 stars 3 forks source link

request: how to set up type checking for tests #8

Closed mikavilpas closed 1 month ago

mikavilpas commented 1 month ago

Hello, and many thanks for the detailed instructions. I'm new to neovim plugin development and am working in the suggestions into my plugin right now.

I especially liked being able to add type checking into my CI workflows! I had no idea this is possible, and I think it will be a huge benefit to me in the long run.

In my project, I also use type annotations to (try to) keep the test data in sync. I'm looking for a way to add this to my CI, but seem to be getting lots of issues with my plugin's types not being found.

Here's my change: https://github.com/mikavilpas/yazi.nvim/commit/3e7a5dd2a3f3da0f4388ad877ff3043e711b6d5b, which produced https://github.com/mikavilpas/yazi.nvim/actions/runs/9228497829/job/25392627855#step:9:577

I spent about 45 minutes trying to figure this out but had no luck. Also, no other project on github seems to be doing this at the moment, so I was not able to find an existing example either.

To be clear, I'm more than willing to fix my project myself. What I'm looking for, if it's okay with you:

mrcjkb commented 1 month ago

Hey :wave:

Thanks for the nice words :wave:

Looking at your workflow file:

      directories: |
        lua
        tests

...will run the lua-language-server type checks once on the lua directory, and once on the tests directory. It can't see your types on the second run, because it sees tests as the root, and doesn't look up.

You should be able to fix this by running the checks in the project root:

      directories: .

And you can provide further configuration via a .luarc.json.

mikavilpas commented 1 month ago

Thanks for the idea. I tried various things out and I think the directories: . approach is the way to go.

Currently I've run into issues with the type checking covering the dependencies too despite attempts to ignore them. This results in 10k+ lines of error diagnostics, so there's still a bit of work to do šŸ˜„

I'm not sure but my guess is the lua-language-server does not handle ignores correctly in this case, or it's somehow configured to check the code base incorrectly.

A simple workaround would be to restructure the CI build so that the dependencies don't have to be placed inside the project. I will see if this is possible in github actions.

mrcjkb commented 1 month ago

Check out the docs on .luarc.json. The full schema is here. You should be able to configure lua-ls to ignore files or directories.