lua-language-server 中未定义的全局“vim”-coc.nvim

lua-language-server 中未定义的全局“vim”-coc.nvim

此代码片段给出警告: local api = vim.api #Undefined global 'vim'

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

答案1

  1. 请按照以下 URL 中的说明进行操作:https://github.com/sumneko/lua-language-server/wiki/Build-and-Run,手动安装lua-language-server

  2. 启动neovim,输入命令::CocConfig

  3. 编辑文件: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

一切coc-lua需求尽"Lua.diagnostics.globals": ["vim"]在你的掌握之中coc-settings.json

答案3

  1. 安装coc-sumneko-lua

  2. 将以下行添加到您的coc-setting.json

    "sumneko-lua.enableNvimLuaDev": true,
    

答案4

实际上 lua lsp 本身已经明确解释了文档在这里

  1. 您可以通过运行来安装 coc-lua:CocInstall coc-lua
  2. 通过运行打开 coc-settings:CocConfig
  3. 如上面链接的文档所述,只需添加以下内容
    -> “Lua.runtime.version”:“LuaJIT”
    ->
    "Lua.workspace.library":[
        "<value of $VIMRUNTIME variable>"
     (you can just do <c-r>=$VIMRUNTIME to insert it there)
    ]
  1. 毕竟只需做一个:CocRestart就可以了

相关内容