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

Using diagnostics.severity setting in .luarc.json seems to break the severity level filtering in generated report #2730

Closed
tomlau10 opened this issue Jun 26, 2024 · 1 comment · Fixed by #2731

Comments

@tomlau10
Copy link
Contributor

tomlau10 commented Jun 26, 2024

How are you using the lua-language-server?

Command Line

Which OS are you using?

MacOS

What is the issue affecting?

Diagnostics/Syntax Checking

Expected Behaviour

I am trying to integrate LuaLS checking into CI so I am testing around with lua-language-server command line. In our codebase there are some functions marked with @deprecated, its default severity is 2 (Warning). We don't want it to be reported so I added the following setting into the .luarc.json:

    "diagnostics.severity": {
        "deprecated": "Information!"
    },

I expected that when running the following command, the report will not contains deprecated (as the severity is downgraded):

${path_to_luals}/bin/lua-language-server --check=.

Actual Behaviour

Out of my expectation, the generated report includes all those redefined-local messages which are of severity level 4 (Hint). 😳 I have tried adding flag --checklevel=Warning but got same result.

With a bit of testing, if I tried to add diagnostics.severity setting (even if an empty table "diagnostics.severity": {}, ), then the generated report will ignore the --checklevel value.
Only if I remove the diagnostics.severity setting, the generated report becomes normal again (only reports Warning or above)

Reproduction steps

  1. prepare a workspace with the following files
  • a.lua
local a
  • .luarc.json
{
    "diagnostics.severity": {},
}
  1. run command line ${path_to_luals}/bin/lua-language-server --check=.
  2. it will output Diagnosis complete, 1 problems found, see ... check.json, and the file content of check.json
{
    "file:///Users/tomlau10/projects/temp/./a.lua": [
        {
            "code": "unused-local",
            "message": "Unused local `a`.",
            "range": {
                "end": {
                    "character": 7,
                    "line": 0
                },
                "start": {
                    "character": 6,
                    "line": 0
                }
            },
            "severity": 4,
            "source": "Lua Diagnostics.",
            "tags": [
                1
            ]
        }
    ]
}
  1. when removing "diagnostics.severity": {}, in .luarc.json, the diagnosis will not found any problem.

Additional Notes

Strange enough, with --checklevel=Error flag then the diagnosis will show no problems found 🤔.

But with either --checklevel=Warning and --checklevel=Information, the report will include these unused-local, which should be at hint level and should not be included.

Log File

No response

@tomlau10
Copy link
Contributor Author

I think I've found the root cause of this 🐛 🎉

The default severity value set by script/cli/check_worker#L86 seems incorrect when the Lua.diagnostics.severity config setting is incomplete.
It should be or serverity instead of or 'Warning', as otherwise any unset diagnostics.severity in the config table will be incorrectly treated as Warning, and thus not added to the disables[].

    for name, serverity in pairs(define.DiagnosticDefaultSeverity) do
        serverity = config.get(rootUri, 'Lua.diagnostics.severity')[name] or 'Warning' --<<< this should be `or serverity`
        if serverity:sub(-1) == '!' then
            serverity = serverity:sub(1, -2)
        end
        if define.DiagnosticSeverity[serverity] > checkLevel then -- the above logic error causing incorrect behavior of this level check
            disables[name] = true
        end

I've tested the change locally and it's working as expected now 🎉
I may soon open a pr for it 😄


ps:
btw the variable name serverity contains a typo, it should be severity 🙂

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 a pull request may close this issue.

1 participant