Issue with "require" for the "parser" gem in Vim plugin using Ruby files in autoload

34 Views Asked by At

I'm currently working on a Vim plugin that involves manipulating abstract syntax trees (ASTs) in Ruby. To achieve this, I'm using the "parser" gem. However, I'm encountering difficulties with the "require" statement when trying to use the "parser" gem in Ruby files located in the "autoload" directory of my plugin.

I've attempted the typical "require" approach as follows:

Copy code
require 'parser'

But it doesn't seem to work as expected. I'm wondering if there's a specific context in which Ruby files within the "autoload" directory are executed, which might be causing the "require" statement to behave differently, especially for external gems like "parser".

I'm seeking guidance on the proper way to "require" gems in Ruby files within the "autoload" directory of a Vim plugin. Is there any special configuration required in the vimrc file or in the plugin's structure to make this work seamlessly?

Any assistance or insights would be greatly appreciated. Thank you in advance for your help!

Best regards

I try many different variation but allways issue with no such parser

My last try was


 59 ruby << EOF
 60 
 61 require 'pathname'
 62 # For IO#ready -- but Cygwin doesn't have io/wait.
 63 require 'io/wait' unless RUBY_PLATFORM =~ /cygwin/
 64 # Needed for String#each_char in Ruby 1.8 on some platforms.
 65 require 'jcode' unless "".respond_to? :each_char
 66 # Needed for Array#each_slice in Ruby 1.8 on some platforms.
 67 require 'enumerator' unless [].respond_to? :each_slice
 68 
 69 $LUSTY_PROFILING = false
 70 
 71 if $LUSTY_PROFILING
 72   require 'rubygems'
 73   require 'ruby-prof'
 74 end
 75 require 'rubygems'
 76 require "parser/current"
 77 require "unparser"
 78 
 79 current_file = VIM::evaluate('expand("%")')
 80 content      = File.read(current_file)
 81 
 82 puts "zizi"
 83 puts "caca"
 84 ast          = Parser::CurrentRuby.parse(content)
 85 
 86 
 87 EOF

into a vimscript what give me this error message.

Erreur détectée en traitant Autocommandes BufWritePost pour "*.vim"..function <SNR>110_AutoReload[3]..xolox#reload#script[18]..<SNR>235_reload_plugin[3]..script /home/valeureux/.vim/bundle/hello_world/plugin/hello_world.vim :
ligne   87 :
NoMethodError: private method `puts' called for #<Object:0x000055c04908c898>
/home/valeureux/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/parser-3.2.2.3/lib/parser/base.rb:91:in `block in default_parser'
/home/valeureux/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/parser-3.2.2.3/lib/parser/diagnostic/engine.rb:68:in `process'
/home/valeureux/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/parser-3.2.2.3/lib/parser/base.rb:286:in `on_error'
(eval):3:in `_racc_do_parse_c'
(eval):3:in `do_parse'
/home/valeureux/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/parser-3.2.2.3/lib/parser/base.rb:190:in `parse'
/home/valeureux/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/parser-3.2.2.3/lib/parser/base.rb:33:in `parse'
eval:25:in `<main>'
0

There are 0 best solutions below