Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use the plugin with VSCode + Prettier extension since 3.x.x release #1253

Closed
DashwoodIce9 opened this issue Jul 7, 2022 · 12 comments

Comments

@DashwoodIce9
Copy link

DashwoodIce9 commented Jul 7, 2022

Metadata

  • Operating system: Amazon Linux 2
  • Ruby version: 2.7.6
  • Node version: Tried with 12.22.12, 14.20.0, 16.13.0
  • @prettier/plugin-ruby or prettier gem version: Every version since 3.0.0
  • syntax_tree version: latest

Input

    puts("Hello, World") #should remove the extra space in the beginning.

How I've integrated with VSCode

  1. Installed Prettier - Code formatter plugin version 9.5.0.
  2. cd ~/.vscode-server/extensions/esbenp.prettier-vscode-9.5.0
  3. npm i @prettier/plugin-ruby
  4. Modified VSCode settings.json to include -
"[ruby]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode",
},

Prettier extension output upon giving the format command

["INFO" - 4:12:38 PM] Extension Name: esbenp.prettier-vscode.
["INFO" - 4:12:38 PM] Extension Version: 9.5.0.
["INFO" - 4:12:42 PM] Formatting file:///home/prakhaga/test.rb
["INFO" - 4:12:42 PM] File Info:
{
  "ignored": false,
  "inferredParser": "ruby"
}
["INFO" - 4:12:42 PM] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 4:12:42 PM] Prettier Options:
{
  "arrowParens": "always",
  "bracketSpacing": true,
  "endOfLine": "lf",
  "htmlWhitespaceSensitivity": "css",
  "insertPragma": false,
  "jsxBracketSameLine": false,
  "jsxSingleQuote": false,
  "printWidth": 80,
  "proseWrap": "preserve",
  "quoteProps": "as-needed",
  "requirePragma": false,
  "semi": true,
  "singleQuote": false,
  "tabWidth": 2,
  "trailingComma": "es5",
  "useTabs": false,
  "vueIndentScriptAndStyle": false,
  "filepath": "/home/prakhaga/test.rb",
  "parser": "ruby"
}
["ERROR" - 4:12:47 PM] Error formatting document.
Error: 
      We failed to spawn our parser server. Please report this error on GitHub
      at https://github.com/prettier/plugin-ruby. The error message was:

        /local/home/prakhaga/.vscode-server/extensions/esbenp.prettier-vscode-9.5.0/node_modules/@prettier/plugin-ruby/src/getInfo.js:12
  throw new Error(`Failed to get information from parse server in time. If this
  ^

Error: Failed to get information from parse server in time. If this
    happens repeatedly, try increasing the PRETTIER_RUBY_TIMEOUT_MS environment
    variable beyond 5000.
    at Timeout._onTimeout (/local/home/prakhaga/.vscode-server/extensions/esbenp.prettier-vscode-9.5.0/node_modules/@prettier/plugin-ruby/src/getInfo.js:12:9)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7)
.
    
	at spawnServer (/local/home/prakhaga/.vscode-server/extensions/esbenp.prettier-vscode-9.5.0/node_modules/@prettier/plugin-ruby/src/parseSync.js:155:11)
	at parseSync (/local/home/prakhaga/.vscode-server/extensions/esbenp.prettier-vscode-9.5.0/node_modules/@prettier/plugin-ruby/src/parseSync.js:180:18)
	at Object.parse (/local/home/prakhaga/.vscode-server/extensions/esbenp.prettier-vscode-9.5.0/node_modules/@prettier/plugin-ruby/src/plugin.js:85:16)
	at Object.parse (/local/home/prakhaga/.vscode-server/extensions/esbenp.prettier-vscode-9.5.0/node_modules/prettier/index.js:7330:23)
	at coreFormat (/local/home/prakhaga/.vscode-server/extensions/esbenp.prettier-vscode-9.5.0/node_modules/prettier/index.js:8641:18)
	at formatWithCursor2 (/local/home/prakhaga/.vscode-server/extensions/esbenp.prettier-vscode-9.5.0/node_modules/prettier/index.js:8833:18)
	at /local/home/prakhaga/.vscode-server/extensions/esbenp.prettier-vscode-9.5.0/node_modules/prettier/index.js:39137:12
	at Object.format (/local/home/prakhaga/.vscode-server/extensions/esbenp.prettier-vscode-9.5.0/node_modules/prettier/index.js:39151:12)
	at t.default.format (/local/home/prakhaga/.vscode-server/extensions/esbenp.prettier-vscode-9.5.0/dist/extension.js:1:13427)
	at async t.PrettierEditProvider.provideEdits (/local/home/prakhaga/.vscode-server/extensions/esbenp.prettier-vscode-9.5.0/dist/extension.js:1:10134)
	at async M.provideDocumentFormattingEdits (/local/home/prakhaga/.vscode-server/bin/30d9c6cd9483b2cc586687151bcbcd635f373630/out/vs/workbench/api/node/extensionHostProcess.js:83:137239)
["INFO" - 4:12:47 PM] Formatting completed in 5.064ms.

With v2.1.0 (last working version)

["INFO" - 4:14:36 PM] Extension Name: esbenp.prettier-vscode.
["INFO" - 4:14:36 PM] Extension Version: 9.5.0.
["INFO" - 4:14:42 PM] Formatting file:///home/prakhaga/test.rb
["INFO" - 4:14:42 PM] File Info:
{
  "ignored": false,
  "inferredParser": "ruby"
}
["INFO" - 4:14:42 PM] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 4:14:42 PM] Prettier Options:
{
  "arrowParens": "always",
  "bracketSpacing": true,
  "endOfLine": "lf",
  "htmlWhitespaceSensitivity": "css",
  "insertPragma": false,
  "jsxBracketSameLine": false,
  "jsxSingleQuote": false,
  "printWidth": 80,
  "proseWrap": "preserve",
  "quoteProps": "as-needed",
  "requirePragma": false,
  "semi": true,
  "singleQuote": false,
  "tabWidth": 2,
  "trailingComma": "es5",
  "useTabs": false,
  "vueIndentScriptAndStyle": false,
  "filepath": "/home/prakhaga/test.rb",
  "parser": "ruby"
}
["INFO" - 4:14:42 PM] Formatting completed in 0.208ms.

Output

puts('Hello, World')
@kddnewton
Copy link
Member

@DashwoodIce9 have you installed the required gems? (See the README)

@kddnewton
Copy link
Member

I'm assuming you're facing the same issues as described in this comment: #1232 (comment). Please see that issue for more details.

@mgrip
Copy link

mgrip commented Jul 26, 2022

@kddnewton I'm also seeing this issue specifically using the VS Code plugin - running prettier directly via the CLI works fine, but running via VS Code (ie run on save or using the "Format Document" command) results in the same error in the issue description. I've followed all the instructions in the README to install the required gems. Could there have been a change in 3.0 that would have affected how the VS Code plugin specifically is able to interact with prettier?

@hidde-jan
Copy link

Still experiencing this, and nothing in the linked comment from 22nd of July gives any details on why this happens specifically for the VSCode plugin.

@kddnewton
Copy link
Member

@hidde-jan which version of Ruby is your VSCode plugin using?

@darrenterhune
Copy link

FWIW I had this issue and had the gems in my gemfile. It didn't work until I installed them with gem install. Ruby 3.1.2.

@kddnewton
Copy link
Member

That probably means you're running with a different set of gem load paths and you need to have it available globally.

@kddnewton
Copy link
Member

@hidde-jan I have trouble debugging this because it entirely has to do with your system. The plugin expects that you have the gems on the correct load path. If you don't, it's going to cause issues.

@darrenterhune
Copy link

That probably means you're running with a different set of gem load paths and you need to have it available globally.

Yep I usually always vendor bundle my gems. So for this plugin and these gems related I just gem install them to get them global and I'm good. Thought it was worth mentioning here 😄

@hidde-jan
Copy link

I've tried to create a devcontainer that mirrors the one of the project I'm using it in, but there it does seem to work, even though the setup is almost the same. Maybe there's some conflict with another extension that I didn't install in my sandbox project?

Unfortunately, it seems to be caused by vscode, and the error message is not helpful in drilling down deeper into the problem:

["INFO" - 5:59:47 PM] Formatting file:///workspace/spec/requests/api/v3/CENSORED_spec.rb
["INFO" - 5:59:47 PM] Using config file at '/workspace/.prettierrc.yml'
["INFO" - 5:59:47 PM] Using ignore file (if present) at /workspace/.prettierignore
["INFO" - 5:59:47 PM] File Info:
{
  "ignored": false,
  "inferredParser": "ruby"
}
["INFO" - 5:59:47 PM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 5:59:47 PM] Prettier Options:
{
  "filepath": "/workspace/spec/requests/api/v3/CENSORED_spec.rb",
  "parser": "ruby"
}
["ERROR" - 5:59:52 PM] Error formatting document.
Error: 
      We failed to spawn our parser server. Please report this error on GitHub
      at https://github.com/prettier/plugin-ruby. The error message was:

        /workspace/node_modules/@prettier/plugin-ruby/src/getInfo.js:12
  throw new Error(`Failed to get information from parse server in time. If this
  ^

Error: Failed to get information from parse server in time. If this
    happens repeatedly, try increasing the PRETTIER_RUBY_TIMEOUT_MS environment
    variable beyond 5000.
    at Timeout._onTimeout (/workspace/node_modules/@prettier/plugin-ruby/src/getInfo.js:12:9)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7)
.
    
	at spawnServer (/workspace/node_modules/@prettier/plugin-ruby/src/parseSync.js:155:11)
	at parseSync (/workspace/node_modules/@prettier/plugin-ruby/src/parseSync.js:180:18)
	at Object.parse (/workspace/node_modules/@prettier/plugin-ruby/src/plugin.js:85:16)
	at Object.parse (/workspace/node_modules/prettier/index.js:7334:23)
	at coreFormat (/workspace/node_modules/prettier/index.js:8645:18)
	at formatWithCursor2 (/workspace/node_modules/prettier/index.js:8837:18)
	at /workspace/node_modules/prettier/index.js:37229:12
	at Object.format (/workspace/node_modules/prettier/index.js:37243:12)
	at t.default.format (/home/vscode/.vscode-server/extensions/esbenp.prettier-vscode-9.9.0/dist/extension.js:1:14503)
	at async t.PrettierEditProvider.provideEdits (/home/vscode/.vscode-server/extensions/esbenp.prettier-vscode-9.9.0/dist/extension.js:1:11197)
	at async H.provideDocumentFormattingEdits (/vscode/vscode-server/bin/linux-arm64/d045a5eda657f4d7b676dedbfa7aab8207f8a075/out/vs/workbench/api/node/extensionHostProcess.js:92:45661)
["INFO" - 5:59:52 PM] Formatting completed in 5242ms.

@thechrisoshow
Copy link

Wow - I had this problem and just realised how to fix it (your mileage may differ).

I was using rvm and had just upgraded to 3.1.2 and installed the required gems.

However I hadn't set the default Ruby in RVM to 3.1.2 - so I had the required gems installed in 3.1.2 but not in 3.1.1 (which was my default). So VSCode was looking for the gems in rvm 3.1.1, and they weren't there.

Setting my default ruby to 3.1.2 fixed it.

@johannesluedke
Copy link

For use closing VS code, rm -rf node_modules && npm i and reopening vs code resolved it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants