lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

Undefined global for builtins

Open ddickstein opened this issue 2 years ago • 13 comments

How are you using the lua-language-server?

NeoVim

Which OS are you using?

Linux

What is the issue affecting?

Diagnostics/Syntax Checking

Expected Behaviour

I think I'm encountering the same issue as https://github.com/sumneko/lua-language-server/issues/1600. In my case it happens sporadically - reloading a lua file in Neovim will often randomly introduce or resolve this behavior.

I'm running version 3.6.4-1 installed from pacman.

Actual Behaviour

Seeing warnings on all builtins as "undefined global"

Reproduction steps

I'm not sure how to reproduce reliably - it seems to happen somewhat randomly when I load the buffer.

Additional Notes

No response

Log File

(I'm time-constrained at the moment but I plan to add this later)

ddickstein avatar Dec 26 '22 22:12 ddickstein

Ditto - I'm seeing the same problem:

MacOS 12.5.1 NVIM v0.8.0 Sumneko 3.6.3

andrewferrier avatar Dec 28 '22 14:12 andrewferrier

Same for me. The problem sometimes disappears when I open certain lua files but it's hard to reproduce consistently.

Ubuntu LTS 22.04 Nvim v0.9.0-dev-47-gcfdb4cbad Sumneko v3.6.4

zenoli avatar Dec 29 '22 10:12 zenoli

Check https://github.com/neovim/nvim-lspconfig/issues/2355

sumneko avatar Jan 03 '23 07:01 sumneko

Nothing really helpful there.

In my case, out of all globals, I'm getting warnings only for the type standard function: Undefined global 'type'

Really weird, I can't tell where is the root of the problem, is it the Language Server, nvim-lspconfig, the neovim lsp implementation, or something else.

caldwell-63 avatar Feb 09 '23 18:02 caldwell-63

Nothing really helpful there.

In my case, out of all globals, I'm getting warnings only for the type standard function: Undefined global 'type'

Really weird, I can't tell where is the root of the problem, is it the Language Server, nvim-lspconfig, the neovim lsp implementation, or something else.

Please open an issue about it.

sumneko avatar Feb 13 '23 07:02 sumneko

I've also had this issue, and for me explicitly extending Lua.workspace.library with one of the meta-directories worked, ie.

nvim_lsp.lua_ls.setup {
    settings = {
        Lua = {
            workspace = {
                library = vim.tbl_extend("keep",
                    -- this will probably vary depending on setup, not sure if plugins like mason even install it.
                    {"/usr/lib/lua-language-server/meta/template"},
                    -- and runtime-directories.
                    vim.api.nvim_get_runtime_file("", true)),
            },
        },
    },
}

(might have undesired consequences, but I haven't found any so far :shrug:)

L3MON4D3 avatar Mar 10 '23 19:03 L3MON4D3

Please try to startup server with parameters --meta=<WRITEABLE_PATH>. Maybe it generated meta files failed.

sumneko avatar Mar 11 '23 09:03 sumneko

Ah, yes you're right :+1: cmd = {sumneko_binary, "--logpath", "/home/simon/.cache/lua-language-server/", "--metapath", "/home/simon/.cache/lua-language-server/meta/"} works perfectly, thank you!

L3MON4D3 avatar Mar 11 '23 11:03 L3MON4D3

I've encountered this when the directory lua-language-server is installed into is not writable by the user. As with the above comment I had to set logpath (or the LS failed to start at all) and metapath (or there would be these undefined global errors).

Perhaps the defaults for logpath and metapath ought to be in a writable directory by default (like $XDG_CONFIG_HOME or $HOME/.cache or on macOS $HOME/Library/Caches?)

benjamineskola avatar Mar 31 '23 09:03 benjamineskola

For me when I use lsp-zero I do not get this error but with the kickstart.nvim default config I do? strange

godalming123 avatar Apr 20 '23 17:04 godalming123

I got same issue in win 11, and fix by this suggession, https://github.com/LuaLS/lua-language-server/issues/1788#issuecomment-1464886248

wsdjeg avatar Jun 19 '23 10:06 wsdjeg

L3MON4D3's comment helped solve this undefined built-ins for me too, but since I'm using vim-lsp-settings, I solved it with this in my vimrc:

call lsp_settings#set('sumneko-lua-language-server', 'args', ["--metapath", expand('~/.vim-cache/lsp/meta')])

idbrii avatar Aug 10 '23 20:08 idbrii

I'm sorry if this is too late, but I would think this is a relevant issue to the problem I'm also seeing:

-- Require the hello-world module
local hello_world = require("hello-world")

-- Define a module named hello-world. This module should return a single
-- function named hello that takes no arguments and returns a string.

describe("hello-world", function()
	it("says hello world", function()
		local result = hello_world.hello()
		assert.are.equal("Hello, World!", result)
	end)
end)

This hello-world_spec.lua gives me warnings for Undefined global 'describe'., Undefined global 'it'. and Undefined field 'are'. while using lua_ls in mason within the LazyVim distro.

I tried setting the command in the lsp config without much success. How can I better investigate the problem? This also happens on some example configs from LazyVim, e.g. the supertab extension gives an Undefined type or alias 'cmp.ConfigSchema'.

massimopavoni avatar Jan 31 '25 21:01 massimopavoni