perproject plugin

main
spike 2 years ago
parent 57555fa04c
commit e38587f30c

@ -11,23 +11,25 @@ local function setup_autocommands ()
autocmd({"BufRead", "BufWinEnter", "BufNewFile"},{ autocmd({"BufRead", "BufWinEnter", "BufNewFile"},{
group = augroup_name, group = augroup_name,
pattern = "*", pattern = "*",
callback = require("spike.perproject").per_project_jsonfile, callback = require("perproject").per_project_jsonfile,
}) })
autocmd({"DirChanged"},{ autocmd({"DirChanged"},{
group = augroup_name, group = augroup_name,
pattern = "window", pattern = "window",
callback = require("spike.perproject").per_project_jsonfile, callback = require("perproject").per_project_jsonfile,
}) })
end end
local _PP_CONF = { local _PP_CONF = {
basename = ".pnvim.json" basename = ".pnvim.json",
callbacks = pp_callbacks,
} }
local pp_callbacks = { local pp_callbacks = {
-- @enabled: bool -- @enabled: bool
lsp_autostart = function(enabled) lsp_autostart = function(enabled)
if enabled then if enabled then
local other_matching_configs = require('lspconfig.util').get_other_matching_providers(vim.bo.filetype) local other_matching_configs = require('lspconfig.util').get_other_matching_providers(vim.bo.filetype)
@ -36,6 +38,7 @@ local pp_callbacks = {
end end
end end
end end
} }
local function call_pp_callback(proj_opts) local function call_pp_callback(proj_opts)
@ -51,7 +54,7 @@ end
local ok, Path = pcall(require, "plenary.path") local ok, Path = pcall(require, "plenary.path")
if not ok then if not ok then
print("perproject plenary required !") print("[perproject] plenary required !")
end end
-- local scandir = require("plenary.scandir") -- local scandir = require("plenary.scandir")
@ -93,14 +96,32 @@ M.per_project_jsonfile = function()
local cwd = Path.new(vim.fn.getcwd()) local cwd = Path.new(vim.fn.getcwd())
local pp_file = cwd:joinpath(_PP_CONF.basename) local pp_file = cwd:joinpath(_PP_CONF.basename)
if pp_file:is_file() then if pp_file:is_file() then
proj_opts = vim.json.decode(pp_file:read()) local ok, decoded = pcall(vim.json.decode, (pp_file:read()))
call_pp_callback(proj_opts) if not ok then
vim.notify(string.format("[perproject] could not parse %s : %s", _PP_CONF.basename, decoded), vim.log.levels.ERROR)
return
end
call_pp_callback(decoded)
-- pp_options = vim.tbl_deep_extend("force", pp_options, proj_opts or {}) -- pp_options = vim.tbl_deep_extend("force", pp_options, proj_opts or {})
end end
end end
local function setup_callbacks(conf)
if conf.callbacks and
type(conf.callbacks) == "table" then
for cb_name, cb in pairs(conf.callbacks) do
if type(cb) == "function" then
print("setting up callback, ", cb_name)
pp_callbacks[cb_name] = cb
end
end
end
end
function M.setup() function M.setup(conf)
local config = conf or {}
setup_callbacks(config)
setup_autocommands() setup_autocommands()
end end

@ -1 +0,0 @@
require("spike.perproject").setup()
Loading…
Cancel
Save