diff --git a/roles/neovim/files/work/.luarc.json b/roles/neovim/files/work/.luarc.json index 5188494..3eaa8fc 100644 --- a/roles/neovim/files/work/.luarc.json +++ b/roles/neovim/files/work/.luarc.json @@ -2,5 +2,8 @@ "$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json", "diagnostics": { "unusedLocalExclude": ["_*"] - } + }, + "diagnostics.globals": [ + "vim" + ] } diff --git a/roles/neovim/files/work/after/ftplugin/gitcommit.lua b/roles/neovim/files/work/after/ftplugin/gitcommit.lua new file mode 100644 index 0000000..98d3f52 --- /dev/null +++ b/roles/neovim/files/work/after/ftplugin/gitcommit.lua @@ -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/)", + }, 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 diff --git a/roles/neovim/files/work/lazy-lock.json b/roles/neovim/files/work/lazy-lock.json new file mode 100644 index 0000000..ccc14b0 --- /dev/null +++ b/roles/neovim/files/work/lazy-lock.json @@ -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" } +} diff --git a/roles/neovim/files/work/lua/aome/lsp/codelens.lua b/roles/neovim/files/work/lua/aome/lsp/codelens.lua index 1db7c0f..4ebadbf 100644 --- a/roles/neovim/files/work/lua/aome/lsp/codelens.lua +++ b/roles/neovim/files/work/lua/aome/lsp/codelens.lua @@ -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 diff --git a/roles/neovim/files/work/lua/aome/lsp/handlers.lua b/roles/neovim/files/work/lua/aome/lsp/handlers.lua index 8aacd65..17cb7b2 100644 --- a/roles/neovim/files/work/lua/aome/lsp/handlers.lua +++ b/roles/neovim/files/work/lua/aome/lsp/handlers.lua @@ -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") @@ -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 }, @@ -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 diff --git a/roles/neovim/files/work/lua/aome/lsp/init.lua b/roles/neovim/files/work/lua/aome/lsp/init.lua index 03252b9..37eb821 100644 --- a/roles/neovim/files/work/lua/aome/lsp/init.lua +++ b/roles/neovim/files/work/lua/aome/lsp/init.lua @@ -153,8 +153,6 @@ local custom_attach = function(client, bufnr) "[w]orkspace [s]ymbols" ) - vim.bo.omnifunc = "v:lua.vim.lsp.omnifunc" - -- Set autocommands conditional on server_capabilities if client.server_capabilities.documentHighlightProvider @@ -196,22 +194,10 @@ local custom_attach = function(client, bufnr) end end - if filetype == "typescript" or filetype == "lua" then - client.server_capabilities.semanticTokensProvider = nil - end - -- Attach any filetype specific options to the client filetype_attach[filetype]() end -local _get_intelephense_license = function() - local f = - assert(io.open(os.getenv "HOME" .. "/intelephense/license.txt", "rb")) - local content = f:read "*a" - f:close() - return string.gsub(content, "%s+", "") -end - local updated_capabilities = vim.lsp.protocol.make_client_capabilities() updated_capabilities.textDocument.completion.completionItem.snippetSupport = true @@ -228,22 +214,7 @@ updated_capabilities.textDocument.completion.completionItem.insertReplaceSupport updated_capabilities.textDocument.codeLens = { dynamicRegistration = false } --- local rust_analyzer, rust_analyzer_cmd = nil, { "rustup", "run", "1.73", "rust-analyzer" } -local rust_analyzer = { - cmd = { "rustup", "run", "nightly", "rust-analyzer" }, - -- settings = { - -- ["rust-analyzer"] = { - -- checkOnSave = { - -- command = "clippy", - -- }, - -- }, - -- }, -} - local servers = { - ansiblels = true, - -- Also uses `shellcheck` and `explainshell` - bashls = true, lua_ls = { Lua = { library = { @@ -257,15 +228,14 @@ local servers = { }, }, - csharp_ls = true, - - phpactor = true, - - tailwindcss = true, + emmet_ls = true, - pyright = true, + tailwindcss = { + on_attach = function(_, bufnr) + require("tailwindcss-colors").buf_attach(bufnr) + end, + }, - graphql = true, html = true, yamlls = { settings = { @@ -284,59 +254,7 @@ local servers = { }, }, - cmake = (1 == vim.fn.executable "cmake-language-server"), - - clangd = { - cmd = { - "clangd", - "--background-index", - "--suggest-missing-includes", - "--clang-tidy", - "--header-insertion=iwyu", - }, - init_options = { - clangdFileStatus = true, - }, - filetypes = { - "c", - "cpp", - }, - }, - - svelte = true, - - intelephense = true, - -- intelephense = { - -- init_options = { - -- licenceKey = get_intelephense_license(), - -- }, - -- }, - htmx = true, - templ = true, - gopls = { - settings = { - gopls = { - codelenses = { test = true }, - hints = inlays and { - assignVariableTypes = true, - compositeLiteralFields = true, - compositeLiteralTypes = true, - constantValues = true, - functionTypeParameters = true, - parameterNames = true, - rangeVariableTypes = true, - } or nil, - }, - }, - - flags = { - debounce_text_changes = 200, - }, - }, - - rust_analyzer = rust_analyzer, - cssls = true, astro = true, @@ -363,28 +281,23 @@ local servers = { ts_util.setup { auto_inlay_hints = false } ts_util.setup_client(client) end, + diagnostics = { + virtual_text = function() + for _, client in ipairs(vim.lsp.get_clients { bufnr = 0 }) do + if client.name == "eslint" then + return false + end + end + return true + end, + }, }, } -- Can remove later if not installed (TODO: enable for not linux) -if vim.fn.executable "tree-sitter-grammar-lsp-linux" == 1 then - vim.api.nvim_create_autocmd({ "BufReadPost", "BufNewFile" }, { - pattern = { "grammar.js", "*/corpus/*.txt" }, - callback = function() - vim.lsp.start { - name = "tree-sitter-grammar-lsp", - cmd = { "tree-sitter-grammar-lsp-linux" }, - root_dir = "/", - capabilities = updated_capabilities, - on_attach = custom_attach, - } - end, - }) -end - require("mason").setup() require("mason-lspconfig").setup { - ensure_installed = { "lua_ls", "jsonls" }, + ensure_installed = { "lua_ls", "jsonls", "eslint", "ts_ls", "tailwindcss" }, } local setup_server = function(server, config) diff --git a/roles/neovim/files/work/lua/aome/lsp/inlay.lua b/roles/neovim/files/work/lua/aome/lsp/inlay.lua index 6155c87..12af297 100644 --- a/roles/neovim/files/work/lua/aome/lsp/inlay.lua +++ b/roles/neovim/files/work/lua/aome/lsp/inlay.lua @@ -48,11 +48,6 @@ require("inlay-hints").setup { vim.api.nvim_create_autocmd("LspAttach", { group = vim.api.nvim_create_augroup("my-inlay-hints", {}), callback = function(args) - local ft = vim.bo[args.buf].filetype - if ft ~= "go" then - return - end - local client = vim.lsp.get_client_by_id(args.data.client_id) require("inlay-hints").on_attach(client, args.buf) end, diff --git a/roles/neovim/files/work/lua/aome/lsp/mason/servers.lua b/roles/neovim/files/work/lua/aome/lsp/mason/servers.lua index 5434f61..73bd1eb 100644 --- a/roles/neovim/files/work/lua/aome/lsp/mason/servers.lua +++ b/roles/neovim/files/work/lua/aome/lsp/mason/servers.lua @@ -1,6 +1,4 @@ local servers = { - "clangd", - "clang-format", "typescript-language-server", "lua-language-server", "html-lsp", @@ -8,17 +6,7 @@ local servers = { "css-lsp", "tailwindcss-language-server", "svelte-language-server", - "graphql-language-service-cli", "emmet-ls", - "prisma-language-server", - "pyright", - "gopls", - -- "gofumpt", - -- "golines", - -- "goimports-reviser", - "gotests", - "gotestsum", - "rust-analyzer", "astro-language-server", "json-lsp", "eslint-lsp", @@ -28,16 +16,10 @@ local servers = { "prettierd", -- ts/js formatter "stylua", -- lua formatter "selene", - "ansible-language-server", - "ansible-lint", - "golangci-lint", "yaml-language-server", "yamllint", "bash-language-server", - "cmake-language-server", "shellcheck", - "templ", - "intelephense", "editorconfig-checker", } diff --git a/roles/neovim/files/work/lua/aome/snippets/ft/go.lua b/roles/neovim/files/work/lua/aome/snippets/ft/go.lua deleted file mode 100644 index e4334c4..0000000 --- a/roles/neovim/files/work/lua/aome/snippets/ft/go.lua +++ /dev/null @@ -1,211 +0,0 @@ -local ls = require "luasnip" - -local fmta = require("luasnip.extras.fmt").fmta -local rep = require("luasnip.extras").rep - -local s = ls.snippet -local c = ls.choice_node -local d = ls.dynamic_node -local i = ls.insert_node -local t = ls.text_node -local sn = ls.snippet_node - --- Map of default values for types. --- Some have a bit more complicated default values, --- but that's OK :) Lua is flexible enough! -local default_values = { - int = "0", - bool = "false", - string = '""', - - error = function(_, info) - if info then - info.index = info.index + 1 - - return c(info.index, { - t(info.err_name), - t( - string.format('errors.Wrap(%s, "%s")', info.err_name, info.func_name) - ), - }) - else - return t "err" - end - end, - - -- Types with a "*" mean they are pointers, so return nil - [function(text) - return string.find(text, "*", 1, true) ~= nil - end] = function(_, _) - return t "nil" - end, - - -- Convention: Usually no "*" and Capital is a struct type, so give the option - -- to have it be with {} as well. - [function(text) - return not string.find(text, "*", 1, true) - and string.upper(string.sub(text, 1, 1)) == string.sub(text, 1, 1) - end] = function(text, info) - info.index = info.index + 1 - - return c(info.index, { - t(text .. "{}"), - t(text), - }) - end, -} - ---- Transforms some text into a snippet node ----@param text string ----@param info table -local transform = function(text, info) - --- Determines whether the key matches the condition - local condition_matches = function(condition, ...) - if type(condition) == "string" then - return condition == text - else - return condition(...) - end - end - - -- Find the matching condition to get the correct default value - for condition, result in pairs(default_values) do - if condition_matches(condition, text, info) then - if type(result) == "string" then - return t(result) - else - return result(text, info) - end - end - end - - -- If no matches are found, just return the text, can fix up easily - return t(text) -end - --- Maps a node type to a handler function. -local handlers = { - parameter_list = function(node, info) - local result = {} - - local count = node:named_child_count() - for idx = 0, count - 1 do - local matching_node = node:named_child(idx) - local type_node = matching_node:field("type")[1] - table.insert( - result, - transform(vim.treesitter.get_node_text(type_node, 0), info) - ) - if idx ~= count - 1 then - table.insert(result, t { ", " }) - end - end - - return result - end, - - type_identifier = function(node, info) - local text = vim.treesitter.get_node_text(node, 0) - return { transform(text, info) } - end, -} - ---- Gets the corresponding result type based on the ---- current function context of the cursor. ----@param info table -local function go_result_type(info) - local function_node_types = { - function_declaration = true, - method_declaration = true, - func_literal = true, - } - - -- Find the first function node that's a parent of the cursor - local node = vim.treesitter.get_node() - while node ~= nil do - if function_node_types[node:type()] then - break - end - - node = node:parent() - end - - -- Exit if no match - if not node then - vim.notify "Not inside of a function" - return t "" - end - - -- This file is in `queries/go/return-snippet.scm` - local query = - assert(vim.treesitter.query.get("go", "return-snippet"), "No query") - for _, capture in query:iter_captures(node, 0) do - if handlers[capture:type()] then - return handlers[capture:type()](capture, info) - end - end -end - -local go_return_values = function(args) - return sn( - nil, - go_result_type { - index = 0, - err_name = args[1][1], - func_name = args[2][1], - } - ) -end - -ls.add_snippets("go", { - s( - "efi", - fmta( - [[ -, := () -if != nil { - return -} - -]], - { - val = i(1), - err = i(2, "err"), - f = i(3), - args = i(4), - err_same = rep(2), - result = d(5, go_return_values, { 2, 3 }), - finish = i(0), - } - ) - ), - s("ie", fmta("if err != nil {\n\treturn \n}", { err = i(1, "err") })), -}) - --- ls.add_snippets( --- "go", --- make { --- main = { --- t { "func main() {", "\t" }, --- i(0), --- t { "", "}" }, --- }, --- --- ef = { --- i(1, { "val" }), --- t ", err := ", --- i(2, { "f" }), --- t "(", --- i(3), --- t ")", --- i(0), --- }, --- --- -- TODO: Fix this up so that it actually uses the tree sitter thing --- ie = { "if err != nil {", "\treturn err", i(0), "}" }, --- } --- ) - --- ls.add_snippets("go", { --- s("f", fmt("func {}({}) {} {{\n\t{}\n}}", { i(1, "name"), i(2), i(3), i(0) })), --- }) diff --git a/roles/neovim/files/work/lua/aome/telescope/setup.lua b/roles/neovim/files/work/lua/aome/telescope/setup.lua index 3b6743d..ffc5d66 100644 --- a/roles/neovim/files/work/lua/aome/telescope/setup.lua +++ b/roles/neovim/files/work/lua/aome/telescope/setup.lua @@ -22,7 +22,6 @@ telescope.setup { }, }, file_ignore_patterns = { - "node_modules/", "%.git/", "%.DS_Store$", "target/", diff --git a/roles/neovim/files/work/lua/custom/plugins/editor/colorizer.lua b/roles/neovim/files/work/lua/custom/plugins/editor/colorizer.lua index 834e917..2cf1e31 100644 --- a/roles/neovim/files/work/lua/custom/plugins/editor/colorizer.lua +++ b/roles/neovim/files/work/lua/custom/plugins/editor/colorizer.lua @@ -1,27 +1,8 @@ return { - "NvChad/nvim-colorizer.lua", - cmd = "ColorizerToggle", - keys = { - { - "ct", - "ColorizerToggle", - desc = "[Colorizer] Toggle colorizer", - }, - }, + "themaxmarchuk/tailwindcss-colors.nvim", + event = { "BufReadPre *.{js,ts,jsx,tsx}", "BufNewFile *.{js,ts,jsx,tsx}" }, + ft = { "javascript", "typescript", "javascriptreact", "typescriptreact" }, config = function() - local colorizer = require "colorizer" - - colorizer.setup { - user_default_options = { - RRGGBBAA = true, - AARRGGBB = true, - tailwind = true, - rgb_fn = true, - hsl_fn = true, - css = true, - css_fn = true, - names = false, - }, - } + require("tailwindcss-colors").setup() end, } diff --git a/roles/neovim/files/work/lua/custom/plugins/editor/comment.lua b/roles/neovim/files/work/lua/custom/plugins/editor/comment.lua index e11489c..910c6ff 100644 --- a/roles/neovim/files/work/lua/custom/plugins/editor/comment.lua +++ b/roles/neovim/files/work/lua/custom/plugins/editor/comment.lua @@ -1,42 +1,5 @@ return { - "numToStr/Comment.nvim", - dependencies = { "JoosepAlviste/nvim-ts-context-commentstring" }, - lazy = true, - keys = { - { "gcc", desc = "Comment current line" }, - { "gc", mode = "v", desc = "Comment selected text" }, - }, - config = function() - local comment = require "Comment" - comment.setup { - pre_hook = function(ctx) - -- Only calculate commentstring for tsx filetypes - if vim.bo.filetype == "typescriptreact" then - local utils = require "Comment.utils" - - -- Determine whether to use linewise or blockwise commentstring - local type = ctx.ctype == utils.ctype.linewise and "__default" - or "__multiline" - - -- Determine the location where to calculate commentstring from - local location = nil - if ctx.ctype == utils.ctype.blockwise then - location = - require("ts_context_commentstring.utils").get_cursor_location() - elseif - ctx.cmotion == utils.cmotion.v - or ctx.cmotion == utils.cmotion.V - then - location = - require("ts_context_commentstring.utils").get_visual_start_location() - end - - return require("ts_context_commentstring.internal").calculate_commentstring { - key = type, - location = location, - } - end - end, - } - end, + "folke/ts-comments.nvim", + event = "VeryLazy", + enabled = vim.fn.has "nvim-0.10.0" == 1, } diff --git a/roles/neovim/files/work/lua/custom/plugins/editor/fugitive.lua b/roles/neovim/files/work/lua/custom/plugins/editor/fugitive.lua index aa7da1c..5689b9a 100644 --- a/roles/neovim/files/work/lua/custom/plugins/editor/fugitive.lua +++ b/roles/neovim/files/work/lua/custom/plugins/editor/fugitive.lua @@ -3,6 +3,8 @@ return { lazy = true, cmd = { "G", "Git" }, keys = { - { "gs", "tab Git", desc = "Git status" }, + { "gs", "tab Git", desc = "[g]it [s]tatus" }, + { "GD", "Gvdiff", desc = "[G]it [D]iff" }, + { "GM", "Gvdiffsplit!", desc = "[G]it [M]erge" }, }, } diff --git a/roles/neovim/files/work/lua/custom/plugins/editor/neotest.lua b/roles/neovim/files/work/lua/custom/plugins/editor/neotest.lua deleted file mode 100644 index dc5372e..0000000 --- a/roles/neovim/files/work/lua/custom/plugins/editor/neotest.lua +++ /dev/null @@ -1,58 +0,0 @@ -return { - "nvim-neotest/neotest", - dependencies = { - "nvim-neotest/nvim-nio", - "antoinemadec/FixCursorHold.nvim", - "nvim-treesitter/nvim-treesitter", - -- adapters -- - "nvim-neotest/neotest-go", - "nvim-neotest/neotest-jest", - "marilari88/neotest-vitest", - }, - keys = { - { - "tr", - "lua require('neotest').run.run()", - desc = "[t]est [r]un", - }, - { - "tf", - "lua require('neotest').run.run(vim.fn.expand('%')", - desc = "[t]est [f]ile", - }, - { - "tK", - "lua require('neotest').output.open()", - desc = "[t]est [K]hover", - }, - { - "tO", - "lua require('neotest').summary.toggle()", - desc = "[t]est [O]pen summary", - }, - }, - config = function() - local neotest = require "neotest" - ---@diagnostic disable-next-line: missing-fields - neotest.setup { - adapters = { - require "neotest-go" { - recursive_run = true, - }, - require "neotest-jest" { - jestCommand = require("neotest-jest.jest-util").getJestCommand( - vim.fn.expand "%:p:h" - ) .. " --watch", - }, - require "neotest-vitest" { - -- Filter directories when searching for test files. Useful in large projects (see Filter directories notes). - ---@diagnostic disable-next-line: unused-local - filter_dir = function(name, rel_path, root) - return name ~= "node_modules" - end, - vitestCommand = "vitest --watch", - }, - }, - } - end, -} diff --git a/roles/neovim/files/work/lua/custom/plugins/editor/surround.lua b/roles/neovim/files/work/lua/custom/plugins/editor/surround.lua deleted file mode 100644 index e3c3c6c..0000000 --- a/roles/neovim/files/work/lua/custom/plugins/editor/surround.lua +++ /dev/null @@ -1,6 +0,0 @@ -return { - "kylechui/nvim-surround", - event = { "BufReadPre", "BufNewFile" }, - version = "*", - config = true, -} diff --git a/roles/neovim/files/work/lua/custom/plugins/editor/telescope.lua b/roles/neovim/files/work/lua/custom/plugins/editor/telescope.lua index 6dcca26..9d4ec19 100644 --- a/roles/neovim/files/work/lua/custom/plugins/editor/telescope.lua +++ b/roles/neovim/files/work/lua/custom/plugins/editor/telescope.lua @@ -9,10 +9,7 @@ return { build = "make", }, }, - lazy = true, - cmd = { - "Telescope", - }, + lazy = false, config = function() require "aome.telescope.setup" require "aome.telescope.keys" diff --git a/roles/neovim/files/work/lua/custom/plugins/editor/toggleterm.lua b/roles/neovim/files/work/lua/custom/plugins/editor/toggleterm.lua deleted file mode 100644 index bc2a413..0000000 --- a/roles/neovim/files/work/lua/custom/plugins/editor/toggleterm.lua +++ /dev/null @@ -1,21 +0,0 @@ -local highlights = require "rose-pine.plugins.toggleterm" -return { - "akinsho/toggleterm.nvim", - cmd = { "ToggleTerm" }, - keys = { - { "", "ToggleTerm", desc = "[t]oggle [t]erminal" }, - }, - opts = { - highlights = highlights, - open_mapping = [[]], - direction = "float", - insert_mappings = false, - float_opts = { - border = "curved", - title_pos = "center", - width = math.floor((vim.o.columns / 2) + 50), - height = vim.o.lines - 10, - winblend = 0, - }, - }, -} diff --git a/roles/neovim/files/work/lua/custom/plugins/editor/treesitter.lua b/roles/neovim/files/work/lua/custom/plugins/editor/treesitter.lua index 8c71435..598e69d 100644 --- a/roles/neovim/files/work/lua/custom/plugins/editor/treesitter.lua +++ b/roles/neovim/files/work/lua/custom/plugins/editor/treesitter.lua @@ -45,50 +45,12 @@ return { "vimdoc", "dockerfile", "gitignore", - "php", - "go", - "rust", - "c", "astro", "jsdoc", "http", "xml", - "templ", }, auto_install = true, } - - local ok, ts_context_commentstring = - pcall(require, "ts_context_commentstring") - if not ok then - vim.notify("Tresitter context comment string not loaded", 3) - return - end - ts_context_commentstring.setup { - commentary_integration = { - Commentary = "gc", - CommentaryLine = "gcc", - ChangeCommentary = "cgc", - CommentaryUndo = "gcu", - }, - enable_autocmd = false, - languages = { - typescript = "// %s", - }, - config = {}, - } - local treesitter_parser_config = - require("nvim-treesitter.parsers").get_parser_configs() - - ---@diagnostic disable-next-line: inject-field - treesitter_parser_config.templ = { - install_info = { - url = "https://github.com/vrischmann/tree-sitter-templ.git", - files = { "src/parser.c", "src/scanner.c" }, - branch = "master", - }, - } - - vim.treesitter.language.register("templ", "templ") end, } diff --git a/roles/neovim/files/work/lua/custom/plugins/lsp/none-ls.lua b/roles/neovim/files/work/lua/custom/plugins/lsp/none-ls.lua index c20c82b..e8afc97 100644 --- a/roles/neovim/files/work/lua/custom/plugins/lsp/none-ls.lua +++ b/roles/neovim/files/work/lua/custom/plugins/lsp/none-ls.lua @@ -28,18 +28,12 @@ return { ".git", "package.json", "selene.toml", - ".luacheck", - "ansible.cfg" + ".luacheck" ), -- setup formatters & linters sources = { -- formatting formatting.stylua, - -- formatting.gofumpt, - -- formatting.goimports_reviser, - -- formatting.golines, - formatting.gofmt, - formatting.clang_format, formatting.biome.with { condition = function(utils) return utils.root_has_file { "biome.json", "biome.jsonc" } @@ -86,14 +80,6 @@ return { } end, }, - -- formatting.prettierd.with { - -- condition = function(utils) - -- return utils.root_has_file { "pnpm-lock.yaml", "package-lock.json" } - -- and not utils.root_has_file { "biome.json", "biome.jsonc" } - -- end, - -- }, - formatting.phpcsfixer, - diagnostics.markdownlint.with { condition = function(utils) return utils.root_has_file { ".markdownlint.json" } @@ -106,7 +92,6 @@ return { return utils.root_has_file { "cspell.json", ".cspell.json" } end, }, - -- require "none-ls.diagnostics.stylua", require("none-ls.code_actions.eslint_d").with { condition = function(utils) return utils.root_has_file { "pnpm-lock.yaml", "package-lock.json", "yarn.lock" } @@ -123,16 +108,6 @@ return { diagnostics.codespell.with { filetypes = { "markdown", "text" }, }, - diagnostics.ansiblelint.with { - condition = function(utils) - return utils.root_has_file { "ansible.cfg" } - end, - }, - diagnostics.golangci_lint.with { - condition = function(utils) - return utils.root_has_file { ".golangci.yml", ".golangci.yaml" } - end, - }, diagnostics.markdownlint.with { condition = function(utils) return utils.root_has_file { ".markdownlint.json" } @@ -149,12 +124,6 @@ return { and not utils.root_has_file { ".luacheckrc" } end, }, - require("none-ls-luacheck.diagnostics.luacheck").with { - condition = function(utils) - return utils.root_has_file { ".luacheckrc" } - and not utils.root_has_file { "selene.toml", ".selene.toml" } - end, - }, require("none-ls.diagnostics.eslint_d").with { filetypes = { "javascript", diff --git a/roles/neovim/files/work/lua/custom/plugins/lsp/nvim-cmp.lua b/roles/neovim/files/work/lua/custom/plugins/lsp/nvim-cmp.lua index 8dd35c0..974d8e6 100644 --- a/roles/neovim/files/work/lua/custom/plugins/lsp/nvim-cmp.lua +++ b/roles/neovim/files/work/lua/custom/plugins/lsp/nvim-cmp.lua @@ -41,9 +41,8 @@ return { cmp.setup { sources = { { name = "lazydev", group_index = 0 }, - { name = "gitmoji" }, - { name = "supermaven" }, { name = "nvim_lsp" }, + { name = "gitmoji" }, { name = "path" }, { name = "buffer" }, -- text within current buffer }, @@ -68,7 +67,5 @@ return { ), }, } - - vim.api.nvim_set_hl(0, "CmpItemKindSupermaven", { fg = "#44bdff" }) end, } diff --git a/roles/neovim/files/work/lua/custom/plugins/lsp/supermaven.lua b/roles/neovim/files/work/lua/custom/plugins/lsp/supermaven.lua index d8af1ce..91bbb3b 100644 --- a/roles/neovim/files/work/lua/custom/plugins/lsp/supermaven.lua +++ b/roles/neovim/files/work/lua/custom/plugins/lsp/supermaven.lua @@ -1,6 +1,5 @@ return { "supermaven-inc/supermaven-nvim", - -- event = "VeryLazy", lazy = false, config = function() require("supermaven-nvim").setup { @@ -12,16 +11,6 @@ return { cterm = vim.api.nvim_get_hl(0, { name = "NonText" }).cterm, suggestion_group = "NonText", }, - condition = function() - local filename = vim.fn.expand "%:t:r" - local ignored_filanames = { "local", "private", "cache", ".env" } - for _, ignored in ipairs(ignored_filanames) do - if string.find(filename, ignored) then - return true - end - end - end, - dot_repeat = true, ignore_filetypes = { alpha = true, man = true, @@ -36,5 +25,4 @@ return { log_level = "off", } end, - dev = true, } diff --git a/roles/neovim/files/work/lua/custom/plugins/ui/alpha.lua b/roles/neovim/files/work/lua/custom/plugins/ui/alpha.lua deleted file mode 100644 index d8fab8a..0000000 --- a/roles/neovim/files/work/lua/custom/plugins/ui/alpha.lua +++ /dev/null @@ -1,101 +0,0 @@ -return { - "goolord/alpha-nvim", - event = "VimEnter", - dependencies = { "nvim-tree/nvim-web-devicons" }, - config = function() - local alpha = require "alpha" - local dashboard = require "alpha.themes.dashboard" - - local lazy_path = vim.fn.stdpath "config" .. "/lua/aome/lazy.lua" - local nvim_version = "v" - .. vim.version().major - .. "." - .. vim.version().minor - .. "." - .. vim.version().patch - - ---Adds zero if the number is less than 10 - ---@param number string|integer - ---@return string number - local add_zero = function(number) - if number < 10 then - return 0 .. number - end - return tostring(number) - end - - local get_date = function() - local date = os.date "*t" - local formatted_date = add_zero(date.day) - .. "-" - .. add_zero(date.month) - .. "-" - .. date.year - .. " | " - .. add_zero(date.hour) - .. ":" - .. add_zero(date.min) - return formatted_date - end - - local header = dashboard.section.header - local footer = dashboard.section.footer - local buttons = dashboard.section.buttons - - local plugins = #vim.tbl_keys(require("lazy").plugins()) - local datetime = get_date() - local info = string.format(" %d plugins at %s", plugins, datetime) - local version = string.format("NVIM Version %s", nvim_version) - - local fortune = require "alpha.fortune"() - - -- Set header - header.val = { - "╭────────────────── 青目 ──────────────────╮", - "│ │", - "│ 󰝚 I'm Blue da ba dee da ba daa 󰝚 │", - "│ │", - "│ ┌─┐┌─┐┌┬┐┌─┐ │", - "╰────────────── ├─┤│ ││││├┤ ──────────────╯", - " ┴ ┴└─┘┴ ┴└─┘ ", - } - - -- Set menu - buttons.val = { - dashboard.button("e", " > New File", ":e "), - dashboard.button("SPC ee", " > Toggle file explorer", "Ex"), - dashboard.button( - "SPC pf", - "󰱼 > Find File", - "Telescope find_files" - ), - dashboard.button( - "SPC ps", - " > Find Word", - "lua require('aome.telescope').grep_prompt()" - ), - dashboard.button( - "SPC epp", - "󱇧 > Edit lazy.lua", - "e " .. lazy_path .. "" - ), - dashboard.button("q", " > Quit NVIM", "qa"), - } - - ---@type string[] - footer.val = { - " ", - info, - version, - } - for _, text in pairs(fortune) do - table.insert(footer.val, text) - end - - -- Send config to alpha - alpha.setup(dashboard.opts) - - -- Disable folding on alpha buffer - vim.cmd [[autocmd FileType alpha setlocal nofoldenable]] - end, -} diff --git a/roles/neovim/files/work/lua/custom/plugins/ui/colorscheme-installer.lua b/roles/neovim/files/work/lua/custom/plugins/ui/colorscheme-installer.lua deleted file mode 100644 index 4a3a6de..0000000 --- a/roles/neovim/files/work/lua/custom/plugins/ui/colorscheme-installer.lua +++ /dev/null @@ -1,8 +0,0 @@ -return { - "AlejandroSuero/colorscheme-installer.nvim", - lazy = false, - dev = true, - config = function() - require("colorscheme-installer").setup() - end, -} diff --git a/roles/neovim/files/work/lua/custom/plugins/ui/freeze.lua b/roles/neovim/files/work/lua/custom/plugins/ui/freeze.lua deleted file mode 100644 index b320680..0000000 --- a/roles/neovim/files/work/lua/custom/plugins/ui/freeze.lua +++ /dev/null @@ -1,57 +0,0 @@ -return { - -- { - -- "ethanholz/freeze.nvim", - -- config = true, - -- opts = { - -- theme = "rose-pine-moon", - -- copy = true, - -- open = true, - -- }, - -- event = "verylazy", - -- keys = { - -- { "fz", "freeze", desc = "[f]ree[z]e file" }, - -- { - -- "fz", - -- "freezeline", - -- desc = "[f]ree[z]e line", - -- mode = "v", - -- }, - -- }, - -- dev = true, - -- }, - { - "AlejandroSuero/freeze-code.nvim", - keys = { - { - "fz", - function() - require("freeze-code.utils.api").freeze() - end, - desc = "[f]ree[z]e file", - }, - { - "fz", - function() - require("freeze-code.utils.api").freeze(vim.fn.line ".", vim.fn.line "v") - end, - desc = "[f]ree[z]e line", - mode = "v", - }, - { - "fz", - function() - require("freeze-code.utils.api").freeze_line() - end, - desc = "[f]ree[z]e current line", - }, - }, - config = function() - require("freeze-code").setup { - freeze_config = { - config = "user", - }, - } - end, - dev = true, - }, -} diff --git a/roles/neovim/files/work/lua/custom/plugins/ui/lualine.lua b/roles/neovim/files/work/lua/custom/plugins/ui/lualine.lua index c766f62..65e0216 100644 --- a/roles/neovim/files/work/lua/custom/plugins/ui/lualine.lua +++ b/roles/neovim/files/work/lua/custom/plugins/ui/lualine.lua @@ -38,6 +38,19 @@ local get_date = function() return formatted_date end +---Gets if the current file is in a ts server component +---@return boolean is_ts_server_component +local get_if_ts_server_component = function() + local path = vim.fn.expand "%:h" + local splitted_path = vim.split(path, "/") + for _, route in ipairs(splitted_path) do + if string.find(route, "[%[%]]") then + return true + end + end + return false +end + ---Gets the filename and if modified or not ---@param reverse boolean ---@return string filename_and_status - A modified or not status with the filename @@ -50,6 +63,13 @@ local get_filename_and_status = function(reverse) end if reverse == true then + if vim.bo.ft:find "react" then + if get_if_ts_server_component() then + return " server component " + else + return " client component " + end + end return string.format("%s %s", file_status, filename) else return string.format("%s %s", filename, file_status) @@ -123,7 +143,7 @@ return { inactive_winbar = { lualine_z = { function() - return get_filename_and_status(false) + return get_filename_and_status(true) end, }, }, diff --git a/roles/neovim/files/work/lua/custom/plugins/ui/pr.lua b/roles/neovim/files/work/lua/custom/plugins/ui/pr.lua deleted file mode 100644 index 086df41..0000000 --- a/roles/neovim/files/work/lua/custom/plugins/ui/pr.lua +++ /dev/null @@ -1,8 +0,0 @@ -return { - "AlejandroSuero/pr.nvim", - event = "VeryLazy", - config = function() - require("pr").setup() - end, - dev = true, -} diff --git a/roles/neovim/files/work/lua/custom/plugins/ui/trouble.lua b/roles/neovim/files/work/lua/custom/plugins/ui/trouble.lua index 7bb0bb2..2e39c75 100644 --- a/roles/neovim/files/work/lua/custom/plugins/ui/trouble.lua +++ b/roles/neovim/files/work/lua/custom/plugins/ui/trouble.lua @@ -4,9 +4,25 @@ return { keys = { { "tq", - "Trouble diagnostics toggle focus=false", + "Trouble diagnostics toggle focus=true", { desc = "[t]rouble [q]uickfix" }, }, + { + "n", + function() + vim.cmd "Trouble diagnostics next" + vim.cmd "Trouble diagnostics jump" + end, + { desc = "[t]rouble [n]ext" }, + }, + { + "N", + function() + vim.cmd "Trouble diagnostics prev" + vim.cmd "Trouble diagnostics jump" + end, + { desc = "[t]rouble [n]ext" }, + }, }, config = function() local trouble = require "trouble"