neovim / nvim-lspconfig

Quickstart configs for Nvim LSP
Apache License 2.0
10.75k stars 2.09k forks source link

[lua_ls] throw errors when loading lua file #2953

Closed CoolPlayLin closed 10 months ago

CoolPlayLin commented 10 months ago

Description

When I enter a certain lua file, it throws below error

image

The lua config

lspconfig.lua_ls.setup(
    {
        on_init = function(client)
            local path = client.workspace_folders[1].name
            if not vim.loop.fs_stat(path .. "/.luarc.json") and not vim.loop.fs_stat(path .. "/.luarc.jsonc") then
                client.config.settings =
                    vim.tbl_deep_extend(
                    "force",
                    client.config.settings.Lua,
                    {
                        runtime = {
                            -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
                            version = "LuaJIT"
                        },
                        diagnostics = {
                          globals = { 'vim' }
                        },
                        -- Make the server aware of Neovim runtime files
                        workspace = {
                            library = {vim.env.VIMRUNTIME}
                            -- or pull in all of 'runtimepath'. NOTE: this is a lot slower
                            -- library = vim.api.nvim_get_runtime_file("", true)
                        }
                    }
                )

                client.notify("workspace/didChangeConfiguration", {settings = client.config.settings})
            end
            return true
        end
    }
)

Neovim version

NVIM v0.10.0-dev-1988+g1ef60ea65 Build type: RelWithDebInfo LuaJIT 2.1.1703358377

Nvim-lspconfig version

No response

Operating system and version

Windows11 23H2

Affected language servers

lua_ls

Steps to reproduce

enter a lua file

Actual behavior

No error was thrown

Expected behavior

No response

Minimal config

The config complete config https://github.com/CoolPlayLin/dotfiles/blob/master/nvim/lua/plugins/lsp/lspconfig.lua

LSP log

I don't know where is it

glepnir commented 10 months ago

can't reproduce please try a min config.