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

Diagnosis report contains more diagnostics than VSCode #1955

Closed
ghost opened this issue Feb 28, 2023 · 0 comments
Closed

Diagnosis report contains more diagnostics than VSCode #1955

ghost opened this issue Feb 28, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented Feb 28, 2023

How are you using the lua-language-server?

Command Line

Which OS are you using?

Windows

What is the issue affecting?

Diagnostics/Syntax Checking

Expected Behaviour

For the same code and configuration, the diagnostics reported by the CLI match the diagnostics in VSCode.

Actual Behaviour

For the same code and configuration, the diagnostics reported by the CLI deviate from the diagnostics in VSCode.

Reproduction steps

  1. Create a workspace directory with some Lua files. In my example, I use two files B.lua and R.lua. The content of B.lua is:
A = {}
A.B = {}

function A.f()
end

function A.B.g()
end

local function test()
    m = require('R')
    m.s()
    G = 5 + 5
    G = math.abs(G) + math.acos()
end

The content of R.lua is:

local function s()
end

return { s }
  1. Open the workspace in VSCode and change some diagnostics levels in the settings. I changed the groupSeverity of global to Error and the severity of missing-parameter to Error. VSCode shows the diagnostics as expected:
    br-dreport
  2. Execute the check command with the CLI. I executed the command C:\Users\<user name>\.vscode\extensions\sumneko.lua-3.6.11-win32-x64\server\bin\lua-language-server.exe --loglevel debug --logpath log --metapath meta --configpath C:\Development\git-repos\bug-report\diagnosis-report\settings.json --check C:\Development\git-repos\bug-report\diagnosis-report\library --checklevel Hint (the current working directory is set to C:\Development\git-repos\bug-report\diagnosis-report) with the following settings file content:
{
    "file:///c%3A/Development/git-repos/bug-report/diagnosis-report/library/B.lua": [
        {
            "code": "undefined-global",
            "message": "Undefined global `A`.",
            "range": {
                "end": {
                    "character": 1,
                    "line": 1
                },
                "start": {
                    "character": 0,
                    "line": 1
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "undefined-global",
            "message": "Undefined global `A`.",
            "range": {
                "end": {
                    "character": 10,
                    "line": 3
                },
                "start": {
                    "character": 9,
                    "line": 3
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "undefined-global",
            "message": "Undefined global `A`.",
            "range": {
                "end": {
                    "character": 10,
                    "line": 6
                },
                "start": {
                    "character": 9,
                    "line": 6
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "undefined-global",
            "message": "Undefined global `m`.",
            "range": {
                "end": {
                    "character": 5,
                    "line": 11
                },
                "start": {
                    "character": 4,
                    "line": 11
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "undefined-global",
            "message": "Undefined global `require`.(You can treat `require` as `require` by setting.)",
            "range": {
                "end": {
                    "character": 15,
                    "line": 10
                },
                "start": {
                    "character": 8,
                    "line": 10
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "undefined-global",
            "message": "Undefined global `math`.",
            "range": {
                "end": {
                    "character": 12,
                    "line": 13
                },
                "start": {
                    "character": 8,
                    "line": 13
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "undefined-global",
            "message": "Undefined global `G`.",
            "range": {
                "end": {
                    "character": 18,
                    "line": 13
                },
                "start": {
                    "character": 17,
                    "line": 13
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "undefined-global",
            "message": "Undefined global `math`.",
            "range": {
                "end": {
                    "character": 26,
                    "line": 13
                },
                "start": {
                    "character": 22,
                    "line": 13
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "unused-function",
            "message": "Unused functions.",
            "range": {
                "end": {
                    "character": 14,
                    "line": 9
                },
                "start": {
                    "character": 6,
                    "line": 9
                }
            },
            "severity": 4,
            "source": "Lua Diagnostics.",
            "tags": [
                1
            ]
        },
        {
            "code": "unused-local",
            "message": "Unused local `test`.",
            "range": {
                "end": {
                    "character": 19,
                    "line": 9
                },
                "start": {
                    "character": 15,
                    "line": 9
                }
            },
            "severity": 4,
            "source": "Lua Diagnostics.",
            "tags": [
                1
            ]
        },
        {
            "code": "lowercase-global",
            "message": "Global variable in lowercase initial, Did you miss `local` or misspell it?",
            "range": {
                "end": {
                    "character": 5,
                    "line": 10
                },
                "start": {
                    "character": 4,
                    "line": 10
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        }
    ]
}

It is confusing that undefined globals are reported.
6. More confusingly, if I comment line 11 in B.lua (m = require('R')) out and execute the check command again, 99 problems are reported. Here is an incomplete list of the problems:

{
    "file:///c%3A/Development/git-repos/bug-report/diagnosis-report/library/B.lua": [
        {
            "code": "undefined-global",
            "message": "Undefined global `A`.",
            "range": {
                "end": {
                    "character": 1,
                    "line": 1
                },
                "start": {
                    "character": 0,
                    "line": 1
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "undefined-global",
            "message": "Undefined global `A`.",
            "range": {
                "end": {
                    "character": 10,
                    "line": 3
                },
                "start": {
                    "character": 9,
                    "line": 3
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "undefined-global",
            "message": "Undefined global `A`.",
            "range": {
                "end": {
                    "character": 10,
                    "line": 6
                },
                "start": {
                    "character": 9,
                    "line": 6
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "undefined-global",
            "message": "Undefined global `m`.",
            "range": {
                "end": {
                    "character": 5,
                    "line": 11
                },
                "start": {
                    "character": 4,
                    "line": 11
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "undefined-global",
            "message": "Undefined global `math`.",
            "range": {
                "end": {
                    "character": 12,
                    "line": 13
                },
                "start": {
                    "character": 8,
                    "line": 13
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "undefined-global",
            "message": "Undefined global `G`.",
            "range": {
                "end": {
                    "character": 18,
                    "line": 13
                },
                "start": {
                    "character": 17,
                    "line": 13
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "undefined-global",
            "message": "Undefined global `math`.",
            "range": {
                "end": {
                    "character": 26,
                    "line": 13
                },
                "start": {
                    "character": 22,
                    "line": 13
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "unused-function",
            "message": "Unused functions.",
            "range": {
                "end": {
                    "character": 14,
                    "line": 9
                },
                "start": {
                    "character": 6,
                    "line": 9
                }
            },
            "severity": 4,
            "source": "Lua Diagnostics.",
            "tags": [
                1
            ]
        },
        {
            "code": "unused-local",
            "message": "Unused local `test`.",
            "range": {
                "end": {
                    "character": 19,
                    "line": 9
                },
                "start": {
                    "character": 15,
                    "line": 9
                }
            },
            "severity": 4,
            "source": "Lua Diagnostics.",
            "tags": [
                1
            ]
        },
        {
            "code": "undefined-global",
            "message": "Undefined global `A`.",
            "range": {
                "end": {
                    "character": 1,
                    "line": 1
                },
                "start": {
                    "character": 0,
                    "line": 1
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "undefined-global",
            "message": "Undefined global `A`.",
            "range": {
                "end": {
                    "character": 10,
                    "line": 3
                },
                "start": {
                    "character": 9,
                    "line": 3
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "undefined-global",
            "message": "Undefined global `A`.",
            "range": {
                "end": {
                    "character": 10,
                    "line": 6
                },
                "start": {
                    "character": 9,
                    "line": 6
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "undefined-global",
            "message": "Undefined global `m`.",
            "range": {
                "end": {
                    "character": 5,
                    "line": 11
                },
                "start": {
                    "character": 4,
                    "line": 11
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "undefined-global",
            "message": "Undefined global `math`.",
            "range": {
                "end": {
                    "character": 12,
                    "line": 13
                },
                "start": {
                    "character": 8,
                    "line": 13
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "undefined-global",
            "message": "Undefined global `G`.",
            "range": {
                "end": {
                    "character": 18,
                    "line": 13
                },
                "start": {
                    "character": 17,
                    "line": 13
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        },
        {
            "code": "undefined-global",
            "message": "Undefined global `math`.",
            "range": {
                "end": {
                    "character": 26,
                    "line": 13
                },
                "start": {
                    "character": 22,
                    "line": 13
                }
            },
            "severity": 1,
            "source": "Lua Diagnostics."
        }
    ],
    "file:///c%3A/Development/git-repos/bug-report/diagnosis-report/meta/Lua%205.4%20en-us%20utf8/basic.lua": [
        <further diagnostics>
    ],
    "file:///c%3A/Development/git-repos/bug-report/diagnosis-report/meta/Lua%205.4%20en-us%20utf8/builtin.lua": [
        {
            "code": "undefined-doc-class",
            "message": "Undefined class `stringlib`.",
            "range": {
                "end": {
                    "character": 27,
                    "line": 12
                },
                "start": {
                    "character": 18,
                    "line": 12
                }
            },
            "relatedInformation": [],
            "severity": 2,
            "source": "Lua Diagnostics."
        }
    ]
}

Additional Notes

I am not sure if I am using the CLI correctly. I oriented me on the wiki page about the diagnosis report and CLI flags. So, if this is not a bug, I am sorry and you can close this issue.

Log File

This is the log file for the first run:
file_c%3A_Development_git-repos_bug-report_diagnosis-report_library.log
This is the log file for the second run (with line 11 commented out):
file_c%3A_Development_git-repos_bug-report_diagnosis-report_library.log

@sumneko sumneko added the bug Something isn't working label Mar 3, 2023
@sumneko sumneko closed this as completed in cac06e5 Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant