diff --git a/vim/lua/commands.lua b/vim/lua/commands.lua index 64f8416..3cd417a 100644 --- a/vim/lua/commands.lua +++ b/vim/lua/commands.lua @@ -1,52 +1,61 @@ function _G.dump(...) - local objects = vim.tbl_map(vim.inspect, {...}) - print(unpack(objects)) - return ... + local objects = vim.tbl_map(vim.inspect, { ... }) + print(unpack(objects)) + return ... end function _G.insert_uuid() - local uuid = vim.fn.system("uuidprint") - local errcode = vim.v.shell_error - if errcode ~= 0 then - vim.api.nvim_err_writeln("uuidprint returned error code: " .. errcode) - return - end + local uuid = vim.fn.system("uuidprint") + local errcode = vim.v.shell_error + if errcode ~= 0 then + vim.api.nvim_err_writeln("uuidprint returned error code: " .. errcode) + return + end - vim.fn.setreg("u", uuid) - vim.api.nvim_command([[normal! "up]]) + vim.fn.setreg("u", uuid) + vim.api.nvim_command([[normal! "up]]) end -vim.api.nvim_set_keymap("n", "pu", [[:lua _G.insert_uuid()]], {noremap = true, silent = true}) -vim.api.nvim_set_keymap("i", "", [[:lua _G.insert_uuid()a]], {noremap = true, silent = true}) +vim.api.nvim_set_keymap("n", "pu", [[:lua _G.insert_uuid()]], { noremap = true, silent = true }) +vim.api.nvim_set_keymap("i", "", [[:lua _G.insert_uuid()a]], { noremap = true, silent = true }) function _G.insert_jira_url() - local url = vim.fn.system("jira") - local errcode = vim.v.shell_error - if errcode ~= 0 then - vim.api.nvim_err_writeln("jira returned error code: " .. errcode) - return - end + local url = vim.fn.system("jira") + local errcode = vim.v.shell_error + if errcode ~= 0 then + vim.api.nvim_err_writeln("jira returned error code: " .. errcode) + return + end - vim.fn.setreg("u", url) - vim.api.nvim_command([[normal! "up]]) + vim.fn.setreg("u", url) + vim.api.nvim_command([[normal! "up]]) end -vim.api.nvim_set_keymap("n", "pj", [[:lua _G.insert_jira_url()]], {noremap = true, silent = true}) -vim.api.nvim_set_keymap("i", "", [[:lua _G.insert_jira_url()a]], {noremap = true, silent = true}) +vim.api.nvim_set_keymap("n", "pj", [[:lua _G.insert_jira_url()]], { noremap = true, silent = true }) +vim.api.nvim_set_keymap("i", "", [[:lua _G.insert_jira_url()a]], { noremap = true, silent = true }) function _G.insert_iso8601_timestamp() - local ts = vim.fn.system("echo -n $(date --iso-8601=seconds)") + local ts = vim.fn.system("echo -n $(date --iso-8601=seconds)") - local errcode = vim.v.shell_error - if errcode ~= 0 then - vim.api.nvim_err_writeln("date returned error code: " .. errcode) - return - end + local errcode = vim.v.shell_error + if errcode ~= 0 then + vim.api.nvim_err_writeln("date returned error code: " .. errcode) + return + end - vim.fn.setreg("u", ts) - vim.api.nvim_command([[normal! "up]]) + vim.fn.setreg("u", ts) + vim.api.nvim_command([[normal! "up]]) end - -vim.api.nvim_set_keymap("n", "pt", [[:lua _G.insert_iso8601_timestamp()]], {noremap = true, silent = true}) -vim.api.nvim_set_keymap("i", "", [[:lua _G.insert_iso8601_timestamp()a]], {noremap = true, silent = true}) +vim.api.nvim_set_keymap( + "n", + "pt", + [[:lua _G.insert_iso8601_timestamp()]], + { noremap = true, silent = true } +) +vim.api.nvim_set_keymap( + "i", + "", + [[:lua _G.insert_iso8601_timestamp()a]], + { noremap = true, silent = true } +) diff --git a/vim/lua/copilot_config.lua b/vim/lua/copilot_config.lua index 9d9cfa3..4a4828f 100644 --- a/vim/lua/copilot_config.lua +++ b/vim/lua/copilot_config.lua @@ -1,11 +1,11 @@ vim.defer_fn(function() - require('copilot').setup({ - panel = { - enabled = false, - auto_refresh = true, - }, - suggestion = { - enabled = false, - }, - }) + require("copilot").setup({ + panel = { + enabled = false, + auto_refresh = true, + }, + suggestion = { + enabled = false, + }, + }) end, 100) diff --git a/vim/lua/formatter_config.lua b/vim/lua/formatter_config.lua index bc46884..5a4baee 100644 --- a/vim/lua/formatter_config.lua +++ b/vim/lua/formatter_config.lua @@ -1,33 +1,36 @@ local prettier = function() - return { - exe = Get_project_node_modules_path() .. "/.bin/prettier", - args = {"--stdin-filepath", vim.api.nvim_buf_get_name(0), '--single-quote'}, - stdin = true - } + return { + exe = Get_project_node_modules_path() .. "/.bin/prettier", + args = { "--stdin-filepath", vim.api.nvim_buf_get_name(0), "--single-quote" }, + stdin = true, + } end -require('formatter').setup({ - log_level = vim.log.levels.INFO, - filetype = { - javascript = { prettier }, - typescript = { prettier }, - typescriptreact = { prettier }, +require("formatter").setup({ + log_level = vim.log.levels.INFO, + filetype = { + javascript = { prettier }, + typescript = { prettier }, + typescriptreact = { prettier }, - -- https://github.com/JohnnyMorganz/StyLua - -- cargo install stylua --features lua54 - lua = { - require("formatter.filetypes.lua").stylua - }, - } + -- https://github.com/JohnnyMorganz/StyLua + -- cargo install stylua --features lua54 + lua = { + require("formatter.filetypes.lua").stylua, + }, + }, }) -- TODO: use vim.api.nvim_create_augroup() -vim.api.nvim_exec2([[ +vim.api.nvim_exec2( + [[ augroup FormatAutogroup autocmd! autocmd BufWritePost *.js,*.ts,*.tsx,*.lua silent FormatWrite augroup END -]], { output = true }) +]], + { output = true } +) local bufnr = vim.fn.bufnr("%") -vim.api.nvim_buf_set_keymap(bufnr, 'n', 'F', 'silent Format', { noremap=true, silent=true }) +vim.api.nvim_buf_set_keymap(bufnr, "n", "F", "silent Format", { noremap = true, silent = true }) diff --git a/vim/lua/helpers.lua b/vim/lua/helpers.lua index 9668f97..edf7b7d 100644 --- a/vim/lua/helpers.lua +++ b/vim/lua/helpers.lua @@ -1,12 +1,12 @@ -- Return the node_modules path for this project. If the project root contains a -- frontend/ directory, assume node_modules lives there. function Get_project_node_modules_path() - local root_path = vim.fn.getcwd() - local frontend_path = root_path .. "/frontend" - local is_frontend = vim.fn.isdirectory(frontend_path) ~= 0 - local base_path = root_path - if is_frontend then - base_path = frontend_path - end - return base_path .. "/node_modules" + local root_path = vim.fn.getcwd() + local frontend_path = root_path .. "/frontend" + local is_frontend = vim.fn.isdirectory(frontend_path) ~= 0 + local base_path = root_path + if is_frontend then + base_path = frontend_path + end + return base_path .. "/node_modules" end diff --git a/vim/lua/lsp_config.lua b/vim/lua/lsp_config.lua index b04323d..28f0cc0 100644 --- a/vim/lua/lsp_config.lua +++ b/vim/lua/lsp_config.lua @@ -1,179 +1,179 @@ -local nvim_lsp = require('lspconfig') +local nvim_lsp = require("lspconfig") local on_attach = function(client, bufnr) - -- TODO: use vim.api.nvim_create_autocmd - vim.api.nvim_exec2([[autocmd User LspDiagnosticsChanged call lightline#update()]], { output = false }) + -- TODO: use vim.api.nvim_create_autocmd + vim.api.nvim_exec2([[autocmd User LspDiagnosticsChanged call lightline#update()]], { output = false }) - local opts = { noremap=true, silent=false } - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.type_definition()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.type_definition()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'e', 'lua vim.lsp.buf.rename()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'r', 'lua vim.lsp.buf.references()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'i', 'lua vim.lsp.buf.implementation()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ca', 'lua vim.lsp.buf.code_action()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ci', 'lua vim.lsp.buf.incoming_calls()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'co', 'lua vim.lsp.buf.outgoing_calls()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', ']e', 'lua vim.diagnostic.goto_next({severity="Error"})', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', '[e', 'lua vim.diagnostic.goto_prev({severity="Error"})', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', ']d', 'lua vim.diagnostic.goto_next()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', '[d', 'lua vim.diagnostic.goto_prev()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'cd', 'lua vim.diagnostic.hide(nil, 0)', opts) + local opts = { noremap = true, silent = false } + vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "lua vim.lsp.buf.definition()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "lua vim.lsp.buf.type_definition()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "lua vim.lsp.buf.definition()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "lua vim.lsp.buf.type_definition()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "e", "lua vim.lsp.buf.rename()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "r", "lua vim.lsp.buf.references()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "i", "lua vim.lsp.buf.implementation()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "ca", "lua vim.lsp.buf.code_action()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "ci", "lua vim.lsp.buf.incoming_calls()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "co", "lua vim.lsp.buf.outgoing_calls()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "lua vim.lsp.buf.hover()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "]e", 'lua vim.diagnostic.goto_next({severity="Error"})', opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "[e", 'lua vim.diagnostic.goto_prev({severity="Error"})', opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "]d", "lua vim.diagnostic.goto_next()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "[d", "lua vim.diagnostic.goto_prev()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "cd", "lua vim.diagnostic.hide(nil, 0)", opts) - -- fzf triggers: - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'fr', 'References', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'fi', 'Implementations', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'fs', 'DocumentSymbols', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'fw', 'WorkspaceSymbols', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'fc', 'CodeActions', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'fci', 'IncomingCalls', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'fco', 'OutgoingCalls', opts) + -- fzf triggers: + vim.api.nvim_buf_set_keymap(bufnr, "n", "fr", "References", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "fi", "Implementations", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "fs", "DocumentSymbols", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "fw", "WorkspaceSymbols", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "fc", "CodeActions", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "fci", "IncomingCalls", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "fco", "OutgoingCalls", opts) - require 'lsp_signature'.on_attach({ - hint_enable = false, - }) + require("lsp_signature").on_attach({ + hint_enable = false, + }) - require 'copilot_cmp'.setup(); + require("copilot_cmp").setup() end -- Go -local capabilities = require('cmp_nvim_lsp').default_capabilities() +local capabilities = require("cmp_nvim_lsp").default_capabilities() capabilities.textDocument.completion.completionItem.snippetSupport = true capabilities.textDocument.completion.completionItem.resolveSupport = { - properties = { - 'documentation', - 'detail', - 'additionalTextEdits', - } + properties = { + "documentation", + "detail", + "additionalTextEdits", + }, } -nvim_lsp.gopls.setup{ - settings = { - gopls = { - staticcheck = true, - -- Disalbing linksInHover may not be working as expected: - linksInHover = false, - usePlaceholders = true, - analyses = { - unusedparams = true, - shadow = true, - unusedwrite = true, - unusedresult = true, - nilness = true, - }, - }, - }, - capabilities = capabilities, - on_attach = on_attach, -} +nvim_lsp.gopls.setup({ + settings = { + gopls = { + staticcheck = true, + -- Disalbing linksInHover may not be working as expected: + linksInHover = false, + usePlaceholders = true, + analyses = { + unusedparams = true, + shadow = true, + unusedwrite = true, + unusedresult = true, + nilness = true, + }, + }, + }, + capabilities = capabilities, + on_attach = on_attach, +}) -- Rust -nvim_lsp.rust_analyzer.setup{ - capabilities = capabilities, - on_attach = on_attach, - settings = { - ["rust-analyzer"] = { - imports = { - granularity = { - group = "module", - }, - prefix = "self", - }, - cargo = { - buildScripts = { - enable = true, - }, - }, - procMacro = { - enable = false, - }, - diagnostics = { - disabled = { "unresolved-proc-macro" }, - } - } - } -} +nvim_lsp.rust_analyzer.setup({ + capabilities = capabilities, + on_attach = on_attach, + settings = { + ["rust-analyzer"] = { + imports = { + granularity = { + group = "module", + }, + prefix = "self", + }, + cargo = { + buildScripts = { + enable = true, + }, + }, + procMacro = { + enable = false, + }, + diagnostics = { + disabled = { "unresolved-proc-macro" }, + }, + }, + }, +}) -- Ruby -nvim_lsp.solargraph.setup{ - on_attach = on_attach, -} +nvim_lsp.solargraph.setup({ + on_attach = on_attach, +}) -- Typescript -- https://jose-elias-alvarez.medium.com/configuring-neovims-lsp-client-for-typescript-development-5789d58ea9c -nvim_lsp.tsserver.setup{ - on_attach = on_attach, -} +nvim_lsp.tsserver.setup({ + on_attach = on_attach, +}) local filetypes = { - typescript = "eslint", - typescriptreact = "eslint", + typescript = "eslint", + typescriptreact = "eslint", } -- diagnosticls local linters = { - eslint = { - sourceName = "eslint", - -- fallback to global eslint if the local is not found? - -- https://github.com/creativenull/diagnosticls-configs-nvim/blob/e7d6f7e99f6b416d2aeee89314bc46fc36df7b22/lua/diagnosticls-configs/fs.lua#L20 - command = "./node_modules/.bin/eslint", - rootPatterns = {".eslintrc", ".eslintrc.js"}, - debounce = 100, - args = {"--stdin", "--stdin-filename", "%filepath", "--format", "json"}, - parseJson = { - errorsRoot = "[0].messages", - line = "line", - column = "column", - endLine = "endLine", - endColumn = "endColumn", - message = "${message} [${ruleId}]", - security = "severity" - }, - securities = {[1] = "error", [2] = "warning"} - } + eslint = { + sourceName = "eslint", + -- fallback to global eslint if the local is not found? + -- https://github.com/creativenull/diagnosticls-configs-nvim/blob/e7d6f7e99f6b416d2aeee89314bc46fc36df7b22/lua/diagnosticls-configs/fs.lua#L20 + command = "./node_modules/.bin/eslint", + rootPatterns = { ".eslintrc", ".eslintrc.js" }, + debounce = 100, + args = { "--stdin", "--stdin-filename", "%filepath", "--format", "json" }, + parseJson = { + errorsRoot = "[0].messages", + line = "line", + column = "column", + endLine = "endLine", + endColumn = "endColumn", + message = "${message} [${ruleId}]", + security = "severity", + }, + securities = { [1] = "error", [2] = "warning" }, + }, } -nvim_lsp.diagnosticls.setup{ - on_attach = on_attach, - filetypes = vim.tbl_keys(filetypes), - init_options = { - linters = linters, - filetypes = filetypes, - } -} +nvim_lsp.diagnosticls.setup({ + on_attach = on_attach, + filetypes = vim.tbl_keys(filetypes), + init_options = { + linters = linters, + filetypes = filetypes, + }, +}) -- Lua -local lua_ls_root_path = os.getenv("HOME").."/dev/lua-language-server" -local lua_ls_binary = lua_ls_root_path.."/bin/lua-language-server" +local lua_ls_root_path = os.getenv("HOME") .. "/dev/lua-language-server" +local lua_ls_binary = lua_ls_root_path .. "/bin/lua-language-server" -local runtime_path = vim.split(package.path, ';') +local runtime_path = vim.split(package.path, ";") table.insert(runtime_path, "lua/?.lua") table.insert(runtime_path, "lua/?/init.lua") -nvim_lsp.lua_ls.setup { - cmd = {lua_ls_binary, "-E", lua_ls_root_path .. "/main.lua"}; - settings = { - Lua = { - runtime = { - version = 'LuaJIT', - path = runtime_path, - }, - diagnostics = { - globals = {'vim'}, - }, - workspace = { - library = vim.api.nvim_get_runtime_file("", true), - }, - telemetry = { - enable = false, - }, - }, - }, - on_attach = on_attach, -} +nvim_lsp.lua_ls.setup({ + cmd = { lua_ls_binary, "-E", lua_ls_root_path .. "/main.lua" }, + settings = { + Lua = { + runtime = { + version = "LuaJIT", + path = runtime_path, + }, + diagnostics = { + globals = { "vim" }, + }, + workspace = { + library = vim.api.nvim_get_runtime_file("", true), + }, + telemetry = { + enable = false, + }, + }, + }, + on_attach = on_attach, +}) diff --git a/vim/lua/nvim_cmp_config.lua b/vim/lua/nvim_cmp_config.lua index 91ff9e2..a7db697 100644 --- a/vim/lua/nvim_cmp_config.lua +++ b/vim/lua/nvim_cmp_config.lua @@ -1,47 +1,48 @@ -local cmp = require('cmp') -local cmp_buffer = require('cmp_buffer') +local cmp = require("cmp") +local cmp_buffer = require("cmp_buffer") cmp.setup({ - completion = { - completeopt = 'menu,menuone,noinsert', - }, - snippet = { - expand = function(args) - vim.fn["vsnip#anonymous"](args.body) - end, - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.close(), - ['C-y'] = cmp.mapping.confirm({ select = true, behaviour = cmp.ConfirmBehavior.Replace }), - [''] = cmp.mapping.confirm({ select = true, behaviour = cmp.ConfirmBehavior.Replace }), - }), - sources = cmp.config.sources({ - { name = 'copilot', keyword_length = 0 }, - { name = 'nvim_lsp', keyword_length = 3 }, - { - name = 'buffer', - option = { - get_bufnrs = function() - return vim.api.nvim_list_bufs() - end - }, - }, - { name = 'path' }, - { name = 'calc' }, - }), - sorting = { - comparators = { - function(...) return cmp_buffer:compare_locality(...) end, - } - }, - view = { - entries = 'native', - }, - experimental = { - ghost_text = true, - }, + completion = { + completeopt = "menu,menuone,noinsert", + }, + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.close(), + ["C-y"] = cmp.mapping.confirm({ select = true, behaviour = cmp.ConfirmBehavior.Replace }), + [""] = cmp.mapping.confirm({ select = true, behaviour = cmp.ConfirmBehavior.Replace }), + }), + sources = cmp.config.sources({ + { name = "copilot", keyword_length = 0 }, + { name = "nvim_lsp", keyword_length = 3 }, + { + name = "buffer", + option = { + get_bufnrs = function() + return vim.api.nvim_list_bufs() + end, + }, + }, + { name = "path" }, + { name = "calc" }, + }), + sorting = { + comparators = { + function(...) + return cmp_buffer:compare_locality(...) + end, + }, + }, + view = { + entries = "native", + }, + experimental = { + ghost_text = true, + }, }) - diff --git a/vim/lua/test_runner.lua b/vim/lua/test_runner.lua index a836744..b6433fb 100644 --- a/vim/lua/test_runner.lua +++ b/vim/lua/test_runner.lua @@ -1,104 +1,109 @@ _G._test_cmd_to_wins = {} _G._build_test_cmd = function() - local bufnr = vim.fn.bufnr("%") - local filetype = vim.fn.getbufvar(bufnr, "&filetype") - if filetype == "" then - vim.api.nvim_err_writeln("cannot build test command for filetype:" .. filetype) - return nil - end + local bufnr = vim.fn.bufnr("%") + local filetype = vim.fn.getbufvar(bufnr, "&filetype") + if filetype == "" then + vim.api.nvim_err_writeln("cannot build test command for filetype:" .. filetype) + return nil + end - local path = vim.fn.expand("%:p") + local path = vim.fn.expand("%:p") - -- TODO: allow line number to be passed - -- TODO: check file exists before running command - if filetype == "ruby" then - if not path:find("_spec.rb") then - path = path:gsub("/app/", "/spec/"):gsub([[.rb$]], "_spec.rb") - end + -- TODO: allow line number to be passed + -- TODO: check file exists before running command + if filetype == "ruby" then + if not path:find("_spec.rb") then + path = path:gsub("/app/", "/spec/"):gsub([[.rb$]], "_spec.rb") + end - return "bundle exec rspec --format=progress --no-profile " .. path - elseif filetype == "go" then - return "go test -v " .. path:gsub("^(.*)/(.*go)$", "%1/...") - else - vim.api.nvim_err_writeln("filetype not supported: " .. filetype) - return nil - end + return "bundle exec rspec --format=progress --no-profile " .. path + elseif filetype == "go" then + return "go test -v " .. path:gsub("^(.*)/(.*go)$", "%1/...") + else + vim.api.nvim_err_writeln("filetype not supported: " .. filetype) + return nil + end end _G.run_tests = function() - local cmd = _G._build_test_cmd() - if cmd == nil then - return - end + local cmd = _G._build_test_cmd() + if cmd == nil then + return + end - vim.api.nvim_command([[silent up]]) + vim.api.nvim_command([[silent up]]) - local winid = _G._test_cmd_to_wins[cmd] - local current_winid = vim.fn.win_getid() - if winid == nil or not vim.api.nvim_win_is_valid(winid) or winid == current_winid or not vim.fn.win_gotoid(winid) == -1 then - vim.api.nvim_command([[10split]]) - winid = vim.fn.win_getid() - _G._test_cmd_to_wins[cmd] = winid - end + local winid = _G._test_cmd_to_wins[cmd] + local current_winid = vim.fn.win_getid() + if + winid == nil + or not vim.api.nvim_win_is_valid(winid) + or winid == current_winid + or not vim.fn.win_gotoid(winid) == -1 + then + vim.api.nvim_command([[10split]]) + winid = vim.fn.win_getid() + _G._test_cmd_to_wins[cmd] = winid + end - local buf = vim.api.nvim_create_buf(false, true) - vim.api.nvim_buf_set_option(buf, "bufhidden", "delete") - vim.api.nvim_win_set_buf(winid, buf) + local buf = vim.api.nvim_create_buf(false, true) + vim.api.nvim_buf_set_option(buf, "bufhidden", "delete") + vim.api.nvim_win_set_buf(winid, buf) - vim.fn.termopen(cmd) - vim.api.nvim_command([[normal! G]]) - vim.api.nvim_command([[wincmd p]]) + vim.fn.termopen(cmd) + vim.api.nvim_command([[normal! G]]) + vim.api.nvim_command([[wincmd p]]) end _G.focus_tests = function() - local cmd = _G._build_test_cmd() - if cmd == nil then - return - end + local cmd = _G._build_test_cmd() + if cmd == nil then + return + end - local winid = _G._test_cmd_to_wins[cmd] - if winid == nil or not vim.api.nvim_win_is_valid(winid) then - return - end + local winid = _G._test_cmd_to_wins[cmd] + if winid == nil or not vim.api.nvim_win_is_valid(winid) then + return + end - vim.fn.win_gotoid(winid) - vim.api.nvim_command([[wincmd =]]) + vim.fn.win_gotoid(winid) + vim.api.nvim_command([[wincmd =]]) end _G.close_tests = function() - local current_winid = vim.api.nvim_get_current_win() - for _, winid in pairs(_G._test_cmd_to_wins) do - if current_winid == winid and vim.api.nvim_win_is_valid(winid) then - vim.api.nvim_win_close(winid, false) - return - end - end + local current_winid = vim.api.nvim_get_current_win() + for _, winid in pairs(_G._test_cmd_to_wins) do + if current_winid == winid and vim.api.nvim_win_is_valid(winid) then + vim.api.nvim_win_close(winid, false) + return + end + end - local cmd = _G._build_test_cmd() - if cmd == nil then - return - end + local cmd = _G._build_test_cmd() + if cmd == nil then + return + end - local winid = _G._test_cmd_to_wins[cmd] - if winid == nil or not vim.api.nvim_win_is_valid(winid) then - return - end + local winid = _G._test_cmd_to_wins[cmd] + if winid == nil or not vim.api.nvim_win_is_valid(winid) then + return + end - vim.api.nvim_win_close(winid, false) + vim.api.nvim_win_close(winid, false) end _G.copy_test_cmd = function() - local cmd = _G._build_test_cmd() - if cmd == nil then - return - end + local cmd = _G._build_test_cmd() + if cmd == nil then + return + end - vim.fn.setreg("+", cmd) - print("Copied: " .. cmd) + vim.fn.setreg("+", cmd) + print("Copied: " .. cmd) end -vim.api.nvim_set_keymap("n", "cr", [[:lua _G.run_tests()]], {noremap = true, silent = true}) -vim.api.nvim_set_keymap("n", "cf", [[:lua _G.focus_tests()]], {noremap = true, silent = true}) -vim.api.nvim_set_keymap("n", "cq", [[:lua _G.close_tests()]], {noremap = true, silent = true}) -vim.api.nvim_set_keymap("n", "cc", [[:lua _G.copy_test_cmd()]], {noremap = true, silent = true}) +vim.api.nvim_set_keymap("n", "cr", [[:lua _G.run_tests()]], { noremap = true, silent = true }) +vim.api.nvim_set_keymap("n", "cf", [[:lua _G.focus_tests()]], { noremap = true, silent = true }) +vim.api.nvim_set_keymap("n", "cq", [[:lua _G.close_tests()]], { noremap = true, silent = true }) +vim.api.nvim_set_keymap("n", "cc", [[:lua _G.copy_test_cmd()]], { noremap = true, silent = true }) diff --git a/vim/lua/treesitter_config.lua b/vim/lua/treesitter_config.lua index 6305f06..eabcb81 100644 --- a/vim/lua/treesitter_config.lua +++ b/vim/lua/treesitter_config.lua @@ -1,93 +1,93 @@ -require 'nvim-treesitter.configs'.setup { - ensure_installed = "all", - highlight = { - enable = true, - disable = {"vim", "swift"}, - additional_vim_regex_highlighting = true, - }, - incremental_selection = { - enable = true, - }, - indent = { - -- enabling breaks autoindent: - enable = false, - }, - textobjects = { - select = { - enable = true, - lookahead = true, - keymaps = { - ["ak"] = "@keyed_element.outer", - ["av"] = "@keyed_element.inner", - ["ia"] = "@parameter.inner", - ["aa"] = "@parameter.outer", - ["ac"] = "@comment.outer", - ["at"] = "@statement.outer", - ["ar"] = "@return", - ["af"] = "@function.outer", - ["if"] = "@function.inner", - }, - }, - move = { - enable = true, - set_jumps = true, - goto_next_start = { - ["]a"] = "@parameter.inner", - ["]f"] = "@function.outer", - ["]F"] = "@function.inner", - }, - goto_previous_start = { - ["[a"] = "@parameter.inner", - ["[f"] = "@function.outer", - ["[F"] = "@function.inner", - }, - }, - lsp_interop = { - enable = true, - peek_definition_code = { - ["d"] = "@class.outer", - -- ["d"] = "@function.outer", - }, - }, - }, - refactor = { - highlight_definitions = { enable = true }, - highlight_current_scope = { enable = false }, - smart_rename = { - enable = true, - keymaps = { - smart_rename = "grr", - }, - }, - navigation = { - enable = true, - keymaps = { - -- goto_definition_lsp_fallback = "gd", - goto_next_usage = "]r", - goto_previous_usage = "[r", - }, - }, - }, - playground = { - enable = true, - disable = {}, - updatetime = 25, - persist_queries = false, - keybindings = { - toggle_query_editor = 'o', - toggle_hl_groups = 'i', - toggle_injected_languages = 't', - toggle_anonymous_nodes = 'a', - toggle_language_display = 'I', - focus_language = 'f', - unfocus_language = 'F', - update = 'R', - goto_node = '', - show_help = '?', - }, - } -} +require("nvim-treesitter.configs").setup({ + ensure_installed = "all", + highlight = { + enable = true, + disable = { "vim", "swift" }, + additional_vim_regex_highlighting = true, + }, + incremental_selection = { + enable = true, + }, + indent = { + -- enabling breaks autoindent: + enable = false, + }, + textobjects = { + select = { + enable = true, + lookahead = true, + keymaps = { + ["ak"] = "@keyed_element.outer", + ["av"] = "@keyed_element.inner", + ["ia"] = "@parameter.inner", + ["aa"] = "@parameter.outer", + ["ac"] = "@comment.outer", + ["at"] = "@statement.outer", + ["ar"] = "@return", + ["af"] = "@function.outer", + ["if"] = "@function.inner", + }, + }, + move = { + enable = true, + set_jumps = true, + goto_next_start = { + ["]a"] = "@parameter.inner", + ["]f"] = "@function.outer", + ["]F"] = "@function.inner", + }, + goto_previous_start = { + ["[a"] = "@parameter.inner", + ["[f"] = "@function.outer", + ["[F"] = "@function.inner", + }, + }, + lsp_interop = { + enable = true, + peek_definition_code = { + ["d"] = "@class.outer", + -- ["d"] = "@function.outer", + }, + }, + }, + refactor = { + highlight_definitions = { enable = true }, + highlight_current_scope = { enable = false }, + smart_rename = { + enable = true, + keymaps = { + smart_rename = "grr", + }, + }, + navigation = { + enable = true, + keymaps = { + -- goto_definition_lsp_fallback = "gd", + goto_next_usage = "]r", + goto_previous_usage = "[r", + }, + }, + }, + playground = { + enable = true, + disable = {}, + updatetime = 25, + persist_queries = false, + keybindings = { + toggle_query_editor = "o", + toggle_hl_groups = "i", + toggle_injected_languages = "t", + toggle_anonymous_nodes = "a", + toggle_language_display = "I", + focus_language = "f", + unfocus_language = "F", + update = "R", + goto_node = "", + show_help = "?", + }, + }, +}) -require'treesitter-context'.setup{ - enable = true, -} +require("treesitter-context").setup({ + enable = true, +})