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

Example for nix setup with neodev. #34

Closed
pysan3 opened this issue Nov 13, 2023 · 15 comments
Closed

Example for nix setup with neodev. #34

pysan3 opened this issue Nov 13, 2023 · 15 comments

Comments

@pysan3
Copy link

pysan3 commented Nov 13, 2023

Hi, I came across this action and I'm currently trying to integrate it into my plugin.
Being able to do type check before all commits would be amazing!

However, all files are raising errors since they cannot find the vim global variable at the moment.

When I look at your haskell-tools.nvim, you are doing some nix magic to install neodev and other plugins.

I don't have any experience with nix or nixos, so I'd be glad if you could give me an example of how to setup neovim with neodev installed to use this action.

Thanks in advance!

@mrcjkb
Copy link
Owner

mrcjkb commented Nov 13, 2023

Hey 👋

There are two ways you can solve the vim global issue with this action:

{
  "Lua.diagnostics.globals": ["vim"]
}

or

  • see this comment on how to checkout neodev. You could potentially also use luarocks to install dependencies, but I don't think neodev is on luarocks as of today.

Footnotes

  1. see the JSON schema.

@pysan3
Copy link
Author

pysan3 commented Nov 13, 2023

Thanks for you quick response!

1 is a no-go for me since I wanted to check if I'm calling the vim apis correctly as well.

I managed to set it up so I'd like to share here for others.

  • I had to create a dedicated .luarc.json file for the action since it needs hardcoded paths. So I placed it into .github/workflows/.luarc.json and mention that with the action argument.
// ./.github/workflows/.luarc.json
{
  "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
  "runtime.version": "LuaJIT",
  "runtime.path": [
    "lua/?.lua",
    "lua/?/init.lua"
  ],
  "workspace.library": [
    "/github/workspace/deps/neodev.nvim/types/stable",
    "${3rd}/busted/library"
  ],
  "diagnostics.libraryFiles": "Disable",
  "workspace.checkThirdParty": "Disable"
}
# ./.github/workflows/lua_ls-typecheck.yml
# you could add `tests` folder at the end but it will raise errors for `describe, it, ...` anyways...
name: lua_ls-typecheck
on:
  pull_request: ~
  push:
    branches:
      - '*'

jobs:
  build:
    name: Type Check Code Base
    runs-on: ubuntu-latest

    steps:
      - name: Checkout Code
        uses: actions/checkout@v3

      - name: Checkout dependency neodev
        uses: actions/checkout@v3
        with:
          repository: "folke/neodev.nvim"
          path: "deps/neodev.nvim"

      - name: Type Check Code Base
        uses: mrcjkb/[email protected]
        with:
          configpath: .github/workflows/.luarc.json
          directories: |
            lua

Read this quote before you do anything if you are following this snippet.

From my experience of introducing style / type / lint / diagnostic checks to whole (non-confirming) database the best way was to add the checker with corresponding check steps in pipeline and simultaneously put every checkable code file into global ignore file (effectively making the check noop) in the first PR and then fix and take out modules/files one by one from ignore file in multiple separate subsequent PRs. This way has almost no friction for finishing and merging existing PRs. If some friction is okay: the first step shouldn't put files into ignore list if they're green initially.

Originally posted by @Anrock in nvim-neorg/neorg#1161 (comment)

EDIT:
Updated .luarc.json. The "${3rd}/busted/library" contains type annotations for describe, it, ... in the busted and luassert library.

@pysan3 pysan3 closed this as completed Nov 13, 2023
@mrcjkb
Copy link
Owner

mrcjkb commented Nov 13, 2023

That's great to hear 🚀

Thanks for sharing your solution!
I'll create a wiki page and post it there.

@pysan3
Copy link
Author

pysan3 commented Nov 13, 2023

Amazing! That'll help a lot of people.

Btw do you know any way to add type notation for describe, it, etc coming from busted?

I wished there was something like neodev for that but unfortunately I couldn't find a solution other than sticking them into diagnostic.global.

@mrcjkb
Copy link
Owner

mrcjkb commented Nov 13, 2023

Btw do you know any way to add type notation for describe, it, etc coming from busted?

I've been trying to get that working with Nix in my plugins. But so far without success 😞.
plenary.nvim provides a subset of the busted/luassert signatures, so you could use that in some cases.

@pysan3
Copy link
Author

pysan3 commented Nov 15, 2023

Btw do you know any way to add type notation for describe, it, etc coming from busted?

I've been trying to get that working with Nix in my plugins. But so far without success 😞. plenary.nvim provides a subset of the busted/luassert signatures, so you could use that in some cases.

I see. I'll look into it but they also don't have much documentation so I don't think it'll be a good reference lol.

@max397574
Copy link

shouldn't that be possible because those types are builtin with luals?
I did this, not sure if it works do

{
  "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
  "runtime.version": "LuaJIT",
  "runtime.path": [
    "lua/?.lua",
    "lua/?/init.lua"
  ],
  "workspace.library": [
    "/github/workspace/deps/neodev.nvim/types/stable",
    "${3rd}/busted/library"
  ],
  "diagnostics.libraryFiles": "Disable",
  "workspace.checkThirdParty": "Disable"
}

@pysan3
Copy link
Author

pysan3 commented Nov 15, 2023

BTW @mrcjkb I added a caution in the above comment: #34 (comment), that might be worth mentioning.

Would you agree to add this comment to the wiki as well?

@pysan3
Copy link
Author

pysan3 commented Nov 15, 2023

shouldn't that be possible because those types are builtin with luals? I did this, not sure if it works do

{
  "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
  "runtime.version": "LuaJIT",
  "runtime.path": [
    "lua/?.lua",
    "lua/?/init.lua"
  ],
  "workspace.library": [
    "/github/workspace/deps/neodev.nvim/types/stable",
    "${3rd}/busted/library"
  ],
  "diagnostics.libraryFiles": "Disable",
  "workspace.checkThirdParty": "Disable"
}

OMG it works!

You are my god!

image

I don't think I heard about this anywhere else or even by googling. You gotta spread your words more lol.

@mrcjkb
Copy link
Owner

mrcjkb commented Nov 15, 2023

BTW @mrcjkb I added a caution in the above comment: #34 (comment), that might be worth mentioning.

Would you agree to add this comment to the wiki as well?

Sure, that sounds reasonable.

@mrcjkb
Copy link
Owner

mrcjkb commented Nov 15, 2023

"${3rd}/busted/library"

Nice! This (and "${3rd}/luassert/library") seems to improve things in my Nix builds, too (it's still complaining about was_not_called and equals, etc, which I thought should be provided by luassert (?).

I just checked the docs. Apparently, setting "workspace.checThirdParty": "true" should automatically apply any third party libraries. But it doesn't seem to be working.

@max397574
Copy link

quite sure that setting would just prompt you to add the library to workspace.library when e.g. starting neovim

@mrcjkb
Copy link
Owner

mrcjkb commented Nov 15, 2023

quite sure that setting would just prompt you to add the library to workspace.library when e.g. starting neovim

Ahh, I'm using the lua-language-server CLI for linting.

@mrcjkb
Copy link
Owner

mrcjkb commented Nov 15, 2023

Looks like 3rd may be deprecated...

@mrcjkb
Copy link
Owner

mrcjkb commented Nov 15, 2023

I was using deprecated luassert APIs. That's why it still wasn't working.

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

No branches or pull requests

3 participants