1

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"
            ]
          }
        }
      }
    }
  }
`

4 Answers 4

2
  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" ]
          }  
        }
      }
    }
  }
}
2

All coc-lua needs is a "Lua.diagnostics.globals": ["vim"] in your coc-settings.json.

1
2
  1. Install coc-sumneko-lua.

  2. Add the following line to your coc-setting.json.

    "sumneko-lua.enableNvimLuaDev": true,
    
1
  • 2
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Feb 21, 2022 at 9:04
0

actually lua lsp itself has clearly explains what to do in the docs here.

  1. You install coc-lua by running :CocInstall coc-lua
  2. open coc-settings by running :CocConfig
  3. as stated in the linked docs above just add the following
    -> "Lua.runtime.version":"LuaJIT"
    ->
    "Lua.workspace.library":[
        "<value of $VIMRUNTIME variable>"
     (you can just do <c-r>=$VIMRUNTIME to insert it there)
    ]
  1. after all just do a :CocRestart and you are good to go

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .