my neovim config, who would've thought

Refect lua/scratch/gotest_switcher.lua from 597fa4fb36604a2ead62150df4c5ca184c3c3a1c

olexsmir.xyz a4c26cb4 a8b8513e

verified
Changed files
+21
after
ftplugin
lua
scratch
+2
after/ftplugin/go.lua
··· 13 13 map("n", "<localleader>t", "<cmd>GoTestAdd<cr>", true) 14 14 map("n", "<localleader>a", "<cmd>GoTestsAll<cr>", true) 15 15 map("n", "<localleader>e", "<cmd>GoTestsExp<cr>", true) 16 + 17 + map("n", "<localleader>s", require("scratch.gotest").switch, true)
+19
lua/scratch/gotest.lua
··· 1 + local gotests = {} 2 + 3 + function gotests.switch() 4 + local bufnr = vim.api.nvim_get_current_buf() 5 + local fname_parts = vim.split(vim.api.nvim_buf_get_name(bufnr), "/") 6 + local test_fname = fname_parts[#fname_parts] 7 + if test_fname:find "_test.go" then 8 + test_fname = test_fname:gsub("_test.go", ".go") 9 + else 10 + test_fname = test_fname:gsub(".go", "_test.go") 11 + end 12 + 13 + table.remove(fname_parts, #fname_parts) 14 + local path = table.concat(fname_parts, "/") .. "/" .. test_fname 15 + 16 + vim.cmd("edit " .. path) 17 + end 18 + 19 + return gotests