From 29fbaa1522c339b3c157bb94d923f70c1df5c178 Mon Sep 17 00:00:00 2001 From: Shadow Cat Date: Thu, 4 Aug 2022 16:44:09 -0400 Subject: [PATCH] fixed plugin require lsp integration and made reloading safer and more clean --- lua/config/neovide.lua | 2 ++ lua/config/plugins.lua | 2 ++ lua/config/plugins/lsp.lua | 15 +++++++++--- lua/config/plugins/tree.lua | 2 +- lua/config/reload.lua | 46 +++++++++++++++---------------------- lua/config/utils.lua | 24 ++++++++++++------- 6 files changed, 51 insertions(+), 40 deletions(-) diff --git a/lua/config/neovide.lua b/lua/config/neovide.lua index 9e1b2d5..5ecb321 100644 --- a/lua/config/neovide.lua +++ b/lua/config/neovide.lua @@ -1,3 +1,5 @@ +-- originally taken from the FAQ + vim.g.gui_font_default_size = 14 vim.g.gui_font_size = vim.g.gui_font_default_size vim.g.gui_font_face = "Comic Code Ligatures" diff --git a/lua/config/plugins.lua b/lua/config/plugins.lua index 9a192c3..1bf5fb7 100644 --- a/lua/config/plugins.lua +++ b/lua/config/plugins.lua @@ -1,5 +1,6 @@ local fn = vim.fn +-- bootstrap local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' if fn.empty(fn.glob(install_path)) > 0 then PACKER_BOOTSTRAP = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) @@ -10,6 +11,7 @@ local packer = require('packer') packer.startup(function(use) use 'wbthomason/packer.nvim' + -- plugin categories require 'config.plugins.telescope'(use) require 'config.plugins.tree'(use) require 'config.plugins.syntax'(use) diff --git a/lua/config/plugins/lsp.lua b/lua/config/plugins/lsp.lua index f88fb04..69fc7bc 100644 --- a/lua/config/plugins/lsp.lua +++ b/lua/config/plugins/lsp.lua @@ -11,7 +11,9 @@ local config = function() vim.o.signcolumn = 'yes' local map = function(from, to) - vim.keymap.set('n', from, to, { noremap = true, silent = true, buffer = bufnr }) + vim.keymap.set('n', from, to, + { noremap = true, silent = true, buffer = bufnr } + ) end map('gd', vim.lsp.buf.definition) @@ -33,7 +35,9 @@ local config = function() map('fm', vim.lsp.buf.formatting) end - local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) + local capabilities = require 'cmp_nvim_lsp'.update_capabilities( + vim.lsp.protocol.make_client_capabilities() + ) require 'lspconfig'.sumneko_lua.setup { on_attach = on_attach, @@ -43,6 +47,12 @@ local config = function() diagnostics = { globals = { 'vim' }, }, + workspace = { + library = vim.api.nvim_get_runtime_file("", true) + }, + telemetry = { + enable = false, + }, }, }, } @@ -75,7 +85,6 @@ return function(use) 'mfussenegger/nvim-dap', } } - use 'tjdevries/nlua.nvim' use { 'windwp/nvim-autopairs', config = function() require 'nvim-autopairs'.setup {} end diff --git a/lua/config/plugins/tree.lua b/lua/config/plugins/tree.lua index 9c90b0b..8d7582c 100644 --- a/lua/config/plugins/tree.lua +++ b/lua/config/plugins/tree.lua @@ -16,7 +16,7 @@ return function(use) } }, window = { - width = 20, + width = 30, }, } diff --git a/lua/config/reload.lua b/lua/config/reload.lua index 79ff6df..d9d05d9 100644 --- a/lua/config/reload.lua +++ b/lua/config/reload.lua @@ -1,36 +1,26 @@ local u = require 'config.utils'.load -local g -vim.api.nvim_create_augroup('reload', {}) - ---- @param arg {file: string} -local reload_file = function(arg) - u.reload(u.path_for(arg.file)) -end +local g = vim.api.nvim_create_augroup('reload', {}) -- reload these files when written to -for _, path in ipairs({ - 'reload.lua', - 'settings.lua', - 'utils.lua', - 'neovide.lua', - 'theme.lua', -}) do u.post_write(g, path, reload_file) end - ---- @param arg {file: string} -local update_plugins = function(arg) - -- unload the file if it's not plugins.lua - local mod = u.path_for(arg.file) - if mod ~= 'config.plugins' then - u.unload(mod) - end - -- reload plugins.lua and compile - u.reload('config.plugins') - require 'packer'.compile() -end +for _, mod in ipairs({ + 'config.reload', + 'config.settings', + 'config.utils', + 'config.neovide', + 'config.theme', +}) do u.mod_post_write(g, mod, u.reload) end -- reload plugin files when written to -u.post_write(g, 'plugins.lua', update_plugins) -u.post_write(g, 'plugins/*', update_plugins) +u.mod_post_write(g, 'config.plugins', function(mod) + u.reload(mod) + require 'packer'.compile() +end) +u.mod_post_write(g, 'config.plugins.*', function(mod) + print(mod) + u.unload(mod) + u.reload('config.plugins') + require 'packer'.compile() +end) diff --git a/lua/config/utils.lua b/lua/config/utils.lua index c2d3a7e..75a3b81 100644 --- a/lua/config/utils.lua +++ b/lua/config/utils.lua @@ -20,23 +20,31 @@ mapping.layout = layout -- loading stuff local load = {} +load.lua_path = vim.fn.stdpath('config') .. '/lua/' + load.post_write = function(group, path, fn) vim.api.nvim_create_autocmd('BufWritePost', { group = group, - pattern = '**/lua/config/' .. path, + pattern = load.lua_path .. path, callback = fn, }) end +load.mod_post_write = function(group, mod, fn) + local set_name = false + if mod:sub(-1, -1) == '*' then set_name = true end + local path = mod:gsub('[.]', '/') .. '.lua' + load.post_write(group, path, function(arg) + local m = mod + if set_name then + local name = arg.file:match('.*/(.*).lua') + m = mod:sub(0, -2) .. name + end + fn(m, arg) + end) +end load.unload = function(mod) package.loaded[mod] = nil end load.reload = function(mod) load.unload(mod) require(mod) end ---- @param path string -load.path_for = function(path) - local i = path:find("lua/config/") - if i == nil then return nil end - local mod = path:sub(i + 4):gsub("/", "."):sub(0, -5) - return mod -end return { mapping = mapping,