summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/lvim/bootstrap.lua2
-rw-r--r--lua/lvim/config/init.lua4
-rw-r--r--lua/lvim/core/autocmds.lua5
-rw-r--r--lua/lvim/core/commands.lua2
-rw-r--r--lua/lvim/core/info.lua4
-rw-r--r--lua/lvim/core/which-key.lua4
-rw-r--r--lua/lvim/lsp/config.lua5
-rw-r--r--lua/lvim/lsp/manager.lua43
-rw-r--r--lua/lvim/lsp/utils.lua17
-rw-r--r--lua/lvim/plugin-loader.lua58
-rw-r--r--lua/lvim/utils/ft.lua47
-rw-r--r--lua/lvim/utils/hooks.lua3
12 files changed, 89 insertions, 105 deletions
diff --git a/lua/lvim/bootstrap.lua b/lua/lvim/bootstrap.lua
index e17c79db..74a9bf45 100644
--- a/lua/lvim/bootstrap.lua
+++ b/lua/lvim/bootstrap.lua
@@ -87,7 +87,7 @@ function M:init(base_dir)
require("lvim.config"):init()
- require("lvim.plugin-loader"):init {
+ require("lvim.plugin-loader").init {
package_root = self.pack_dir,
install_path = self.packer_install_dir,
}
diff --git a/lua/lvim/config/init.lua b/lua/lvim/config/init.lua
index e89cb260..1256e236 100644
--- a/lua/lvim/config/init.lua
+++ b/lua/lvim/config/init.lua
@@ -102,8 +102,8 @@ function M:reload()
local plugins = require "lvim.plugins"
utils.toggle_autoformat()
local plugin_loader = require "lvim.plugin-loader"
- plugin_loader:cache_reset()
- plugin_loader:load { plugins, lvim.plugins }
+ plugin_loader.cache_clear()
+ plugin_loader.load { plugins, lvim.plugins }
vim.cmd ":PackerInstall"
vim.cmd ":PackerCompile"
-- vim.cmd ":PackerClean"
diff --git a/lua/lvim/core/autocmds.lua b/lua/lvim/core/autocmds.lua
index 5d1d365e..569622be 100644
--- a/lua/lvim/core/autocmds.lua
+++ b/lua/lvim/core/autocmds.lua
@@ -6,11 +6,6 @@ function M.load_augroups()
return {
_general_settings = {
- {
- "Filetype",
- "*",
- "lua require('lvim.utils.ft').do_filetype(vim.fn.expand(\"<amatch>\"))",
- },
{ "FileType", "qf,help,man", "nnoremap <silent> <buffer> q :close<CR>" },
{
"TextYankPost",
diff --git a/lua/lvim/core/commands.lua b/lua/lvim/core/commands.lua
index b750f12b..61148889 100644
--- a/lua/lvim/core/commands.lua
+++ b/lua/lvim/core/commands.lua
@@ -14,6 +14,8 @@ M.defaults = {
[[ command! LvimInfo lua require('lvim.core.info').toggle_popup(vim.bo.filetype) ]],
[[ command! LvimCacheReset lua require('lvim.utils.hooks').reset_cache() ]],
[[ command! LvimUpdate lua require('lvim.bootstrap').update() ]],
+ [[ command! LvimSyncCorePlugins lua require('lvim.plugin-loader'):sync_core_plugins() ]],
+ [[ command! LvimReload lua require('lvim.config'):reload() ]],
}
M.load = function(commands)
diff --git a/lua/lvim/core/info.lua b/lua/lvim/core/info.lua
index 5707cc30..fc87691e 100644
--- a/lua/lvim/core/info.lua
+++ b/lua/lvim/core/info.lua
@@ -61,11 +61,13 @@ local function make_client_info(client)
local client_enabled_caps = lsp_utils.get_client_capabilities(client.id)
local name = client.name
local id = client.id
+ local filetypes = lsp_utils.get_supported_filetypes(name)
local document_formatting = client.resolved_capabilities.document_formatting
local attached_buffers_list = table.concat(vim.lsp.get_buffers_by_client_id(client.id), ", ")
local client_info = {
fmt("* Name: %s", name),
fmt("* Id: [%s]", tostring(id)),
+ fmt("* filetype(s): [%s]", table.concat(filetypes, ", ")),
fmt("* Attached buffers: [%s]", tostring(attached_buffers_list)),
fmt("* Supports formatting: %s", tostring(document_formatting)),
}
@@ -106,7 +108,7 @@ function M.toggle_popup(ft)
local lsp_info = {
"Language Server Protocol (LSP) info",
- fmt "* Associated server(s):",
+ fmt "* Active server(s):",
}
for _, client in pairs(clients) do
diff --git a/lua/lvim/core/which-key.lua b/lua/lvim/core/which-key.lua
index 42e37456..b036e376 100644
--- a/lua/lvim/core/which-key.lua
+++ b/lua/lvim/core/which-key.lua
@@ -98,7 +98,7 @@ M.config = function()
name = "Packer",
c = { "<cmd>PackerCompile<cr>", "Compile" },
i = { "<cmd>PackerInstall<cr>", "Install" },
- r = { "<cmd>lua require('lvim.utils').reload_lv_config()<cr>", "Reload" },
+ r = { "<cmd>lua require('lvim.plugin-loader').recompile()<cr>", "Re-compile" },
s = { "<cmd>PackerSync<cr>", "Sync" },
S = { "<cmd>PackerStatus<cr>", "Status" },
u = { "<cmd>PackerUpdate<cr>", "Update" },
@@ -220,7 +220,7 @@ M.config = function()
},
P = { "<cmd>exe 'edit '.stdpath('cache').'/packer.nvim.log'<cr>", "Open the Packer logfile" },
},
- r = { "<cmd>lua require('lvim.utils').reload_lv_config()<cr>", "Reload configurations" },
+ r = { "<cmd>LvimReload<cr>", "Reload LunarVim's configuration" },
u = { "<cmd>LvimUpdate<cr>", "Update LunarVim" },
},
s = {
diff --git a/lua/lvim/lsp/config.lua b/lua/lvim/lsp/config.lua
index 2d9104ea..ccc524ee 100644
--- a/lua/lvim/lsp/config.lua
+++ b/lua/lvim/lsp/config.lua
@@ -46,15 +46,20 @@ return {
"ansiblels",
"denols",
"ember",
+ "emmet_ls",
"eslint",
"eslintls",
+ "graphql",
"jedi_language_server",
+ "ltex",
+ "phpactor",
"pylsp",
"rome",
"sqlls",
"sqls",
"stylelint_lsp",
"tailwindcss",
+ "tflint",
"volar",
},
}
diff --git a/lua/lvim/lsp/manager.lua b/lua/lvim/lsp/manager.lua
index a8544803..dbb7b87f 100644
--- a/lua/lvim/lsp/manager.lua
+++ b/lua/lvim/lsp/manager.lua
@@ -39,6 +39,12 @@ local function resolve_config(name, user_config)
return config
end
+-- manually start the server and don't wait for the usual filetype trigger from lspconfig
+local function buf_try_add(server_name, bufnr)
+ bufnr = bufnr or vim.api.nvim_get_current_buf()
+ require("lspconfig")[server_name].manager.try_add_wrapper(bufnr)
+end
+
---Setup a language server by providing a name
---@param server_name string name of the language server
---@param user_config table [optional] when available it will take predence over any default configurations
@@ -48,32 +54,37 @@ function M.setup(server_name, user_config)
if lvim_lsp_utils.is_client_active(server_name) then
return
end
+ local servers = require "nvim-lsp-installer.servers"
local config = resolve_config(server_name, user_config)
- local server_available, requested_server = require("nvim-lsp-installer.servers").get_server(server_name)
+ local server_available, requested_server = servers.get_server(server_name)
- local function ensure_installed(server)
- if server:is_installed() then
- return true
- end
- if not lvim.lsp.automatic_servers_installation then
- Log:debug(server.name .. " is not managed by the automatic installer")
- return false
+ if server_available then
+ local install_notification = false
+
+ if not requested_server:is_installed() then
+ if lvim.lsp.automatic_servers_installation then
+ Log:debug "Automatic server installation detected"
+ requested_server:install()
+ install_notification = true
+ else
+ Log:debug(requested_server.name .. " is not managed by the automatic installer")
+ end
end
- Log:debug(string.format("Installing [%s]", server.name))
- server:install()
- vim.schedule(function()
- vim.cmd [[LspStart]]
- end)
- end
- if server_available and ensure_installed(requested_server) then
- requested_server:setup(config)
+ requested_server:on_ready(function()
+ if install_notification then
+ vim.notify(string.format("Installation complete for [%s] server", requested_server.name), vim.log.levels.INFO)
+ end
+ install_notification = false
+ requested_server:setup(config)
+ end)
else
-- since it may not be installed, don't attempt to configure the LSP unless there is a custom provider
local has_custom_provider, _ = pcall(require, "lvim/lsp/providers/" .. server_name)
if has_custom_provider then
require("lspconfig")[server_name].setup(config)
+ buf_try_add(server_name)
end
end
end
diff --git a/lua/lvim/lsp/utils.lua b/lua/lvim/lsp/utils.lua
index a34fbf44..7cc8f54f 100644
--- a/lua/lvim/lsp/utils.lua
+++ b/lua/lvim/lsp/utils.lua
@@ -49,14 +49,17 @@ function M.get_client_capabilities(client_id)
end
function M.get_supported_filetypes(server_name)
- -- print("got filetypes query request for: " .. server_name)
- local configs = require "lspconfig/configs"
- pcall(require, ("lspconfig/" .. server_name))
- for _, config in pairs(configs) do
- if config.name == server_name then
- return config.document_config.default_config.filetypes or {}
- end
+ -- temporary workaround: https://github.com/neovim/nvim-lspconfig/pull/1358
+ if server_name == "dockerls" then
+ return { "dockerfile" }
+ end
+ local lsp_installer_servers = require "nvim-lsp-installer.servers"
+ local server_available, requested_server = lsp_installer_servers.get_server(server_name)
+ if not server_available then
+ return {}
end
+
+ return requested_server:get_supported_filetypes()
end
return M
diff --git a/lua/lvim/plugin-loader.lua b/lua/lvim/plugin-loader.lua
index e1ede7bc..c4bd7373 100644
--- a/lua/lvim/plugin-loader.lua
+++ b/lua/lvim/plugin-loader.lua
@@ -5,7 +5,9 @@ local Log = require "lvim.core.log"
-- we need to reuse this outside of init()
local compile_path = get_config_dir() .. "/plugin/packer_compiled.lua"
-function plugin_loader:init(opts)
+local _, packer = pcall(require, "packer")
+
+function plugin_loader.init(opts)
opts = opts or {}
local install_path = opts.install_path or vim.fn.stdpath "data" .. "/site/pack/packer/start/packer.nvim"
@@ -16,14 +18,10 @@ function plugin_loader:init(opts)
vim.cmd "packadd packer.nvim"
end
- local packer_ok, packer = pcall(require, "packer")
- if not packer_ok then
- return
- end
-
packer.init {
package_root = package_root,
compile_path = compile_path,
+ log = { level = "warn" },
git = { clone_timeout = 300 },
display = {
open_fn = function()
@@ -31,36 +29,51 @@ function plugin_loader:init(opts)
end,
},
}
+end
- self.packer = packer
- return self
+-- packer expects a space separated list
+local function pcall_packer_command(cmd, kwargs)
+ local status_ok, msg = pcall(function()
+ require("packer")[cmd](unpack(kwargs or {}))
+ end)
+ if not status_ok then
+ Log:warn(cmd .. " failed with: " .. vim.inspect(msg))
+ Log:trace(vim.inspect(vim.fn.eval "v:errmsg"))
+ end
end
-function plugin_loader:cache_clear()
+function plugin_loader.cache_clear()
if vim.fn.delete(compile_path) == 0 then
Log:debug "deleted packer_compiled.lua"
end
end
-function plugin_loader:cache_reset()
- self.cache_clear()
- require("packer").compile()
+function plugin_loader.recompile()
+ plugin_loader.cache_clear()
+ pcall_packer_command "compile"
if utils.is_file(compile_path) then
Log:debug "generated packer_compiled.lua"
end
end
-function plugin_loader:load(configurations)
- return self.packer.startup(function(use)
- for _, plugins in ipairs(configurations) do
- for _, plugin in ipairs(plugins) do
- use(plugin)
+function plugin_loader.load(configurations)
+ Log:debug "loading plugins configuration"
+ local status_ok, _ = xpcall(function()
+ packer.startup(function(use)
+ for _, plugins in ipairs(configurations) do
+ for _, plugin in ipairs(plugins) do
+ use(plugin)
+ end
end
- end
- end)
+ end)
+ end, debug.traceback)
+ if not status_ok then
+ Log:warn "problems detected while loading plugins' configurations"
+ Log:trace(debug.traceback())
+ end
end
-function plugin_loader:get_core_plugins()
+function plugin_loader.get_core_plugins()
local list = {}
local plugins = require "lvim.plugins"
for _, item in pairs(plugins) do
@@ -69,9 +82,10 @@ function plugin_loader:get_core_plugins()
return list
end
-function plugin_loader:sync_core_plugins()
+function plugin_loader.sync_core_plugins()
local core_plugins = plugin_loader.get_core_plugins()
- vim.cmd("PackerSync " .. unpack(core_plugins))
+ Log:trace(string.format("Syncing core plugins: [%q]", table.concat(core_plugins, ", ")))
+ pcall_packer_command("sync", core_plugins)
end
return plugin_loader
diff --git a/lua/lvim/utils/ft.lua b/lua/lvim/utils/ft.lua
deleted file mode 100644
index e9852e6f..00000000
--- a/lua/lvim/utils/ft.lua
+++ /dev/null
@@ -1,47 +0,0 @@
--- Here be dragons
--- Opening files with telescope will not start LSP without this
-local ft = {}
-
-ft.find_lua_ftplugins = function(filetype)
- local patterns = {
- string.format("ftplugin/%s.lua", filetype),
-
- -- Looks like we don't need this, because the first one works
- -- string.format("after/ftplugin/%s.lua", filetype),
- }
-
- local result = {}
- for _, pat in ipairs(patterns) do
- vim.list_extend(result, vim.api.nvim_get_runtime_file(pat, true))
- end
-
- return result
-end
-
-ft.do_filetype = function(filetype)
- local ftplugins = ft.find_lua_ftplugins(filetype)
-
- local f_env = setmetatable({
- -- Override print, so the prints still go through, otherwise it's confusing for people
- print = vim.schedule_wrap(print),
- }, {
- -- Buf default back read/write to whatever is going on in the global landscape
- __index = _G,
- __newindex = _G,
- })
-
- for _, file in ipairs(ftplugins) do
- local f = loadfile(file)
- if not f then
- vim.api.nvim_err_writeln("Unable to load file: " .. file)
- else
- local ok, msg = pcall(setfenv(f, f_env))
-
- if not ok then
- vim.api.nvim_err_writeln("Error while processing file: " .. file .. "\n" .. msg)
- end
- end
- end
-end
-
-return ft
diff --git a/lua/lvim/utils/hooks.lua b/lua/lvim/utils/hooks.lua
index cc884523..0fe4a7fd 100644
--- a/lua/lvim/utils/hooks.lua
+++ b/lua/lvim/utils/hooks.lua
@@ -15,8 +15,7 @@ end
---Tip: Useful for clearing any outdated settings
function M.reset_cache()
_G.__luacache.clear_cache()
-
- plugin_loader:cache_reset()
+ require("lvim.plugin-loader").recompile()
package.loaded["lvim.lsp.templates"] = nil
Log:debug "Re-generatring ftplugin template files"