perproject custom conf (lsp)
parent
e6dcfa8f3a
commit
57555fa04c
@ -0,0 +1,3 @@
|
||||
{
|
||||
"lsp_autostart": true
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
-- helper module for setting custom lsp settings per project
|
||||
-- will be used for setting autostart of lspclient per projects
|
||||
|
||||
|
||||
local ok, Path = pcall(require, "plenary.path")
|
||||
if not ok then
|
||||
print("plenary required !")
|
||||
end
|
||||
-- local scandir = require("")
|
||||
local pp = require("spike.perproject")
|
||||
|
||||
local autocmd = vim.api.nvim_create_autocmd
|
||||
local augroup = vim.api.nvim_create_augroup
|
||||
local augroup_name = "spike_lsp"
|
||||
local custom
|
||||
|
||||
local function per_project_file()
|
||||
local cwd = Path.new(vim.fn.getcwd())
|
||||
local pp_dir = cwd:joinpath(pp.base_dirname)
|
||||
if pp_dir:is_dir() then
|
||||
print(pp_dir)
|
||||
else
|
||||
-- print("no " .. pp.base_dirname)
|
||||
end
|
||||
|
||||
-- TODO:
|
||||
-- check if there is a custom .nvim-lsp dir in working dir
|
||||
-- each file inside .nvim-lsp represent a active option if
|
||||
-- it is present
|
||||
-- example
|
||||
-- workingDir/
|
||||
-- .perproject/
|
||||
-- lsp.autostart --> autostart lsp for this project
|
||||
end
|
||||
|
||||
per_project_file()
|
||||
|
||||
|
||||
augroup( augroup_name ,{}) -- automatically clears prev group commands
|
||||
autocmd({"BufReadPre"},{
|
||||
group = augroup_name,
|
||||
pattern = "*",
|
||||
callback = per_project_file,
|
||||
})
|
||||
autocmd({"DirChanged"},{
|
||||
group = augroup_name,
|
||||
pattern = "window",
|
||||
callback = per_project_file
|
||||
})
|
||||
|
@ -1,5 +1,107 @@
|
||||
-- helper module for setting custom lsp settings per project
|
||||
-- will be used for setting autostart of lspclient per projects
|
||||
--
|
||||
local M = {}
|
||||
local autocmd = vim.api.nvim_create_autocmd
|
||||
local augroup = vim.api.nvim_create_augroup
|
||||
local augroup_name = "perproject"
|
||||
|
||||
M.base_dirname = '.pnvim'
|
||||
local function setup_autocommands ()
|
||||
augroup( augroup_name ,{}) -- automatically clears prev group commands
|
||||
autocmd({"BufRead", "BufWinEnter", "BufNewFile"},{
|
||||
group = augroup_name,
|
||||
pattern = "*",
|
||||
callback = require("spike.perproject").per_project_jsonfile,
|
||||
})
|
||||
|
||||
autocmd({"DirChanged"},{
|
||||
group = augroup_name,
|
||||
pattern = "window",
|
||||
callback = require("spike.perproject").per_project_jsonfile,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
local _PP_CONF = {
|
||||
basename = ".pnvim.json"
|
||||
}
|
||||
|
||||
local pp_callbacks = {
|
||||
-- @enabled: bool
|
||||
lsp_autostart = function(enabled)
|
||||
if enabled then
|
||||
local other_matching_configs = require('lspconfig.util').get_other_matching_providers(vim.bo.filetype)
|
||||
for _, config in ipairs(other_matching_configs) do
|
||||
config.launch()
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
local function call_pp_callback(proj_opts)
|
||||
for key, val in pairs(proj_opts) do
|
||||
-- pp_callbacks[opt] ~= nil and pp_callbacks[opt].__call()
|
||||
if pp_callbacks[key] ~= nil then
|
||||
pp_callbacks[key](val)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
local ok, Path = pcall(require, "plenary.path")
|
||||
|
||||
if not ok then
|
||||
print("perproject plenary required !")
|
||||
end
|
||||
|
||||
-- local scandir = require("plenary.scandir")
|
||||
|
||||
local function per_project_file()
|
||||
local cwd = Path.new(vim.fn.getcwd())
|
||||
local pp_dir = cwd:joinpath(_PP_CONF_.basename)
|
||||
|
||||
if pp_dir:is_dir() then
|
||||
|
||||
-- find if there is perproject dir
|
||||
local function on_exit(results)
|
||||
|
||||
vim.schedule(function()
|
||||
for _, res in ipairs(results) do
|
||||
pp_options[vim.fs.basename(res)] = true
|
||||
end
|
||||
end)
|
||||
end
|
||||
scandir.scan_dir_async(pp_dir.filename, {
|
||||
-- on_insert = on_insert,
|
||||
on_exit = on_exit,
|
||||
})
|
||||
else
|
||||
print("no " .. _PP_CONF.basename)
|
||||
end
|
||||
|
||||
-- TODO:
|
||||
-- check if there is a custom .nvim-lsp dir in working dir
|
||||
-- each file inside .nvim-lsp represent a active option if
|
||||
-- it is present
|
||||
-- example
|
||||
-- workingDir/
|
||||
-- .perproject/
|
||||
-- lsp.autostart --> autostart lsp for this project
|
||||
end
|
||||
|
||||
M.per_project_jsonfile = function()
|
||||
local cwd = Path.new(vim.fn.getcwd())
|
||||
local pp_file = cwd:joinpath(_PP_CONF.basename)
|
||||
if pp_file:is_file() then
|
||||
proj_opts = vim.json.decode(pp_file:read())
|
||||
call_pp_callback(proj_opts)
|
||||
-- pp_options = vim.tbl_deep_extend("force", pp_options, proj_opts or {})
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function M.setup()
|
||||
setup_autocommands()
|
||||
end
|
||||
|
||||
return M
|
||||
|
@ -0,0 +1 @@
|
||||
require("spike.perproject").setup()
|
Loading…
Reference in New Issue