refactor: fully moved attach to configs for compression
Removed the entire folder of attach because there was mostly boilerplate instead of language specific code. It was redundant and just for testing to have concept of what I wanted
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
local config = require("vern-nvim.configs.c")
|
||||
|
||||
---@param bufnr integer Buffer to activate on : defaults to 0
|
||||
---@param user_opts? VernCConfig
|
||||
return function(bufnr, user_opts)
|
||||
---@type VernCConfig
|
||||
local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {})
|
||||
for key, def in pairs(opts.c.keybinds or {}) do
|
||||
if type(def.action) == "function" then
|
||||
vim.api.nvim_buf_create_user_command(bufnr, def.user_command, function()
|
||||
def.action(opts)
|
||||
end, { nargs = "*", desc = def.desc })
|
||||
vim.keymap.set("n", key, function()
|
||||
def.action(opts)
|
||||
end, {
|
||||
buffer = bufnr,
|
||||
silent = true,
|
||||
desc = def.desc,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,22 +0,0 @@
|
||||
local config = require("vern-nvim.configs.cpp")
|
||||
|
||||
---@param bufnr integer Buffer to activate on : defaults to 0
|
||||
---@param user_opts? VernCPPConfig
|
||||
return function(bufnr, user_opts)
|
||||
---@type VernCPPConfig
|
||||
local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {})
|
||||
for key, def in pairs(opts.cpp.keybinds or {}) do
|
||||
if type(def.action) == "function" then
|
||||
vim.api.nvim_buf_create_user_command(bufnr, def.user_command, function()
|
||||
def.action(opts)
|
||||
end, { nargs = "*", desc = def.desc })
|
||||
vim.keymap.set("n", key, function()
|
||||
def.action(opts)
|
||||
end, {
|
||||
buffer = bufnr,
|
||||
silent = true,
|
||||
desc = def.desc,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,22 +0,0 @@
|
||||
local config = require("vern-nvim.configs.lua")
|
||||
|
||||
---@param bufnr integer Buffer to activate on : defaults to 0
|
||||
---@param user_opts? VernLuaConfig
|
||||
return function(bufnr, user_opts)
|
||||
---@type VernLuaConfig
|
||||
local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {})
|
||||
for key, def in pairs(opts.lua.keybinds or {}) do
|
||||
if type(def.action) == "function" then
|
||||
vim.api.nvim_buf_create_user_command(bufnr, def.user_command, function()
|
||||
def.action(opts)
|
||||
end, { nargs = "*", desc = def.desc })
|
||||
vim.keymap.set("n", key, function()
|
||||
def.action(opts)
|
||||
end, {
|
||||
buffer = bufnr,
|
||||
silent = true,
|
||||
desc = def.desc,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,37 +0,0 @@
|
||||
local config = require("vern-nvim.configs.python")
|
||||
|
||||
---@param bufnr integer Buffer to activate on : defaults to 0
|
||||
---@param user_opts? VernPythonConfig
|
||||
return function(bufnr, user_opts)
|
||||
---@type VernPythonConfig
|
||||
local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {})
|
||||
for key, def in pairs(opts.python.keybinds or {}) do
|
||||
if type(def.action) == "function" then
|
||||
vim.api.nvim_buf_create_user_command(bufnr, def.user_command, function()
|
||||
def.action(opts)
|
||||
end, { nargs = "*", desc = def.desc })
|
||||
vim.keymap.set("n", key, function()
|
||||
def.action(opts)
|
||||
end, {
|
||||
buffer = bufnr,
|
||||
silent = true,
|
||||
desc = def.desc,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
local root = require("vern-nvim.utils").proj_root()
|
||||
if not root then
|
||||
return
|
||||
end
|
||||
local venv_dir = nil
|
||||
if vim.uv.fs_stat(root .. "/venv/bin/python") then
|
||||
venv_dir = root .. "/venv"
|
||||
elseif vim.uv.fs_stat(root .. "/.venv/bin/python") then
|
||||
venv_dir = root .. "/.venv"
|
||||
end
|
||||
if venv_dir then
|
||||
vim.env.VIRTUAL_ENV = venv_dir
|
||||
vim.env.PATH = venv_dir .. "/bin:" .. vim.env.PATH
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,7 @@
|
||||
local M = {}
|
||||
|
||||
M.attach = function() end
|
||||
|
||||
---@type VernLanguageConfig
|
||||
M.c = {
|
||||
root = "C",
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
local M = {}
|
||||
|
||||
M.attach = function() end
|
||||
|
||||
---@type VernLanguageConfig
|
||||
M.cpp = {
|
||||
root = "CPP",
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
local M = {}
|
||||
|
||||
M.attach = function() end
|
||||
|
||||
---@type VernLanguageConfig
|
||||
M.lua = {
|
||||
root = "Lua",
|
||||
|
||||
@@ -1,5 +1,22 @@
|
||||
local M = {}
|
||||
|
||||
M.attach = function()
|
||||
local root = require("vern-nvim.utils").proj_root()
|
||||
if not root then
|
||||
return
|
||||
end
|
||||
local venv_dir = nil
|
||||
if vim.uv.fs_stat(root .. "/venv/bin/python") then
|
||||
venv_dir = root .. "/venv"
|
||||
elseif vim.uv.fs_stat(root .. "/.venv/bin/python") then
|
||||
venv_dir = root .. "/.venv"
|
||||
end
|
||||
if venv_dir then
|
||||
vim.env.VIRTUAL_ENV = venv_dir
|
||||
vim.env.PATH = venv_dir .. "/bin:" .. vim.env.PATH
|
||||
end
|
||||
end
|
||||
|
||||
---@type VernLanguageConfig
|
||||
M.python = {
|
||||
root = "Python",
|
||||
|
||||
+28
-3
@@ -35,9 +35,34 @@ function M.setup(user_opts)
|
||||
pattern = "*",
|
||||
callback = function(args)
|
||||
local ft = vim.bo[args.buf].filetype
|
||||
local ok, attach = pcall(require, "vern-nvim.attach." .. ft)
|
||||
if ok and type(attach) == "function" then
|
||||
attach(args.buf, M.opts)
|
||||
if not ft or ft == "" then
|
||||
return
|
||||
end
|
||||
local has_config, mod = pcall(require, "vern-nvim.configs." .. ft)
|
||||
if not has_config then
|
||||
return
|
||||
end
|
||||
|
||||
local opts = vim.tbl_deep_extend("force", {}, mod, M.opts or {})
|
||||
if opts[ft] and opts[ft].keybinds then
|
||||
for key, def in pairs(opts[ft].keybinds or {}) do
|
||||
if type(def.action) == "function" then
|
||||
vim.api.nvim_buf_create_user_command(args.buf, def.user_command, function()
|
||||
def.action(opts)
|
||||
end, { nargs = "*", desc = def.desc })
|
||||
vim.keymap.set("n", key, function()
|
||||
def.action(opts)
|
||||
end, {
|
||||
buffer = args.buf,
|
||||
silent = true,
|
||||
desc = def.desc,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
local ok, attach_mod = pcall(require, "vern-nvim.configs." .. ft)
|
||||
if ok and type(attach_mod.attach) == "function" then
|
||||
attach_mod.attach(args.buf, opts)
|
||||
end
|
||||
end,
|
||||
desc = "Attach languages to buffer",
|
||||
|
||||
Reference in New Issue
Block a user