How to suppress warning: undefined global `vim`?

As title.

Is that luacheck or sumnekko_lua or somehting else?

Yes, exactly. it’s sumnekko installed from a plug-in called nvim-lsp-installer. I want to do this because it triggers so many same warnings and looks ugly.

Pretty much what’s listed in the lspconfig docs: nvim-lspconfig/server_configurations.md at master · neovim/nvim-lspconfig · GitHub

But you just need to include vim within it’s diagnostics.global key settings:

require'lspconfig'.sumneko_lua.setup {
  settings = {
    Lua = {
      diagnostics = {
        -- Get the language server to recognize the `vim` global
        globals = {'vim'},
      },
    },
  },
}
2 Likes

Are these the default settings? it doesn’t work by default in my case. Now my issue become: where should I put this line? This is my current settings:

use {
  'neovim/nvim-lspconfig',
  config = function ()
    vim.diagnostic.config({
      virtual_text = false,
      signs = true,
      underline = true,
      update_in_insert = true
    })
  end
}

Nevermind, I’m using williamboman/nvim-lsp-installer, and the config that works is:

  use {
    -- WARNING: this plugin doesn't provide server update.
    'williamboman/nvim-lsp-installer',
    requires = {
      'neovim/nvim-lspconfig',
      'hrsh7th/nvim-cmp',
    },
    config = function()
      local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
      local on_attach = require'config.on_attach'
      require('nvim-lsp-installer').on_server_ready(
        function(server)
          local config = {
            on_attach = on_attach[server.name],
            capabilities = capabilities,
            autostart = true,
            settings = {
              Lua = {
                diagnostics = { globals = {'vim'} }
              }
            }
          }
          server:setup(config)
        end
      )
    end
  }