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

accessing undefined variable 'vim' #2948

Closed
aminnairi opened this issue Dec 23, 2023 · 1 comment
Closed

accessing undefined variable 'vim' #2948

aminnairi opened this issue Dec 23, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@aminnairi
Copy link

aminnairi commented Dec 23, 2023

Description

Documentation for configuring Lua to use Vim does not work as expected.
image

Neovim version

NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1700008891

Nvim-lspconfig version

image

Operating system and version

Archlinux

Affected language servers

lua

Steps to reproduce

  1. Copy the configuration from the server configuration
  2. Reload the Neovim configuration
  3. See the error

Actual behavior

Vim globals are not recognized, and LSP server throws errors when using it. Other plugins such as nvim-cmp do not provide any completion for the vim global.

Expected behavior

Vim global should be recognized, and other plugins such as nvim-cmp should benefit from the LSP completions.

Minimal config

return {
  "neovim/nvim-lspconfig",
  event = "VeryLazy",
  dependencies = {
    "williamboman/mason-lspconfig.nvim",
    "hrsh7th/nvim-cmp",
  },
  config = function()
    local lspconfig = require("lspconfig")
    local capabilities = require("cmp_nvim_lsp").default_capabilities()

    lspconfig.lua_ls.setup({
      capabilities = capabilities,
      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'
              },
              -- Make the server aware of Neovim runtime files
              workspace = {
                checkThirdParty = false,
                library = {
                  vim.env.VIMRUNTIME
                  -- "${3rd}/luv/library"
                  -- "${3rd}/busted/library",
                }
                -- 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
    })
  end,
}

LSP log

None

@aminnairi aminnairi added the bug Something isn't working label Dec 23, 2023
@wookayin
Copy link
Member

wookayin commented Dec 28, 2023

                library = {
-                  vim.env.VIMRUNTIME
+                  vim.env.VIMRUNTIME .. '/lua'
                  -- "${3rd}/luv/library"
                  -- "${3rd}/busted/library",
                }

If you also want to add vim plugins, add them (plugin_paths/lua) into library or use https://github.com/folke/neodev.nvim

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

3 participants