diff options
| author | kylo252 <[email protected]> | 2022-09-19 13:10:07 +0200 | 
|---|---|---|
| committer | GitHub <[email protected]> | 2022-09-19 13:10:07 +0200 | 
| commit | 68fdbaa51d658899d4405b2660bfbe360e9dfed4 (patch) | |
| tree | 0c3f4504ddb5a9ea6e46f5c3dba5ec62acce0a10 /lua/lvim/lsp/providers/sumneko_lua.lua | |
| parent | 26d493419af23244fe6ca3daf3477c7b5d95c36e (diff) | |
fix(lsp): enforce lvim completion for lua-server (#3035)
Diffstat (limited to 'lua/lvim/lsp/providers/sumneko_lua.lua')
| -rw-r--r-- | lua/lvim/lsp/providers/sumneko_lua.lua | 55 | 
1 files changed, 38 insertions, 17 deletions
| diff --git a/lua/lvim/lsp/providers/sumneko_lua.lua b/lua/lvim/lsp/providers/sumneko_lua.lua index 6cd78157..ef159e1c 100644 --- a/lua/lvim/lsp/providers/sumneko_lua.lua +++ b/lua/lvim/lsp/providers/sumneko_lua.lua @@ -1,32 +1,53 @@ -local dev_opts = { +local default_workspace = {    library = { -    vimruntime = true, -- runtime path -    types = true, -- full signature, docs and completion of vim.api, vim.treesitter, vim.lsp and others -    -- plugins = true, -- installed opt or start plugins in packpath -    -- you can also specify the list of plugins to make available as a workspace library -    plugins = { "plenary.nvim" }, +    vim.fn.expand "$VIMRUNTIME", +    get_lvim_base_dir(), +    require("lua-dev.sumneko").types(),    }, -  override = nil, -- function(root_dir, options) end, + +  maxPreload = 1000, +  preloadFileSize = 10000,  } -local lua_dev_loaded, lua_dev = pcall(require, "lua-dev") -if lua_dev_loaded then -  lua_dev.setup(dev_opts) +local add_packages_to_workspace = function(packages, config) +  -- config.settings.Lua = config.settings.Lua or { workspace = default_workspace } +  local runtimedirs = vim.api.nvim__get_runtime({ "lua" }, true, { is_lua = true }) +  local workspace = config.settings.Lua.workspace +  for _, v in pairs(runtimedirs) do +    for _, pack in ipairs(packages) do +      if v:match(pack) and not vim.tbl_contains(workspace.library, v) then +        table.insert(workspace.library, v) +      end +    end +  end  end +local lspconfig = require "lspconfig" + +local make_on_new_config = function(on_new_config, _) +  return lspconfig.util.add_hook_before(on_new_config, function(new_config, _) +    local server_name = new_config.name + +    if server_name ~= "sumneko_lua" then +      return +    end +    local plugins = { "plenary.nvim", "telescope.nvim", "nvim-treesitter", "LuaSnip" } +    add_packages_to_workspace(plugins, new_config) +  end) +end + +lspconfig.util.default_config = vim.tbl_extend("force", lspconfig.util.default_config, { +  on_new_config = make_on_new_config(lspconfig.util.default_config.on_new_config), +}) +  local opts = {    settings = {      Lua = { +      telemetry = { enable = false },        diagnostics = {          globals = { "vim", "lvim", "packer_plugins" },        }, -      workspace = { -        library = { -          [require("lvim.utils").join_paths(get_runtime_dir(), "lvim", "lua")] = true, -        }, -        maxPreload = 100000, -        preloadFileSize = 10000, -      }, +      workspace = default_workspace,      },    },  } | 
