1

Here is how I start the server:

-- LSP
vim.lsp.start({
  name = 'lua-language-server',
  cmd = { 'lua-language-server' },
  root_dir = vim.fs.dirname(vim.fs.find({'.git', '.vim', 'nvim'}, { upward = true })[1])
})

This is fine. So now I load a lua file in vim, and one that takes advantage of the vim global object that nvim loads somewhere into the lua engine.

My linter doesn't have this library loaded, so it complains about the unset global. My lua code is able to run fine despite these linter warnings, of course.

How can I fix this? How can I straighten out the difference between my TRUE project root (effectively somewhere in nvim?) and my expressed one.


Idk if this helps:

:!lua-language-server --version
3.6.22
1
  • 1
    Another thing I will do is load hs objects when I open a file up in ~/.hammerspoon. I love that I can easily code up this power in my ftplugin file, but DANG I'm struggling Jul 26 at 4:43

1 Answer 1

1

To recognize global objects:

vim.lsp.start({
  name = 'lua-language-server',
  cmd = { 'lua-language-server' },
  root_dir = vim.fs.dirname(vim.fs.find({'.git', '.vim', 'nvim'}, { upward = true })[1]),
  settings = { Lua = { diagnostics = { globals = {'vim'} } } },
})

Alternatively, use a .luarc.json file for workspace configs.

{
    "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
    "diagnostics.globals": ["vim"]
}

See https://github.com/LuaLS/lua-language-server/wiki/Settings for more settings. You might be interested in #workspace library

For vim development, the above suppress warnings. The lsp does not know what's in the vim global. I use neodev plugin for neovim lua development.

You can also look at configurations from lspconfig here and here. I think most people just install the extension, but you should be able to adapt it if you don't want to install it.

3
  • “Most people” citation needed
    – D. Ben Knoble
    Jul 27 at 13:28
  • @D.BenKnoble I guess it's "most people I know / found online". This is the first time I've seen someone setting up LSP without lspconfig, although I do think being able to manually configuring LSP has its benefits.
    – EJam
    Jul 29 at 2:24
  • Still more opinion than fact; I recommend rewording but I won’t plead the case further :)
    – D. Ben Knoble
    Jul 29 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.