fixed plugin require lsp integration and made reloading safer and more clean
This commit is contained in:
1 parent
456f03e4eb
commit
29fbaa1522
6 files changed
+51
-40
No files matched your search
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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('<space>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
|
||||
|
||||
@@ -16,7 +16,7 @@ return function(use)
|
||||
}
|
||||
},
|
||||
window = {
|
||||
width = 20,
|
||||
width = 30,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
+18
-28
@@ -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)
|
||||
+16
-8
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user