nebulab / erb-formatter

Format ERB files with speed and precision
MIT License
135 stars 22 forks source link

"erb-formatter not found by bundler" when using gem install #24

Open archonic opened 1 year ago

archonic commented 1 year ago

The readme says we should be able to use this extension with gem install erb-formatter. I've done that and which erb-format works, but the extension seems unable to find it unless it's in the Gemfile. I've also tried adding this to my settings.json:

"erb-formatter.commandPath": "/Users/user/.asdf/shims/erb-format"

Is the gem check only looking in the Gemfile?

ghost commented 1 year ago

I'm getting this error in VSCode:

erb-formatter not found by bundler. Add `gem 'erb-formatter'` to your Gemfile and run `bundle install`.

I have it listed in my Gemfile. I have it installed globally on my machine. I added the commandPath to settings.json like described in the comment above. I don't know why I'm getting this error message. It's annoying.

For now, I'm just disabling the extension to quiet it.

If anybody has a fix for this, please explain.

elia commented 1 year ago

Is the gem check only looking in the Gemfile?

Sorry for the delay 🙏

It's not, the way it checks for presence in the Gemfile is by running bundle show erb-formatter:

See https://github.com/nebulab/erb-formatter-vscode/blob/e82c54421be0670dac0df25c26460e6ed70d5a5f/erb-formatter.js#L61

In your VS Code logs you should be able to see the command that gets actually executed and that should be really helpful in understanding what went wrong:

https://github.com/nebulab/erb-formatter-vscode/blob/e82c54421be0670dac0df25c26460e6ed70d5a5f/erb-formatter.js#L29

mrbme commented 1 year ago

I'm getting the same error too. When I run "bundle show erb-formatter" I get /Users/myname/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/erb-formatter-0.4.3

brodyreid commented 1 year ago

Same error :( Is there a fix for this? VS Code output shows this failed command: Command failed: /Users/user/.gem/ruby/3.2.1/bin/erb-format --stdin-filename "/Users/user/project/app/views/home/index.html.erb" --print-width 80 /Users/user/.gem/ruby/3.2.1/gems/erb-formatter-0.4.3/lib/erb/formatter.rb:159:in 'tag_stack_pop': (RuntimeError)

brodyreid commented 1 year ago

Same error :( Is there a fix for this? VS Code output shows this failed command: Command failed: /Users/user/.gem/ruby/3.2.1/bin/erb-format --stdin-filename "/Users/user/project/app/views/home/index.html.erb" --print-width 80 /Users/user/.gem/ruby/3.2.1/gems/erb-formatter-0.4.3/lib/erb/formatter.rb:159:in 'tag_stack_pop': (RuntimeError)

Oh I understand now: the formatter was just erroring because of incorrect tags. Is there a way to have VS Code highlight these issues in the editor?

ScotterC commented 11 months ago

+1 to this issue. great gem when it was working.

davidwessman commented 11 months ago

I have had to add something like:

"terminal.integrated.profiles.osx": {
    "zsh": {
      "path": "/bin/zsh",
      "args": [
        "-l",
        "-i"
      ]
    }
  },

to my User settings to have same setup as in my normal terminal. Not sure if the formatter uses terminal.integrated, but maybe there is another profile?

elia commented 11 months ago

Oh I understand now: the formatter was just erroring because of incorrect tags. Is there a way to have VS Code highlight these issues in the editor?

I would very much be in favor of highlighting stuff in the editor, I'll give it a crack but if anyone wants to jump in I'd be very happy to collaborate/merge 🙌

https://github.com/nebulab/erb-formatter-vscode

elia commented 11 months ago

Not sure if the formatter uses terminal.integrated, but maybe there is another profile?

The extension is simply using execSync it generates the updated code and uses the editor api to replace the contents, the idea is to make it work even for unsaved files.

ScotterC commented 11 months ago

For those encountering this error but not understanding the 'incorrect tags' comment. This error can come up when there's an exception by ERB formatter when trying to format - say a missing </div> in a weird spot. The way to diagnose is VSCode Output and select 'erb formatter' in the dropdown since normal output won't show the error.