fixed plugin require lsp integration and made reloading safer and more clean

This commit is contained in:
iris committed 2022-08-04 16:44:09 -04:00
1 parent 456f03e4eb
commit 29fbaa1522
6 files changed
+51 -40

No files matched your search

+2
View File
@@ -1,3 +1,5 @@
-- originally taken from the FAQ
vim.g.gui_font_default_size = 14 vim.g.gui_font_default_size = 14
vim.g.gui_font_size = vim.g.gui_font_default_size vim.g.gui_font_size = vim.g.gui_font_default_size
vim.g.gui_font_face = "Comic Code Ligatures" vim.g.gui_font_face = "Comic Code Ligatures"
+2
View File
@@ -1,5 +1,6 @@
local fn = vim.fn local fn = vim.fn
-- bootstrap
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
if fn.empty(fn.glob(install_path)) > 0 then 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}) 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) packer.startup(function(use)
use 'wbthomason/packer.nvim' use 'wbthomason/packer.nvim'
-- plugin categories
require 'config.plugins.telescope'(use) require 'config.plugins.telescope'(use)
require 'config.plugins.tree'(use) require 'config.plugins.tree'(use)
require 'config.plugins.syntax'(use) require 'config.plugins.syntax'(use)
+12 -3
View File
@@ -11,7 +11,9 @@ local config = function()
vim.o.signcolumn = 'yes' vim.o.signcolumn = 'yes'
local map = function(from, to) 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 end
map('gd', vim.lsp.buf.definition) map('gd', vim.lsp.buf.definition)
@@ -33,7 +35,9 @@ local config = function()
map('<space>fm', vim.lsp.buf.formatting) map('<space>fm', vim.lsp.buf.formatting)
end 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 { require 'lspconfig'.sumneko_lua.setup {
on_attach = on_attach, on_attach = on_attach,
@@ -43,6 +47,12 @@ local config = function()
diagnostics = { diagnostics = {
globals = { 'vim' }, globals = { 'vim' },
}, },
workspace = {
library = vim.api.nvim_get_runtime_file("", true)
},
telemetry = {
enable = false,
},
}, },
}, },
} }
@@ -75,7 +85,6 @@ return function(use)
'mfussenegger/nvim-dap', 'mfussenegger/nvim-dap',
} }
} }
use 'tjdevries/nlua.nvim'
use { use {
'windwp/nvim-autopairs', 'windwp/nvim-autopairs',
config = function() require 'nvim-autopairs'.setup {} end config = function() require 'nvim-autopairs'.setup {} end
+1 -1
View File
@@ -16,7 +16,7 @@ return function(use)
} }
}, },
window = { window = {
width = 20, width = 30,
}, },
} }
+18 -28
View File
@@ -1,36 +1,26 @@
local u = require 'config.utils'.load local u = require 'config.utils'.load
local g local g = vim.api.nvim_create_augroup('reload', {})
vim.api.nvim_create_augroup('reload', {})
--- @param arg {file: string}
local reload_file = function(arg)
u.reload(u.path_for(arg.file))
end
-- reload these files when written to -- reload these files when written to
for _, path in ipairs({ for _, mod in ipairs({
'reload.lua', 'config.reload',
'settings.lua', 'config.settings',
'utils.lua', 'config.utils',
'neovide.lua', 'config.neovide',
'theme.lua', 'config.theme',
}) do u.post_write(g, path, reload_file) end }) do u.mod_post_write(g, mod, u.reload) 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
-- reload plugin files when written to -- reload plugin files when written to
u.post_write(g, 'plugins.lua', update_plugins) u.mod_post_write(g, 'config.plugins', function(mod)
u.post_write(g, 'plugins/*', update_plugins) 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)
+16 -8
View File
@@ -20,23 +20,31 @@ mapping.layout = layout
-- loading stuff -- loading stuff
local load = {} local load = {}
load.lua_path = vim.fn.stdpath('config') .. '/lua/'
load.post_write = function(group, path, fn) load.post_write = function(group, path, fn)
vim.api.nvim_create_autocmd('BufWritePost', { vim.api.nvim_create_autocmd('BufWritePost', {
group = group, group = group,
pattern = '**/lua/config/' .. path, pattern = load.lua_path .. path,
callback = fn, callback = fn,
}) })
end 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.unload = function(mod) package.loaded[mod] = nil end
load.reload = function(mod) load.unload(mod) require(mod) 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 { return {
mapping = mapping, mapping = mapping,