undefined global 'vim' in lua-language-server - coc.nvim

This snippet gives a warning: local api = vim.api #Undefined global 'vim'

my CocConfig:

`  "languageserver": {
    "lua": {
      "command": "/home/manas/.config/coc/extensions/coc-sumneko-lua-data/sumneko-lua-ls/extension/server/bin/Linux/lua-language-server",
      "args": [
        "-E",
        "/home/manas/.config/coc/extensions/coc-sumneko-lua-data/sumneko-lua-ls/extension/server/main.lua"
      ],
      "filetypes": [
        "lua"
      ],
      "rootPatterns": [
        ".git/"
      ],
      "settings": {
        "Lua": {
          "workspace": {
            "library": {
              "/usr/share/nvim/runtime/lua": true,
              "/usr/share/nvim/runtime/lua/vim": true,
              "/usr/share/nvim/runtime/lua/vim/lsp": true
            },
            "maxPreload": 2000,
            "preloadFileSize": 1000
          },
          "runtime": {
            "version": "5.4.1"
          },
          "diagnostics": {
            "disable": [
              "undefined-global",
              "lowercase-global",
              "unused-local",
              "unused-vararg",
              "trailing-space"
            ],
            "globals": [
              "vim",
              "hs",
              "it",
              "describe",
              "before_each",
              "after_each"
            ]
          }
        }
      }
    }
  }
`

Solution 1:

  1. Follow the process from URL: https://github.com/sumneko/lua-language-server/wiki/Build-and-Run, to install lua-language-server manually.

  2. Startup neovim, enter command: :CocConfig

  3. Edit the file: coc-settings.json

{
  "languageserver": {
    "lua": {
      "command": "/home/alanjui/.local/share/lua-language-server/bin/Linux/lua-language-server",
      "args": [
        "-E",
        "/home/alanjui/.local/share/lua-language-server/bin/Linux/main.lua"
      ],
      "filetypes": ["lua"],
      "settings": {
        "Lua": {
          "workspace.library": {
            "/usr/share/nvim/runtime/lua": true,
            "/usr/share/nvim/runtime/lua/vim": true,
            "/usr/share/nvim/runtime/lua/vim/lsp": true
          },
          "diagnostics": {
            "globals": [ "vim" ]
          }  
        }
      }
    }
  }
}