Skip to content

Commit

Permalink
Merge branch 'hotoolong-fix_to_avoid_replacing_unintended_PATH'
Browse files Browse the repository at this point in the history
  • Loading branch information
rgroli committed Apr 7, 2024
2 parents d36a66a + b1b9df1 commit 6913629
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lua/other-nvim/builtin/mappings/rails.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local rails_alternative_targets = {
{ context = "mailer", target = "/app/mailers/%1_mailer.rb" },
{ context = "service", target = "/app/services/%1_service.rb" },
{ context = "worker", target = "/app/workers/**/%1_worker.rb" },
{ context = "factories", target = "/spec/factories/%1.rb", transformer = "singularize" },
{ context = "factories", target = "/spec/factories/%1.rb", transformer = "pluralize" },
}

return {
Expand Down
19 changes: 11 additions & 8 deletions lua/other-nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,17 @@ local findOther = function(filename, context)

if match ~= nil then
local fn = filename
-- if we have a match, optionally transform the match
if mapping.transformer ~= nil then
local transformedMatch = options.transformers[mapping.transformer](match)
fn, _ = filename:gsub(util.escape_pattern(match), transformedMatch)
end

-- return (transformed) match with "target"
local result, _ = fn:gsub(mapping.pattern, mapping.target)
local result, _ = fn:gsub(mapping.pattern, function(...)
local captureds = { ... }
local transformed_parts = {}
for _, part in ipairs(captureds) do
local transformed_part = mapping.transformer and options.transformers[mapping.transformer](part) or part
table.insert(transformed_parts, transformed_part)
end
return mapping.target:gsub("%%(%d)", function(n)
return transformed_parts[tonumber(n)] or ''
end)
end)

local showMissingFiles = options.showMissingFiles
local dirMatching = false
Expand Down
Empty file.
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions lua/spec/mappings_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ describe("rails-mapping", function()
runOther("/lua/spec/fixtures/rails-minitest/lib/user_helper.rb")
assert.is_true(checkForStringAtPos(1, "test/unit/lib/user_helper_test.rb"))
end)

it("rspec", function()
require("other-nvim").setup({
showMissingFiles = false,
Expand Down Expand Up @@ -281,6 +282,9 @@ describe("rails-mapping", function()
assert.is_true(checkForStringAtPos(1, "spec/unit/models/feature_spec.rb"))
assert.is_true(checkForStringAtPos(2, "app/controllers/api/v1/feature_controller.rb"))
assert.is_true(checkForStringAtPos(3, "app/controllers/api/v2/feature_controller.rb"))
assert.is_true(checkForStringAtPos(4, "app/channels/api/v1/feature_channel.rb"))
assert.is_true(checkForStringAtPos(5, "spec/factories/features.rb"))


runOther("/lua/spec/fixtures/rails-rspec/app/models/user.rb")
assert.is_true(checkForStringAtPos(1, "spec/unit/models/user_spec.rb"))
Expand All @@ -293,6 +297,9 @@ describe("rails-mapping", function()
assert.is_true(checkForStringAtPos(8, "app/services/user_service.rb"))
assert.is_true(checkForStringAtPos(9, "app/workers/user/user_worker.rb"))

runOther("/lua/spec/fixtures/rails-rspec/app/models/spec.rb")
assert.is_true(checkForStringAtPos(1, "spec/factories/specs.rb"))

runOther("/lua/spec/fixtures/rails-rspec/app/serializers/user_serializer.rb")
assert.is_true(checkForStringAtPos(1, "spec/unit/serializers/user_serializer_spec.rb"))
assert.is_true(checkForStringAtPos(2, "app/models/user.rb"))
Expand Down

0 comments on commit 6913629

Please sign in to comment.