Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Auto-formatting is deleting all text #443

Closed

Description

@compostbrain

Your environment

  • vscode-ruby version:
  • Ruby version: 2.5
  • Ruby version manager (if any): asdf
  • VS Code version:1.31.1
  • Operating System:macos
  • Using language server? yes

Expected behavior

autoformat on save

Actual behavior

deletes the contents of the entire file
This and the next section should include screenshots, code samples, console output, etc. The more information we have to reproduce the better!

Activity

  1. wingrunr21 commented on Mar 1, 2019

    @wingrunr21
    Collaborator

    You are going to have to provide more information

  2. adamzapasnik commented on Mar 4, 2019

    @adamzapasnik

    Same here.

    vscode-ruby version: 0.22.2
    Ruby version: ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
    Ruby version manager: asdf
    VS code version: 1.31.0
    Operating system: Ubuntu 18.04.2 LTS
    Using language server? yes

    What other information do you need?
    This is an output from OUTPUT tab.

    Lint: executing reek -f json...
    Lint: executing rubocop -s somefile.rb -f json...
    Lint: attempted to lint with unsupported linter: ruby
    Lint: attempted to lint with unsupported linter: fasterer
    Lint: attempted to lint with unsupported linter: debride
    Lint: attempted to lint with unsupported linter: ruby-lint
    
  3. wingrunr21 commented on Mar 4, 2019

    @wingrunr21
    Collaborator

    Well just to start: what formatter? What's your configuration? What's the console output? Do you see a Format: call in the console?

    Basically the part in the issue template that wasn't filled out: This and the next section should include screenshots, code samples, console output, etc. The more information we have to reproduce the better!

  4. adamzapasnik commented on Mar 4, 2019

    @adamzapasnik

    Oh, you are right. I posted Lint output, welp. I'm using rubocop.
    I do see format call:
    Format: executing bundle exec rubocop -s somefile.rb -a...

    I noticed that when I launch/reload vscode it throws error rubocop failed with code=1 but I don't see any more details. I can find rubocop in the terminal, though.

    which rubocop
    /home/username/.asdf/shims/rubocop
    

    configuratioon:

      "ruby.codeCompletion": "rcodetools",
      "ruby.intellisense": "rubyLocate",
      "ruby.useBundler": true,
      "ruby.useLanguageServer": true,
      "ruby.lint": {
        "reek": true,
        "rubocop": true,
        "ruby": true, //Runs ruby -wc
        "fasterer": true,
        "debride": true,
        "ruby-lint": true
      },
      "ruby.format": "rubocop",
    
  5. wingrunr21 commented on Mar 4, 2019

    @wingrunr21
    Collaborator

    Do you have a lot of lint errors in that file? I wonder if it's related to another issue where the RuboCop output is really long

  6. adamzapasnik commented on Mar 4, 2019

    @adamzapasnik

    It happens even to a file with only 1 lint error.

  7. wingrunr21 commented on Mar 4, 2019

    @wingrunr21
    Collaborator

    Ok. It is this specific line + this ternary that's doing that. I'll have to take another pass as I introduced those to fix other bugs with selection formatting.

  8. self-assigned this
    on Mar 4, 2019
  9. adamzapasnik commented on Mar 4, 2019

    @adamzapasnik

    :) Glad you found the cause. Do you need any help with that?

  10. wingrunr21 commented on Mar 4, 2019

    @wingrunr21
    Collaborator

    No, I think I'm going to have to combine the fix with #435. I need to introduce a buffer on all stdout and then process that output based on the return code from the linter/formatter.

  11. adamzapasnik commented on Mar 4, 2019

    @adamzapasnik

    Seems like a good solution 👍 Good luck then. Feel free to ping me to test the fix.

  12. pinned this issue on Mar 5, 2019
  13. wingrunr21 commented on Mar 6, 2019

    @wingrunr21
    Collaborator

    v0.22.3 has the bugfix for this

  14. adamzapasnik commented on Mar 6, 2019

    @adamzapasnik

    Almost...
    If you have "ruby.useBundler": true in config and no rubocop in Gemfile it deletes content of the file and writes this instead:

    load command: rubocop (/home/username/.asdf/installs/ruby/2.5.1/bin/rubocop)
    Gem::Exception: can't find executable rubocop for gem rubocop. rubocop is not currently included in the bundle, perhaps you meant to add it to your Gemfile?
      /home/username/.asdf/installs/ruby/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-1.17.2/lib/bundler/rubygems_integration.rb:462:in `block in replace_bin_path'
      /home/username/.asdf/installs/ruby/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-1.17.2/lib/bundler/rubygems_integration.rb:482:in `block in replace_bin_path'
      /home/username/.asdf/installs/ruby/2.5.1/bin/rubocop:23:in `<top (required)>'
    

    Or is it correct behaviour?

  15. wingrunr21 commented on Mar 6, 2019

    @wingrunr21
    Collaborator

    Well, replacing the file contents is probably not correct. The problem I'm trying to work around is that bundler doesn't distinguish between stdout and stderr until v2 (see rubygems/bundler#3353) so I can't just assume stdout is good and stderr is bad.

    I'll add a test case for it. This is actually a different issue than originally though so I'll probably open a new one and link them.

  16. adamzapasnik commented on Mar 6, 2019

    @adamzapasnik

    I see, thanks for the information and the fix 👍

  17. wingrunr21 commented on Mar 6, 2019

    @wingrunr21
    Collaborator

    Can you post the full Output you are seeing? Having trouble reproducing

  18. adamzapasnik commented on Mar 6, 2019

    @adamzapasnik

    Which Output exactly?

  19. wingrunr21 commented on Mar 6, 2019

    @wingrunr21
    Collaborator

    The Ruby Language Server stuff. I want to see what format command it is attempting to run

  20. adamzapasnik commented on Mar 6, 2019

    @adamzapasnik

    Format: executing bundle exec rubocop -s somefile.rb -a...
    This is what I can see printed from Format

  21. wingrunr21 commented on Mar 6, 2019

    @wingrunr21
    Collaborator

    Interesting. When I try and reproduce this setup:

    • ruby.useBundler: true
    • Gemfile in project without rubocop

    I get a correctly handled language server error. Are you using a binstub?

  22. adamzapasnik commented on Mar 6, 2019

    @adamzapasnik

    AFAIK, no, I don't.

  23. wingrunr21 commented on Mar 6, 2019

    @wingrunr21
    Collaborator

    ok but you have rubocop installed globally? /home/username/.asdf/installs/ruby/2.5.1/bin/rubocop seems to suggest yes

  24. adamzapasnik commented on Mar 6, 2019

    @adamzapasnik

    Yes, I do.

    which rubocop
    => /home/username/.asdf/shims/rubocop
    
  25. wingrunr21 commented on Mar 6, 2019

    @wingrunr21
    Collaborator

    Reproduced it. Thanks

  26. unpinned this issue on Mar 6, 2019
  27. arminanton commented on May 3, 2022

    @arminanton

    Was this solved? I'm having the same issue.

  28. kristof-mattei commented on Oct 31, 2022

    @kristof-mattei

    So this is funny, I just hit this issue. And I switched to .asdf yesterday...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugBug reports

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions