Skip to content

Commit

Permalink
feat(nvim.work): modify for web dev environment
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroSuero committed Oct 9, 2024
1 parent 741bbb8 commit 9b3489e
Show file tree
Hide file tree
Showing 27 changed files with 338 additions and 779 deletions.
5 changes: 4 additions & 1 deletion roles/neovim/files/work/.luarc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json",
"diagnostics": {
"unusedLocalExclude": ["_*"]
}
},
"diagnostics.globals": [
"vim"
]
}
190 changes: 190 additions & 0 deletions roles/neovim/files/work/after/ftplugin/gitcommit.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
local ok, _ = pcall(require, "plenary")
if not ok then
vim.api.nvim_err_writeln "plenary.nvim not found"
return
end

local Job = require "plenary.job"
---@param args string[]
---@param opts? table
---@return string[]
local git_command = function(args, opts)
opts = opts or {}

local _args = { "git" }
if opts.git_dir then
vim.list_extend(_args, { "--git-dir", opts.git_dir })
end
return vim.list_extend(_args, args)
end

---@param cmd string[]
---@param cwd? string
---@return table|nil, integer, string[]
local get_os_cmd_output = function(cmd, cwd)
assert(type(cmd) == "table", "cmd must be a table")
assert(cwd ~= nil, "cwd must be provided")
local command = table.remove(cmd, 1)
local stderr = {}
local stdout, ret = Job:new({
command = command,
args = cmd,
cwd = cwd,
on_stderr = function(_, data)
table.insert(stderr, data)
end,
}):sync()
return stdout, ret, stderr
end

---@param args string[]
---@param opts? table
---@return table|nil, integer, string[]
local get_git_cmd_output = function(args, opts)
assert(type(args) == "table", "args must be a table")
assert(opts ~= nil, "opts must be provided")
local cmd = git_command(args, opts)
return get_os_cmd_output(cmd, opts.cwd)
end

---@param opts? table
local get_git_branches = function(opts)
assert(opts ~= nil, "opts must be provided")
local format = "%(HEAD)"
.. "%(refname)"
.. "%(authorname)"
.. "%(upstream:lstrip=2)"
.. "%(committerdate:format-local:%Y/%m/%d %H:%M:%S)"

local output = get_git_cmd_output({
"for-each-ref",
"--perl",
"--format",
format,
"--sort",
"-authordate",
opts.pattern,
}, opts)
assert(output ~= nil, "output must be provided")

local show_remote_tracking_branches =
vim.F.if_nil(opts.show_remote_tracking_branches, true)

local unescape_single_quote = function(v)
return string.gsub(v, "\\([\\'])", "%1")
end

local parse_line = function(line)
local fields = vim.split(string.sub(line, 2, -2), "''")
local entry = {
head = fields[1],
refname = unescape_single_quote(fields[2]),
authorname = unescape_single_quote(fields[3]),
upstream = unescape_single_quote(fields[4]),
committerdate = fields[5],
}
local prefix
if vim.startswith(entry.refname, "refs/remotes/") then
if show_remote_tracking_branches then
prefix = "refs/remotes/"
else
return
end
elseif vim.startswith(entry.refname, "refs/heads/") then
prefix = "refs/heads/"
else
return
end
if entry.head == "*" then
entry.name = string.sub(entry.refname, string.len(prefix) + 1)
end

if entry.name ~= nil and entry.name:find "feature/" then
return entry
else
return nil
end
end
for _, line in ipairs(output) do
local entry = parse_line(line)
if entry ~= nil then
return entry
end
end
return nil
end

local current_branch = get_git_branches {
cwd = vim.uv.cwd(),
show_remote_tracking_branches = true,
}

assert(current_branch ~= nil, "current_branch is nil")

---@param feature string
---@param insert_end? boolean
local insert_feature_branch = function(feature, insert_end)
assert(feature ~= nil, "feature must be provided")
if insert_end == nil then
insert_end = false
end
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
lines[1] = feature
vim.api.nvim_buf_set_lines(0, 0, -1, false, lines)
vim.api.nvim_win_set_cursor(0, { 1, 0 })
if insert_end then
vim.api.nvim_feedkeys("A", "n", false)
else
vim.api.nvim_feedkeys("I", "n", false)
end
end

---@param type "jira"|"conventional"
---@param branch string
local insert_commit_format = function(type, branch)
local feature = vim.split(branch, "/")[2]
if type == "jira" then
insert_feature_branch(string.format("[%s]", feature))
elseif type == "conventional" then
vim.ui.select({
"feat",
"fix",
"chore",
"docs",
"style",
"refactor",
"perf",
"test",
"build",
"ci",
"revert",
}, {
prompt = "Select the type of commit",
}, function(choice)
vim.ui.input({
prompt = "Enter the scope (empty for feature/<feature>)",
}, function(input)
if input == nil or input == "" then
input = string.format("(%s):", feature)
else
input = string.format("(%s):", input)
end
insert_feature_branch(string.format("%s%s", choice, input), true)
end)
end)
else
insert_feature_branch ""
end
end

if current_branch.name:find "feature/" then
vim.ui.select({
"Jira",
"conventional-commits",
"none",
}, {
prompt = "Select the type of commit",
}, function(choice)
insert_commit_format(choice, current_branch.name)
end)
end
66 changes: 66 additions & 0 deletions roles/neovim/files/work/lazy-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"LuaSnip": { "branch": "master", "commit": "e808bee352d1a6fcf902ca1a71cee76e60e24071" },
"better-ts-errors.nvim": { "branch": "main", "commit": "fdca451849c196ece2754eb8ad98472e0e28d569" },
"bufferline.nvim": { "branch": "main", "commit": "0b2fd861eee7595015b6561dade52fb060be10c4" },
"catppuccin": { "branch": "main", "commit": "7be452ee067978cdc8b2c5f3411f0c71ffa612b9" },
"cloak.nvim": { "branch": "main", "commit": "648aca6d33ec011dc3166e7af3b38820d01a71e4" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
"colorbuddy.nvim": { "branch": "master", "commit": "8b968581e5c19d22a861d5f3fe5dbd83394fa681" },
"cspell.nvim": { "branch": "main", "commit": "2c29bf573292c8f5053383d1be4ab908f4ecfc47" },
"dressing.nvim": { "branch": "master", "commit": "1b7921eecc65af1baf8ac1dc06f0794934cbcfb2" },
"fidget.nvim": { "branch": "main", "commit": "d855eed8a06531a7e8fd0684889b2943f373c469" },
"git-messenger.vim": { "branch": "master", "commit": "edc603d4cda7894a743e383e16c638e206d03148" },
"gitmoji.nvim": { "branch": "main", "commit": "326ddf01cbf3425566a089126ece7e8bd2560601" },
"gitsigns.nvim": { "branch": "main", "commit": "863903631e676b33e8be2acb17512fdc1b80b4fb" },
"gruvbox.nvim": { "branch": "main", "commit": "49d9c0b150ba70efcd831ec7b3cb8ee740067045" },
"harpoon": { "branch": "harpoon2", "commit": "0378a6c428a0bed6a2781d459d7943843f374bce" },
"indent-blankline.nvim": { "branch": "master", "commit": "e7a4442e055ec953311e77791546238d1eaae507" },
"inlay-hints.nvim": { "branch": "main", "commit": "006b0898f5d3874e8e528352103733142e705834" },
"kanagawa.nvim": { "branch": "master", "commit": "f491b0fe68fffbece7030181073dfe51f45cda81" },
"lazy.nvim": { "branch": "main", "commit": "1159bdccd8910a0fd0914b24d6c3d186689023d9" },
"lazydev.nvim": { "branch": "main", "commit": "491452cf1ca6f029e90ad0d0368848fac717c6d2" },
"lazygit.nvim": { "branch": "main", "commit": "56760339a81cd1540d5a72fd9d93010a2677b55d" },
"leap.nvim": { "branch": "main", "commit": "c6bfb191f1161fbabace1f36f578a20ac6c7642c" },
"lspkind.nvim": { "branch": "master", "commit": "59c3f419af48a2ffb2320cea85e44e5a95f71664" },
"lualine.nvim": { "branch": "master", "commit": "b431d228b7bbcdaea818bdc3e25b8cdbe861f056" },
"luvit-meta": { "branch": "main", "commit": "ce76f6f6cdc9201523a5875a4471dcfe0186eb60" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "25c11854aa25558ee6c03432edfa0df0217324be" },
"mason-null-ls.nvim": { "branch": "main", "commit": "de19726de7260c68d94691afb057fa73d3cc53e7" },
"mason-tool-installer.nvim": { "branch": "main", "commit": "c5e07b8ff54187716334d585db34282e46fa2932" },
"mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" },
"none-ls-luacheck.nvim": { "branch": "main", "commit": "a1dfea0d4c40c4023829c8b9a7ab0a26135985ca" },
"none-ls.nvim": { "branch": "main", "commit": "0e0a940477cc08fa7b1799384a1d668058ed4e61" },
"nui.nvim": { "branch": "main", "commit": "b58e2bfda5cea347c9d58b7f11cf3012c7b3953f" },
"nvim-cmp": { "branch": "main", "commit": "ae644feb7b67bf1ce4260c231d1d4300b19c6f30" },
"nvim-lsp-file-operations": { "branch": "master", "commit": "92a673de7ecaa157dd230d0128def10beb56d103" },
"nvim-lsp-ts-utils": { "branch": "main", "commit": "0a6a16ef292c9b61eac6dad00d52666c7f84b0e7" },
"nvim-lspconfig": { "branch": "master", "commit": "ff69ecca55d83ffc70657f260a799f79a5637831" },
"nvim-treesitter": { "branch": "master", "commit": "9d2acd49976e2a9da72949008df03436f781fd23" },
"nvim-treesitter-context": { "branch": "master", "commit": "78a81c7494e7d1a08dd1200b556933e513fd9f29" },
"nvim-ts-autotag": { "branch": "main", "commit": "e239a560f338be31337e7abc3ee42515daf23f5e" },
"nvim-ts-context-commentstring": { "branch": "main", "commit": "9c74db656c3d0b1c4392fc89a016b1910539e7c0" },
"nvim-web-devicons": { "branch": "master", "commit": "56f17def81478e406e3a8ec4aa727558e79786f3" },
"paint.nvim": { "branch": "main", "commit": "ef6f717a8669619ebbd098fb72f85115d64c6c92" },
"playground": { "branch": "master", "commit": "ba48c6a62a280eefb7c85725b0915e021a1a0749" },
"plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" },
"rose-pine": { "branch": "main", "commit": "d396005db5bbd1d4ec7772a7c96c96f4c4802328" },
"schemastore.nvim": { "branch": "main", "commit": "dd374887d6e1de38e9d7041da824a8dc10cae401" },
"supermaven-nvim": { "branch": "main", "commit": "07d20fce48a5629686aefb0a7cd4b25e33947d50" },
"tailwindcss-colors.nvim": { "branch": "main", "commit": "ccb5be2f84673c1a0ef90a0c0a76733e85e5265b" },
"telescope-file-browser.nvim": { "branch": "master", "commit": "3b8a1e17187cfeedb31decbd625da62398a8ff34" },
"telescope-fzf-native.nvim": { "branch": "main", "commit": "cf48d4dfce44e0b9a2e19a008d6ec6ea6f01a83b" },
"telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" },
"todo-comments.nvim": { "branch": "main", "commit": "ae0a2afb47cf7395dc400e5dc4e05274bf4fb9e0" },
"tokyonight.nvim": { "branch": "main", "commit": "2c85fad417170d4572ead7bf9fdd706057bd73d7" },
"transparent.nvim": { "branch": "main", "commit": "8a2749a2fa74f97fe6557f61b89ac7fd873f3c21" },
"trouble.nvim": { "branch": "main", "commit": "254145ffd528b98eb20be894338e2d5c93fa02c2" },
"ts-comments.nvim": { "branch": "main", "commit": "98d7d4dec0af1312d38e288f800bbf6ff562b6ab" },
"vim-fugitive": { "branch": "master", "commit": "d4877e54cef67f5af4f950935b1ade19ed6b7370" },
"vim-maximizer": { "branch": "master", "commit": "2e54952fe91e140a2e69f35f22131219fcd9c5f1" },
"vim-tmux-navigator": { "branch": "master", "commit": "a9b52e7d36114d40350099f254b5f299a35df978" },
"which-key.nvim": { "branch": "main", "commit": "8badb359f7ab8711e2575ef75dfe6fbbd87e4821" },
"zen-mode.nvim": { "branch": "main", "commit": "29b292bdc58b76a6c8f294c961a8bf92c5a6ebd6" }
}
14 changes: 8 additions & 6 deletions roles/neovim/files/work/lua/aome/lsp/codelens.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ M.run = function()

local _, lens = next(lenses)

local client_id = next(vim.lsp.buf_get_clients(bufnr))
local client_id = next(vim.lsp.get_clients { bufnr = 0 })
local client = vim.lsp.get_client_by_id(client_id)
client.request("workspace/executeCommand", lens.command, function(...)
local result = vim.lsp.handlers["workspace/executeCommand"](...)
vim.lsp.codelens.refresh()
return result
end, bufnr)
if client ~= nil then
client.request("workspace/executeCommand", lens.command, function(...)
local result = vim.lsp.handlers["workspace/executeCommand"](...)
vim.lsp.codelens.refresh()
return result
end, bufnr)
end
end

local virtlines_enabled = true
Expand Down
20 changes: 2 additions & 18 deletions roles/neovim/files/work/lua/aome/lsp/handlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ vim.lsp.handlers["textDocument/definition"] = function(_, result)
return
end

if vim.tbl_islist(result) then
if vim.islist(result) then
vim.lsp.util.jump_to_location(result[1], "utf-8")
else
vim.lsp.util.jump_to_location(result, "utf-8")
Expand All @@ -15,7 +15,7 @@ end
vim.lsp.handlers["textDocument/publishDiagnostics"] =
vim.lsp.with(vim.lsp.handlers["textDocument/publishDiagnostics"], {
signs = {
severity = { min = vim.diagnostic.severity.WARNING },
severity = { min = vim.diagnostic.severity.WARN },
},
underline = {
severity = { min = vim.diagnostic.severity.ERROR },
Expand All @@ -33,26 +33,10 @@ M.implementation = function()
"textDocument/implementation",
params,
function(err, result, ctx, config)
local bufnr = ctx.bufnr
local ft = vim.api.nvim_buf_get_option(bufnr, "filetype")

-- In go code, I do not like to see any mocks for impls
if ft == "go" then
local new_result = vim.tbl_filter(function(v)
return not string.find(v.uri, "mock_")
end, result)

if #new_result > 0 then
result = new_result
end
end

vim.lsp.handlers["textDocument/implementation"](err, result, ctx, config)
vim.cmd [[normal! zz]]
end
)
end

-- vim.lsp.codelens.display = require("gl.codelens").display

return M
Loading

0 comments on commit 9b3489e

Please sign in to comment.