This repository has been archived by the owner on Jun 13, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
80 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.