Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
feat(nvim): organizing a bit more
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Jan 2, 2023
1 parent 7d1f3ba commit 66de900
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 88 deletions.
107 changes: 53 additions & 54 deletions nvim/config/after/ftplugin/go.lua
Original file line number Diff line number Diff line change
@@ -1,66 +1,65 @@
vim.opt_local.formatoptions:append("jno")

local function restart(name)
local configs = require("lspconfig.configs")
local bufnr = vim.api.nvim_get_current_buf()
for _, client in
ipairs(vim.lsp.get_active_clients({
bufnr = bufnr,
name = name,
}))
do
vim.notify("Restarting " .. client.name .. "...")
client.stop()
vim.defer_fn(function()
configs[client.name].launch()
end, 500)
end
local configs = require("lspconfig.configs")
local bufnr = vim.api.nvim_get_current_buf()
for _, client in
ipairs(vim.lsp.get_active_clients({
bufnr = bufnr,
name = name,
}))
do
vim.notify("Restarting " .. client.name .. "...")
client.stop()
vim.defer_fn(function()
configs[client.name].launch()
end, 500)
end
end

local function tidy()
vim.notify("Running `go mod tidy`...")
local uv = vim.loop
local stdout = uv.new_pipe(false)
local stderr = uv.new_pipe(false)
local function on_read(err, _)
assert(not err, err)
end
vim.notify("Running `go mod tidy`...")
local uv = vim.loop
local stdout = uv.new_pipe(false)
local stderr = uv.new_pipe(false)
local function on_read(err, _)
assert(not err, err)
end

local function on_error(err, data)
assert(not err, err)
if data then
-- Just print errors, in case I notice in vim and want to debug
print(data)
end
end
local function on_error(err, data)
assert(not err, err)
if data then
-- Just print errors, in case I notice in vim and want to debug
print(data)
end
end

local handle
handle, _ = uv.spawn(
"go",
{
args = { "mod", "tidy" },
stdio = { nil, stdout, stderr },
cwd = vim.fn.expand("%:h"),
},
vim.schedule_wrap(function()
stdout:read_stop()
stderr:read_stop()
stdout:close()
stderr:close()
handle:close()
vim.schedule(function()
for _, name in ipairs({ "gopls", "golangci_lint_ls" }) do
restart(name)
end
end)
end)
)
uv.read_start(stdout, on_read)
uv.read_start(stderr, on_error)
uv.run("once")
local handle
handle, _ = uv.spawn(
"go",
{
args = { "mod", "tidy" },
stdio = { nil, stdout, stderr },
cwd = vim.fn.expand("%:h"),
},
vim.schedule_wrap(function()
stdout:read_stop()
stderr:read_stop()
stdout:close()
stderr:close()
handle:close()
vim.schedule(function()
for _, name in ipairs({ "gopls", "golangci_lint_ls" }) do
restart(name)
end
end)
end)
)
uv.read_start(stdout, on_read)
uv.read_start(stderr, on_error)
uv.run("once")
end

vim.api.nvim_create_user_command("GoModTidy", tidy, vim.tbl_extend("force", { desc = "go mod tidy" }, {}))

local opts = { noremap = true, silent = true }
vim.keymap.set("n", "<leader>gmt", ":GoModTidy<CR>", opts)
vim.keymap.set("n", "<leader>gmt", ":GoModTidy<CR>", { noremap = true, silent = true, desc = "Run go mod tidy" })
5 changes: 2 additions & 3 deletions nvim/config/after/ftplugin/json.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
local opts = { noremap = true, silent = true }
vim.keymap.set("n", "<leader>jf", "<cmd>%!jq<cr>", opts)
vim.keymap.set("n", "<leader>jm", "<cmd>%!jq -c<cr>", opts)
vim.keymap.set("n", "<leader>jf", "<cmd>%!jq<cr>", { noremap = true, silent = true, desc = "Format with jq" })
vim.keymap.set("n", "<leader>jm", "<cmd>%!jq -c<cr>", { noremap = true, silent = true, desc = "Minify with jq" })
27 changes: 19 additions & 8 deletions nvim/config/lua/plugins/lazy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,23 @@ return {
"danymat/neogen",
event = "BufEnter",
keys = {
{ "<leader>nf", "<cmd>Neogen<cr>", desc = "Neogen generate docs" },
{ "<leader>nf", "<cmd>Neogen<cr>", noremap = true, silent = true, desc = "Neogen generate docs" },
},
config = true,
},
{
"vim-test/vim-test",
event = "BufEnter",
keys = {
{ "<leader>ttn", ":TestNearest -v<CR>g", noremap = true, silent = true, desc = "Test Nearest" },
{ "<leader>ttf", ":TestFile -v<CR>g", noremap = true, silent = true, desc = "Test File" },
{ "<leader>tts", ":TestSuite -v<CR>g", noremap = true, silent = true, desc = "Test Suite" },
{ "<leader>ttl", ":TestLast -v<CR>g", noremap = true, silent = true, desc = "Test Last" },
{ "<leader>ttv", ":TestVisit -v<CR>g", noremap = true, silent = true, desc = "Test Visit" },
},
config = function()
require("user.test")
vim.api.nvim_set_var("test#strategy", "neovim")
vim.api.nvim_set_var("test#neovim#term_position", "vert")
end,
},
{
Expand Down Expand Up @@ -102,18 +110,18 @@ return {
{
"tpope/vim-fugitive",
command = "Git",
keys = {
{ "<leader>gs", vim.cmd.Git, noremap = true, silent = true, desc = "Open Git" },
},
config = function()
require("user.fugitive")
end,
keys = {
{ "<leader>gs", vim.cmd.Git, desc = "Open Git" },
},
},
{
"mbbill/undotree",
cmd = "UndotreeToggle",
keys = {
{ "<leader>u", vim.cmd.UndotreeToggle, desc = "Toggle undotree" },
{ "<leader>u", vim.cmd.UndotreeToggle, noremap = true, silent = true, desc = "Toggle undotree" },
},
},
{
Expand All @@ -125,7 +133,7 @@ return {
"nvim-neo-tree/neo-tree.nvim",
cmd = "Neotree",
keys = {
{ "<leader>tv", "<cmd>Neotree toggle<cr>", desc = "NeoTree" },
{ "<leader>tv", "<cmd>Neotree toggle<cr>", noremap = true, silent = true, desc = "NeoTree" },
},
dependencies = {
"nvim-lua/plenary.nvim",
Expand All @@ -141,7 +149,10 @@ return {
},
{
"mhinz/vim-sayonara",
event = "VeryLazy",
cmd = "Sayonara",
keys = {
{ "<leader>q", ":Sayonara!<CR>", noremap = true, silent = true, desc = "NeoTree" },
},
},
{
"tpope/vim-abolish",
Expand Down
2 changes: 1 addition & 1 deletion nvim/config/lua/plugins/lsp_cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ return {
"simrat39/symbols-outline.nvim",
cmd = "SymbolsOutline",
keys = {
{ "<leader>smb", vim.cmd.SymbolsOutline, desc = "Symbols Outline" },
{ "<leader>smb", vim.cmd.SymbolsOutline, noremap = true, silent = true, desc = "Symbols Outline" },
},
config = { width = 25 },
},
Expand Down
8 changes: 0 additions & 8 deletions nvim/config/lua/user/fidget.lua

This file was deleted.

9 changes: 5 additions & 4 deletions nvim/config/lua/user/fugitive.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ vim.api.nvim_create_autocmd("BufWinEnter", {
return
end

local bufnr = vim.api.nvim_get_current_buf()
local opts = { buffer = bufnr, remap = false }

vim.keymap.set("n", "<leader>Pp", function()
vim.cmd.Git("push")
end, opts)
end, {
buffer = vim.api.nvim_get_current_buf(),
remap = false,
desc = "Git push",
})
end,
})
1 change: 0 additions & 1 deletion nvim/config/lua/user/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ keymap("n", "<S-h>", ":bprevious<CR>", opts)

-- save and quit
keymap("n", "<leader>w", ":write<CR>", opts)
keymap("n", "<leader>q", ":Sayonara!<CR>", opts)

-- paste over without replacing default register
keymap("n", "<leader>p", '"_dP', opts)
Expand Down
9 changes: 0 additions & 9 deletions nvim/config/lua/user/test.lua

This file was deleted.

0 comments on commit 66de900

Please sign in to comment.