standardrb / vscode-standard-ruby

The official VS Code extension for the Standard Ruby linter and code formatter
Other
101 stars 7 forks source link

Extension 'standard ruby' is configured as formatter but it cannot format 'Ruby'-files #2

Open Chris24680 opened 1 year ago

Chris24680 commented 1 year ago

Hi, I'm getting this odd error after installing the vscode-standard-ruby extension. Extension 'standard ruby' is configured as formatter but it cannot format 'Ruby'-files

image I'm using the following versions:

standardrb 1.24.3
VSCode 1.75.1

Here is my settings.json:

{
  "workbench.colorTheme": "Default Dark+",
  "security.workspace.trust.untrustedFiles": "open",
  "ruby.useLanguageServer": true,
  "tailwindCSS.includeLanguages": {
    "javascript": "javascript",
    "html": "html",
    "erb": "html"
  },
  "tailwindCSS.emmetCompletions": true,
  "files.associations": {
    "*.html.erb": "erb"
  },
  "git.autofetch": true,
  "[ruby]": {

    "editor.tabSize": 2,
    "editor.defaultFormatter": "testdouble.vscode-standard-ruby"
  },
  "emmet.includeLanguages": {
    "erb": "html"
  },
  "emmet.triggerExpansionOnTab": true,
  "editor.inlineSuggest.enabled": true,
  "git.confirmSync": false,
  "ruby.format": false,
  "gitlens.views.branches.branches.layout": "list",
  "editor.defaultFormatter": "testdouble.vscode-standard-ruby",
  "editor.formatOnSave": true,
  "terminal.integrated.defaultProfile.linux": "zsh",
  "[jsonc]": {
    "editor.defaultFormatter": "vscode.json-language-features"
  }
}

And here is a list of extensions I have installed:

adpyke.vscode-sql-formatter
betterplace.rails-edit-credentials
bradlc.vscode-tailwindcss
bung87.rails
bung87.vscode-gemfile
castwide.solargraph
eamodio.gitlens
GitHub.copilot
gurgeous.bust-a-gem
Gusto.packwerk-vscode
KoichiSasada.vscode-rdbg
ms-azuretools.vscode-docker
ninoseki.vscode-gem-lens
PascalReitermann93.vscode-yaml-sort
rebornix.ruby
redhat.vscode-xml
redhat.vscode-yaml
sianglim.slim
testdouble.vscode-standard-ruby
wingrunr21.vscode-ruby
yzhang.markdown-all-in-one

Happy to provide more detail if needed.

4e4c52 commented 1 year ago

I also have this issue.

robingram commented 1 year ago

I get this if I create a new file within a Rails project using cmd-n and set the type to Ruby without saving.

Strangely, if I do try to save the file then VSCode gives it an extension of arb rather than rb so I don't know if that is related.

searls commented 1 year ago

This is indeed very strange and may be over my head from a VS Code configuration (feels like .rb might be associated with "Ruby" but maybe there's a duplicate language definition with a different id?)

In any case, if Standard Ruby is having any issues itself, it's probably printing something useful out in the output. You can see it if you select the extension in the output panel:

Screenshot 2023-03-26 at 09 37 13
searls commented 1 year ago

Another idea, because you don't have very many settings set:

  1. Check your workspace settings (Open Workspace Settings (JSON) command) for anything fishy
  2. Try uninstalling or disabling other ruby related plugins and see if there's a conflict being caused by one of them (after disabling each, run the Developer: Reload Window command)
robingram commented 1 year ago

I saw a reference on SO to the extension issue being down to VSCode Ruby. I disabled it (which also meant disabling the main Ruby extension) and while ruby files now save with a .rb extension it is still handling unsaved ruby files differently. If I try to format a new ruby file that hasn't been saved I now get "There is no formatter for 'ruby' files installed" and an "Install formatter..." button which opens the extensions list filtered for formatters, including Standard Ruby ironically.

I realise that this is probably a VSCode core issue rather than something relating to this extension, just mentioning it here FYI.

Cheers.

searls commented 1 year ago

I saw a reference on SO to the extension issue being down to VSCode Ruby. I disabled it (which also meant disabling the main Ruby extension) and while ruby files now save with a .rb extension it is still handling unsaved ruby files differently. If I try to format a new ruby file that hasn't been saved I now get "There is no formatter for 'ruby' files installed" and an "Install formatter..." button which opens the extensions list filtered for formatters, including Standard Ruby ironically.

Do you have something like this in your settings.json?

    "[ruby]": {
        "editor.defaultFormatter": "testdouble.vscode-standard-ruby"
    },

And when you're editing unsaved Ruby documents that aren't formatting, do they show up as Ruby in the right side of the status bar?

Screenshot 2023-03-26 at 18 03 33

If the answer to both is "yes", then I'm stumped.

robingram commented 1 year ago

Yes, I'm afraid so. And linting works, just not formatting. It's no biggie now that I know that the problem is only happening on unsaved files (for me at least).

Thanks for taking time to look at this. I can live with it as it stands though.

Chris24680 commented 1 year ago

Thanks for the response. Since my post the issue seems to have resolved itself, though I'm not really sure why.

I don't have any workspace settings on my installation, so that shouldn't be a problem.

After doing a little more investigation I think the Extension 'standard ruby' is configured as formatter but it cannot format 'Ruby'-files error message is just being displayed whenever Standard is unable to start up properly. For example if I open vscode with rvm set to the wrong ruby version. In the output for the extension I get:

[client] Command `bundle list --name-only` failed with exit code 11 (exec options: {"cwd":"/home/chris/workspace/tap-bookkeeping"})
[client] stderr:
https://github.com/seyhunak/twitter-bootstrap-rails.git (at 8a64089@8a64089) is
not yet checked out. Run `bundle install` first.
[client] Failed to invoke Bundler in the current workspace. After resolving the issue, run the command `Standard Ruby: Start Language Server`

However I get the "cannot format ruby files" error in the badge. I've also notice when it is working, I'll still be shown that message until Standard has finished starting up, then it will go to normal.

So it seems it may just be a case of a misleading error message showing regardless of the actual problem.

Hope this helps, now that it's working for me I'm really happy with the extension!

zacheryph commented 1 year ago

We ran into this as well after switching to and getting everyone on the Standard extension. We discovered Ruby was setup with a different formatter. If you see the {*} looking icon next to Ruby in the lower right hand status bar, click that and select Standard, and then Autofix should begin working. That or defining the formatter as noted above in your user settings works too.

searls commented 1 year ago

Folks in this thread, did you follow this step in the readme?

"[ruby]": {
  "editor.defaultFormatter": "testdouble.vscode-standard-ruby"
},

Or was this already set?

robingram commented 1 year ago

@searls I did already have that setting configured.

searls commented 1 year ago

@robingram Rats. Are you still experiencing this issue?

robingram commented 1 year ago

Yeah but only in the limited circumstances I mentioned, for a new file that hasn't been saved, so it is easy to work around.