pechorin / any-jump.vim

Jump to any definition and references 👁 IDE madness without overhead 🚀
1.08k stars 41 forks source link

TS and JS pattern definition causes error on RunXDefinitionSearch #102

Closed jaredgorski closed 1 year ago

jaredgorski commented 1 year ago

Running any-jump inside a Typescript or Javascript project results in the following error:

Screen Shot 2022-11-24 at 10 50 49 PM

text:

Error detected while processing function <SNR>19_Jump[32]..search#SearchDefinitions[33]..<SNR>101_RunRgDefinitionSearch:
line    7:
E484: Can't open file /var/folders/h8/8pfhlns54nl2gf0gmgbr5dgw0000gn/T/vfnfZFj/9

I troubleshot this error and was able to trace it to the patterns being generated for Typescript and Javascript. I can fix this error locally by removing the double quote characters (") from the pcre2 pattern definitions on lines 1294 and 1402. E.g.:

-   \"pcre2_regexp": '(service|factory)\([''"]KEYWORD[''"]',
+   \"pcre2_regexp": '(service|factory)\(['']KEYWORD['']',

I'm sure these double quote characters aren't the root problem, but I think it's interesting that such a small change to these patterns solves the error.

Hopefully this is a good start!

pechorin commented 1 year ago

Hello! Thanks for report. What is your vim/neovim version? is rg latest version? What is your env/osx? And please provide info: is this bash or zsh?

And another one: is this source code for this project public?

jaredgorski commented 1 year ago

No problem!

jaredgorski commented 1 year ago

I just ran PlugUpdate on another machine I have (same details as the comment above) and ran into the same issue. any-jump worked before PlugUpdate and was broken afterwards.

This is the PlugDiff (info):

- any-jump.vim:
  * 6ec5f8a (tag: v0.6) any-jump 0.6 (#100) (4 weeks ago)
  *   15e12ca Merge pull request #86 from bergtholdt/master (6 weeks ago)
  |\
  | * 451536b fix #85 spaces in path break preview (1 year, 9 months ago)
  * 67b1737 haskell support for ripgrep (12 months ago)
  * d58aac1 Merge pull request #90 from paniash/fix-typos (1 year, 5 months ago)
  * 3ededdd another typo fixed (1 year, 6 months ago)
  * fc6a856 fixed typos (1 year, 6 months ago)
bombamong commented 1 year ago

I troubleshot this error and was able to trace it to the patterns being generated for Typescript and Javascript. I can fix this error locally by removing the double quote characters (") from the pcre2 pattern definitions on lines 1294 and 1402. E.g.:

-     \"pcre2_regexp": '(service|factory)\([''"]KEYWORD[''"]',
+ \"pcre2_regexp": '(service|factory)\(['']KEYWORD['']',

Had a similar problem and this fixed the issue for me. Thx!

Using:

Error Image:

image

Changes: image

jaredgorski commented 1 year ago

~When I'm feeling less lazy~ When I'm not working my day job I'll probably run a git bisect to find you the offending commit

pechorin commented 1 year ago

It's about latest commit :) sorry, I'll take a look at it in a couple of days, can't switch my brain to another conetxt right now :)

jaredgorski commented 1 year ago

Take your time! Thanks for your plugin; it's by far my preference over ctags or other overengineered solutions. You rock.

jackyzy823 commented 1 year ago

Same issue here.

@pechorin The root reason is " is not escaped . so it will generate unmatched quote in shell .

Besides, ` need to be escaped too (used for nim-lang), otherwise it will used as $(cmd) in shell.

Here's the solution.

diff --git a/generator/lib/generate.rb b/generator/lib/generate.rb
index b5bd4d3..303aa82 100644
--- a/generator/lib/generate.rb
+++ b/generator/lib/generate.rb
@@ -148,8 +148,11 @@ class Generate
     return string
   end

-  def format_single_quotes(string)
+  def escape_regex(string)
     string.gsub("'", "''")
+          .gsub("\"" , "\\\\\"" )
+          .gsub("`", "\\\\`")
   end

   def prepare_supported_engines(language, engines)
@@ -164,8 +167,8 @@ class Generate
     r = "\n"
     r << "call s:add_definition('#{language}', {\n"
     r << "\t" + '\"type": ' + "'" + hash[:type] + "',\n"
-    r << "\t" + '\"pcre2_regexp": ' + "'" + format_single_quotes(pcre2_regexp(hash[:emacs_regexp])) + "',\n"
-    r << "\t" + '\"emacs_regexp": ' + "'" + format_single_quotes(hash[:emacs_regexp].to_s) + "',\n"
+    r << "\t" + '\"pcre2_regexp": ' + "'" + escape_regex(pcre2_regexp(hash[:emacs_regexp])) + "',\n"
+    r << "\t" + '\"emacs_regexp": ' + "'" + escape_regex(hash[:emacs_regexp].to_s) + "',\n"
     r << "\t" + '\"supports": ' + prepare_supported_engines(language, hash[:supports]) + ",\n"
     r << "\t" + '\"spec_success": ' + hash[:spec_success].to_a.to_json + ",\n"
     r << "\t" + '\"spec_failed": '  + hash[:spec_failed].to_a.to_json + ",\n"

Above modification affects javascript, typescript,nim (previous three are tested) hcl and vhdl (not yet tested)

pechorin commented 1 year ago

Okay mates thanks for your great impact on this problems; this bug easily reproduces in my nvim on any typescript project.

Hopes https://github.com/pechorin/any-jump.vim/commit/9768403b6381ce3758cebac9613910c0160969e3 fix this, please update and let me know if it helps.

jaredgorski commented 1 year ago

@pechorin - Looks like that fixes JS and TS. I also did a naive test of Nim, but someone with actual projects would be a better judge. Thanks!