mirror of
https://github.com/halfdan/dotfiles.git
synced 2025-09-10 19:56:24 +00:00
Soooo many changes
This commit is contained in:
@@ -1,46 +1,116 @@
|
||||
local Worktree = require("git-worktree")
|
||||
local Job = require("plenary.job")
|
||||
local FTerm = require("FTerm")
|
||||
|
||||
local function schedule_notify(message)
|
||||
local function file_exists(name)
|
||||
local f=io.open(name,"r")
|
||||
if f~=nil then io.close(f) return true else return false end
|
||||
end
|
||||
|
||||
local function schedule_notify(message, level)
|
||||
vim.schedule(function()
|
||||
vim.notify.notify(message)
|
||||
vim.notify.notify(message, level or "info")
|
||||
end)
|
||||
end
|
||||
|
||||
local function is_massdriver()
|
||||
return not not (string.find(vim.loop.cwd(), "massdriver.git", 1, true))
|
||||
local function is_elixir_project()
|
||||
return file_exists(vim.loop.cwd() .. "/" .. "mix.exs")
|
||||
end
|
||||
|
||||
-- Run mix compile
|
||||
local compile_job = Job:new({
|
||||
command = "mix",
|
||||
args = { "compile" },
|
||||
on_start = function()
|
||||
schedule_notify("Compiling...", "debug")
|
||||
end,
|
||||
on_exit = function(_j, _return_val)
|
||||
schedule_notify("Compiling done")
|
||||
end
|
||||
})
|
||||
|
||||
-- Run mix deps.get
|
||||
local deps_job = Job:new({
|
||||
command = "mix",
|
||||
args = { "deps.get" },
|
||||
on_start = function()
|
||||
schedule_notify("Fetching dependencies...")
|
||||
end,
|
||||
on_exit = function(_j, _return_val)
|
||||
schedule_notify("Fetched dependencies")
|
||||
end
|
||||
})
|
||||
|
||||
local function create_docker_up_job(path)
|
||||
return Job:new({
|
||||
command = "docker-compose",
|
||||
args = { "up" },
|
||||
cwd = path,
|
||||
detached = true,
|
||||
on_start = function ()
|
||||
schedule_notify("Running docker in " .. path, "debug")
|
||||
end,
|
||||
on_exit = function (_j, return_val)
|
||||
if return_val ~= 0 then
|
||||
schedule_notify("Error running docker for " .. path, "error")
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
local function create_docker_down_job(path)
|
||||
return Job:new({
|
||||
command = "docker-compose",
|
||||
args = { "down" },
|
||||
cwd = path,
|
||||
on_start = function ()
|
||||
schedule_notify("Shutting down containers at " .. path, "debug")
|
||||
end,
|
||||
on_exit = function ()
|
||||
schedule_notify("Shut down containers at " .. path, "debug")
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
local iex = FTerm:new({
|
||||
cmd = { "iex", "-S", "mix" },
|
||||
dimensions = {
|
||||
height = 0.9,
|
||||
width = 0.9
|
||||
}
|
||||
})
|
||||
|
||||
vim.keymap.set('t', '<A-t>', function ()
|
||||
iex:toggle()
|
||||
end)
|
||||
vim.keymap.set('n', '<A-t>', function ()
|
||||
iex:toggle()
|
||||
end)
|
||||
|
||||
Worktree.on_tree_change(function(op, metadata)
|
||||
local compile_job = Job:new({
|
||||
command = "mix",
|
||||
args = { "compile" },
|
||||
on_start = function()
|
||||
schedule_notify("Compiling...")
|
||||
end,
|
||||
on_exit = function(_j, _return_val)
|
||||
schedule_notify("Compiling done")
|
||||
end
|
||||
})
|
||||
|
||||
local deps_job = Job:new({
|
||||
command = "mix",
|
||||
args = { "deps.get" },
|
||||
on_start = function()
|
||||
schedule_notify("Fetching dependencies...")
|
||||
end,
|
||||
on_exit = function(_j, _return_val)
|
||||
schedule_notify("Fetched dependencies")
|
||||
end
|
||||
})
|
||||
|
||||
if op == Worktree.Operations.Create and is_massdriver() then
|
||||
if op == Worktree.Operations.Create and is_elixir_project() then
|
||||
deps_job:and_then(compile_job)
|
||||
deps_job:sync()
|
||||
compile_job:wait()
|
||||
deps_job:start()
|
||||
end
|
||||
|
||||
if op == Worktree.Operations.Switch and is_massdriver() then
|
||||
if op == Worktree.Operations.Switch and is_elixir_project() then
|
||||
local docker_down = create_docker_down_job(metadata.prev_path)
|
||||
local docker_up = create_docker_up_job(metadata.path)
|
||||
|
||||
docker_down:and_then(docker_up)
|
||||
compile_job:start()
|
||||
docker_down:start()
|
||||
|
||||
iex:close(true)
|
||||
end
|
||||
end)
|
||||
|
||||
local group = vim.api.nvim_create_augroup('MyCustomNeogitEvents', { clear = true })
|
||||
vim.api.nvim_create_autocmd('User', {
|
||||
pattern = 'NeogitPullComplete',
|
||||
group = group,
|
||||
callback = function ()
|
||||
deps_job:and_then(compile_job)
|
||||
deps_job:start()
|
||||
end,
|
||||
})
|
||||
|
@@ -127,7 +127,7 @@ local on_attach = function(client, bufnr)
|
||||
nnoremap("gr", function() vim.lsp.buf.references() end)
|
||||
nnoremap("<leader>rn", function() vim.lsp.buf.rename() end)
|
||||
nnoremap("<leader>cl", function() vim.lsp.codelens.run() end)
|
||||
nnoremap("<leader>ff", function() vim.lsp.buf.format{async = true} end)
|
||||
nnoremap("<leader>fa", function() vim.lsp.buf.format{async = true} end)
|
||||
inoremap("<C-h>", function() vim.lsp.buf.signature_help() end)
|
||||
|
||||
lsp_status.on_attach(client, bufnr)
|
||||
@@ -137,7 +137,7 @@ local function config(_config)
|
||||
_config = vim.tbl_deep_extend("force", {
|
||||
log_level = vim.lsp.protocol.MessageType.Log,
|
||||
message_level = vim.lsp.protocol.MessageType.Log,
|
||||
capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()),
|
||||
capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()),
|
||||
on_attach = on_attach,
|
||||
}, _config or {})
|
||||
|
||||
|
1
.config/nvim/after/plugin/luasnip.lua
Normal file
1
.config/nvim/after/plugin/luasnip.lua
Normal file
@@ -0,0 +1 @@
|
||||
require("luasnip/loaders/from_vscode").lazy_load()
|
@@ -2,25 +2,24 @@ local Remap = require("halfdan.keymap")
|
||||
local nnoremap = Remap.nnoremap
|
||||
local builtin = require("telescope.builtin")
|
||||
|
||||
nnoremap("<leader>pg", function()
|
||||
nnoremap("<leader>gg", function()
|
||||
builtin.live_grep()
|
||||
end)
|
||||
nnoremap("<C-p>", function()
|
||||
if not pcall(builtin.git_files) then
|
||||
builtin.find_files()
|
||||
end
|
||||
builtin.commands()
|
||||
end)
|
||||
nnoremap("<Leader>pf", function()
|
||||
|
||||
nnoremap("<Leader>ff", function()
|
||||
builtin.find_files()
|
||||
end)
|
||||
|
||||
nnoremap("<Leader>ps", function()
|
||||
nnoremap("<Leader>fs", function()
|
||||
builtin.lsp_workspace_symbols()
|
||||
end)
|
||||
nnoremap("<leader>pw", function()
|
||||
nnoremap("<leader>gw", function()
|
||||
builtin.grep_string { search = vim.fn.expand("<cword>") }
|
||||
end)
|
||||
nnoremap("<leader>pb", function()
|
||||
nnoremap("<leader>fb", function()
|
||||
builtin.buffers()
|
||||
end)
|
||||
nnoremap("<leader>vh", function()
|
||||
@@ -36,3 +35,5 @@ end)
|
||||
nnoremap("<leader>gc", function()
|
||||
builtin.git_branches()
|
||||
end)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user