tpope / vim-rails

rails.vim: Ruby on Rails power tools
http://www.vim.org/scripts/script.php?script_id=1567
4.09k stars 381 forks source link

Fix “E54: Unmatched (” when jumping to related from a `.sql` file #580

Closed jasoncodes closed 2 years ago

jasoncodes commented 2 years ago

This PR fixes the following error when invoking :R from a .sql file:

Error detected while processing function <SNR>143_Related[1]..<SNR>143_AR[54]..<SNR>143_readable_alternate[1]..<SNR>143_readable_alternate_candidates[2]..<SNR>143_readable_placeholders[5]..<SNR>143_readable_last_method:
line    7:
E54: Unmatched (

The problem is the s:sql_define pattern sets \v (very magic mode) which is then embedded into a matchstr pattern inside s:readable_last_method which does not expect the magic mode to the changed from the default.

I saw two options for solving this:

  1. update the s:sql_define pattern to reset back to magic mode (\m), or
  2. update s:readable_last_method to reset back to magic mode (\m) after embedding self.define_pattern()

The second option seemed to be more robust against other pattern inputs and I did not see s:sql_define being used as a part of other patterns elsewhere.

tpope commented 2 years ago

Wow, how long has this bug been hiding? If I was writing it today I would probably avoid \v entirely, but this is more than good enough.

jasoncodes commented 2 years ago

I discovered this when updating an older install and bisected it down to 37aa670baddf3dd18d3637c82c197342e542e084. So, only 3 years or so. :)

Good to know you’d probably avoid \v today. I might have gone for a rewrite if it were the only \v I spotted in the code but decided for a minimal change instead.