diff --git a/lazy-lock.json b/lazy-lock.json index 8065975..a58a020 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -9,7 +9,7 @@ "crates.nvim": { "branch": "main", "commit": "73d2c590c74a0c582144987a4decb4a642755859" }, "flash.nvim": { "branch": "main", "commit": "3c942666f115e2811e959eabbdd361a025db8b63" }, "friendly-snippets": { "branch": "main", "commit": "31f2a2657b6261724313281fe0d8ba6f43f4a4fa" }, - "fzf-lua": { "branch": "main", "commit": "b62a34f5e4fbf36dd4c6d29920a61451eecd04ed" }, + "fzf-lua": { "branch": "main", "commit": "40fbbb6e4ed2965adf6a502bcd5a82ef95c28fd4" }, "gitsigns.nvim": { "branch": "main", "commit": "d600d3922c1d001422689319a8f915136bb64e1e" }, "grug-far.nvim": { "branch": "main", "commit": "1c9325f6ab18fc8ac4d4c57e765aa845af148277" }, "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, diff --git a/lua/config/keymaps.lua b/lua/config/keymaps.lua index ba8fd5e..120e6b1 100644 --- a/lua/config/keymaps.lua +++ b/lua/config/keymaps.lua @@ -7,18 +7,24 @@ vim.keymap.del({ "n", "i", "v" }, "") vim.keymap.del({ "n", "i", "v" }, "") vim.keymap.set('v', 'y', '"+y') -- v-mode: yank to clipboard; +local function toggle_rb_spec() + -- rails + if vim.fn.filereadable("config/application.rb") == 1 then + if vim.fn.expand("%:t"):match("_spec%.rb$") then + vim.cmd("edit " .. vim.fn.expand("%:h"):gsub("spec", "app") .. "/" .. vim.fn.expand("%:t"):gsub("_spec%.rb$", ".rb")) + else + vim.cmd("edit " .. vim.fn.expand("%:h"):gsub("app", "spec") .. "/" .. vim.fn.expand("%:t"):gsub("%.rb$", "_spec.rb")) + end + end + +end local function toggle_rspec() vim.cmd("lcd " .. vim.fn.system("git rev-parse --show-toplevel"):gsub("\n", "")) - -- Guard clause: Exit if the file is not a Ruby file or if not in a Rails project - if vim.fn.expand("%:e") ~= "rb" or not vim.fn.isdirectory("app") or vim.fn.filereadable("Gemfile") == 0 then - vim.notify("Not a Ruby file or Rails project", vim.log.levels.WARN) - return - end - -- Check if the current file is a spec file - if vim.fn.expand("%:t"):match("_spec%.rb$") then - vim.cmd("edit " .. vim.fn.expand("%:h"):gsub("spec", "app") .. "/" .. vim.fn.expand("%:t"):gsub("_spec%.rb$", ".rb")) + + if vim.bo.filetype == "ruby" and vim.fn.filereadable("Gemfile") == 1 then + toggle_rb_spec() else - vim.cmd("edit " .. vim.fn.expand("%:h"):gsub("app", "spec") .. "/" .. vim.fn.expand("%:t"):gsub("%.rb$", "_spec.rb")) + vim.notify("Unsupported file type and/or project", vim.log.levels.WARN) end end vim.keymap.set('n', 'ti', toggle_rspec, { silent = true, desc = "Toggle Test F(i)le" })