美文网首页
Nvim LSP sumneko_lua Running in

Nvim LSP sumneko_lua Running in

作者: 夙小叶 | 来源:发表于2022-01-01 09:21 被阅读0次
    2021_12_31_23_06_46.png

    问题

    sumneko_lua 在编辑的时候 LSP 只进入单文件模式,对于 require 导入的文件、函数不进行补全

    配置:

      if server.name == "sumneko_lua" then
        opts = {
          cmd = { "lua-language-server" },
          settings = {
            Lua = {
              runtime = {
                version = 'LuaJIT',
                path = vim.api.nvim_get_option('path')
              },
              diagnostics = {
                globals = { 'vim', 'use' },
              },
              workspace = {
                library = {
                  [vim.fn.expand('$VIMRUNTIME/lua')] = true,
                  [vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true,
                  -- vim.api.nvim_get_runtime_file("", true)
                },
                ignoreDir = { '.git', '.vscode', '.idea', 'site' },
                maxPreload      = 2000,
                preloadFileSize = 2000,
              },
              telemetry = { enable = false, }
            },
          },
          single_file_support = true,
        }
      end
    

    解决

    设置 root_dir,升级为项目(针对 runtime_path 内所有 lua 文件)

    root_dir = require "lspconfig".util.root_pattern('*.lua'),
    
    -- 或者
    root_dir = require "lspconfig".util.root_pattern('init.lua', 'lua'),
    
      if server.name == "sumneko_lua" then
        opts = {
          cmd = { "lua-language-server" },
          root_dir = require "lspconfig".util.root_pattern('init.lua', 'lua'),  -- 设置 root_dir
          settings = {
            Lua = {
              runtime = {
                version = 'LuaJIT',
                path = vim.api.nvim_get_option('path')
              },
              diagnostics = {
                globals = { 'vim', 'use' },
              },
              workspace = {
                library = {
                  [vim.fn.expand('$VIMRUNTIME/lua')] = true,
                  [vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true,
                  -- vim.api.nvim_get_runtime_file("", true)
                },
                ignoreDir = { '.git', '.vscode', '.idea', 'site' },
                maxPreload      = 2000,
                preloadFileSize = 2000,
              },
              telemetry = { enable = false, }
            },
          },
          single_file_support = true,
        }
      end
    

    相关文章

      网友评论

          本文标题:Nvim LSP sumneko_lua Running in

          本文链接:https://www.haomeiwen.com/subject/tqjoqrtx.html