Skip to content

Unable to ignore files for diagnostics #873

Description

@clason

Currently, files that are ignored (either via the ignoreDirs or ignoreGlobs setting) are not parsed at all (which was a deliberate change).

However, this is a problem if your project contains vendored library files that trigger diagnostics -- in this case, you do want these files to be parsed but you simply don't want any diagnostics to be reported, especially with emmylua_check. (Otherwise you'll trigger errors in your files because emmylua doesn't know about the vendored API and types.)

(I also didn't find a (documented) way of marking files as ignored via --- emmylua: ignore comments, but an additional config setting for "parse but don't diagnose" would be more useful.)

Activity

  1. CppCXY commented on Dec 5, 2025

    @CppCXY
    Member

    If it is a file, adding meta will not trigger a diagnosis. If it is a directory added to the library, it will not be diagnosed either. Note that the library is resolved before the workspace, and the library is unaware of the definitions in the main workspace.

  2. clason commented on Dec 5, 2025

    @clason
    ContributorAuthor

    For me, it's a single (non-meta) file vendored inside the main sources (say, lua/foo/vendored.lua if my main module is foo), so adding it to the library will have it processed twice. Unless I'm missing something from your suggestion?

  3. xuhuanzy commented on Dec 5, 2025

    @xuhuanzy
    Member

    ---@meta鸟用没有, meta 应该只过滤一些诊断而不是过滤全部

  4. CppCXY commented on Dec 5, 2025

    @CppCXY
    Member

    Currently the library only supports directories, but we should be able to improve this.

  5. added theissue type on Dec 5, 2025
  6. clason commented on Dec 5, 2025

    @clason
    ContributorAuthor

    Adding ---@meta to the top of the file works, for the record. It would be cleaner not having to touch vendored files at all (especially if there are multiple), though, and this annotation breaks luals (which is an issue when you want or need to migrate incrementally, like I do).

  7. clason commented on Dec 8, 2025

    @clason
    ContributorAuthor

    A related issue around the two different aspects ignoring files is the following: In my (Neovim-based) projects, I download the Neovim runtime (and several other dependencies) to a .test-deps folder. I am then specifying (via an environment variable $VIMRUNTIME) the runtime as a workspace library; at the same time, I do not want to check all the dependencies themselves. So my luarc.json has the following:

      "workspace": {
        "library": [
          "$VIMRUNTIME",
          "${3rd}/busted/library"
        ],
        "ignoreDir": [
          ".test-deps",
          "tests"
        ]
      },

    If $VIMRUNTIME is a subdirectory of .test-deps, this works with luals but doesn't work with emmylua_check. (This could also be solved by simply having library overriding ignoreDir/Glob.)

  8. CppCXY commented on Dec 8, 2025

    @CppCXY
    Member

    A related issue around the two different aspects ignoring files is the following: In my (Neovim-based) projects, I download the Neovim runtime (and several other dependencies) to a .test-deps folder. I am then specifying (via an environment variable $VIMRUNTIME) the runtime as a workspace library; at the same time, I do not want to check all the dependencies themselves. So my luarc.json has the following:

    "workspace": {
    "library": [
    "$VIMRUNTIME",
    "${3rd}/busted/library"
    ],
    "ignoreDir": [
    ".test-deps",
    "tests"
    ]
    },
    If $VIMRUNTIME is a subdirectory of .test-deps, this works with luals but doesn't work with emmylua_check. (This could also be solved by simply having library overriding ignoreDir/Glob.)

    Does that mean ignore doesn't apply to paths added to library?

  9. clason commented on Dec 8, 2025

    @clason
    ContributorAuthor

    Does that mean ignore doesn't apply to paths added to library?

    Yes, that would be my suggestion (and expectation, coming from luals).

  10. CppCXY commented on Dec 8, 2025

    @CppCXY
    Member

    Do you think the include setting should also apply to the lib (library)? There isn't an official interface for that, but you can effectively enable it through the runtime.extensions configuration. Keep in mind that not all Lua source files use the .lua extension — I'll often see names like .lua.txt, .bytes, or plain .txt.

  11. clason commented on Dec 8, 2025

    @clason
    ContributorAuthor

    Good question -- I don't use that setting, so I can't really comment. Generally, I think when the settings are in conflict, a specific path should take precedence over a more general path?

  12. CppCXY commented on Dec 8, 2025

    @CppCXY
    Member

    I've submitted the code; please try it.

  13. clason commented on Dec 8, 2025

    @clason
    ContributorAuthor

    Yes, works fine now, thank you!

  14. aurora0x27 commented on Dec 29, 2025

    @aurora0x27

    Now the ignoreGlobs is only used on current workspace filter, but it will cause problems when I add plugin cache (default ~/.local/share/nvim/lazy). As the filter no longer filter files, nvim-higlight-colors/lua/color/nvim-higlight-colors/buffer_utils_spec.lua is parsed. Mock test will override vim.fn and cause incorrect warnings on calling vim.fn.foo. When perform goto definition action on vim.fn, it will be navigated to this position.

    file pos

    -- Needed to mock vim calls
    _G.vim = _G.vim or { api = function() end, fn = function() return {} end }
    Image

    This **/*_spec.lua file was supposed to be filtered before this patch.

    My configuration:

        {
          "$schema": "https://raw.githubusercontent.com/EmmyLuaLs/emmylua-analyzer-rust/refs/heads/main/crates/emmylua_code_analysis/resources/schema.json",
          "runtime": {
            "version": "LuaJIT",
            "requirePattern": [
              "lua/?.lua",
              "lua/?/init.lua",
              "?/lua/?.lua",
              "?/lua/?/init.lua"
            ]
          },
          "workspace": {
            "library": [
              "$VIMRUNTIME",
              "$LLS_Addons/luvit",
            ],
            "ignoreGlobs": ["**/*_spec.lua" ]
          },
          "codeAction": {
            "insertSpace": true
          },
          "strict": {
            "typeCall": true,
            "arrayIndex": true
          }
        }
    
  15. CppCXY commented on Dec 29, 2025

    @CppCXY
    Member

    I think the reason is that Lua doesn't provide enough conventions for me to follow; to fix this, we need to support a multi-lib configuration system that allows each library's .luarc to take effect independently.

  16. lxymahatma commented on Dec 29, 2025

    @lxymahatma

    I think the reason is that Lua doesn't provide enough conventions for me to follow; to fix this, we need to support a multi-lib configuration system that allows each library's .luarc to take effect independently.

    But actually many nvim plugins do not follow the standard .luarc.json convention (eg, nvim-highlight-colors), so just directly reading from each library's .luarc might have some issues
    I guess the most robust solution is to handle this directly within the .emmyrc.json.
    Either something like

    "workspace": {
      "library": [],
      "libraryIgnoreGlobs": [],
      "workspaceIgnoreGlobs":[]
    },

    for entire library imports or like more detailed

    "workspace": {
      "library": [
        "$VIMRUNTIME",
        {
          "root": "/path/to/somelib",
          "ignoreGlob": ["**/*_spec.lua"]
        },
        {
          "root": "/path/to/anotherlib",
        }
      ],
    },
  17. clason commented on Dec 29, 2025

    @clason
    ContributorAuthor

    A simpler (but harder to document) fix could be to have only ignoreDirs being ignored for library paths (since they're both "dirs"), while ignoreGlobs still applying to library?

    But actually many nvim plugins do not follow the standard .luarc.json convention (eg, nvim-highlight-colors)

    Yes, but they should. So why not open an issue about (or even better, a PR) adding one?

  18. lxymahatma commented on Dec 29, 2025

    @lxymahatma

    Yes, but they should. So why not open an issue about (or even better, a PR) adding one?

    While I agree that they should put a .luarc.json in their repo, but because it's not forced behavior, I guess some plugin authors might not want to put it into their repo or like maybe that repo is rarely maintained and they just accept critical prs? Also, there are a lot of plugins that I used don't have this file in their repo, so it's kinda a big task to find them all and pr them one by one. Moreover, I think most people just let nvim plugins managed by the plugin managers and these plugins should be treated as immutable/read-only dependencies. Well, at least imo it's better that there's a way to configure how these libraries are indexed locally without modifying the upstream source or maintaining forks. But still these are just my personal thoughts. I'm new to lua and nvim, so I don't know if this is exactly what everyone else needs, maybe we can propose a better solution with more people discuss about this

  19. CppCXY commented on Jan 26, 2026

    @CppCXY
    Member

    I have update the workspace.library config, it can config like:

    {
        "workspace.library": [
            {
                "path": "rx",
                "ignoreGlobs": [
                    "*.lua.txt"
                ]
            },
            "$VIMRUNITME",
            "XXX/to/file.lua"
        ]
    }

    It can also be configured directly as a specific file; in that case the module name is the filename, and it can be mixed with the traditional plain-string configuration.

    see: faf2233

  20. clason commented on Mar 6, 2026

    @clason
    ContributorAuthor

    @CppCXY Can it be that something has regressed in the new release? My setup

      "workspace": {
        "library": [
          "$VIMRUNTIME",
          "${3rd}/busted/library"
        ],
        "ignoreDir": [
          ".test-deps",
          "tests"
        ]
      },

    no longer finds the $VIMRUNTIME as a subdirectory of .test-deps, which I tested in January and it worked. Do I need to adapt the config?

  21. clason commented on Mar 6, 2026

    @clason
    ContributorAuthor

    Yes, regression bisected to faf2233 (Sorry for not immediately testing that!)

    Just to make clear: My main issue here is the opposite than what is handled in that commit: I have a library directory inside an ignoreDir, not some files/directories inside a library I want to ignore!

  22. xuhuanzy commented on Jun 19, 2026

    @xuhuanzy
    Member

    close?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions