prettier / prettier-vscode

Visual Studio Code extension for Prettier
https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
MIT License
5.18k stars 460 forks source link

Can't figure out how to get VS Code to format a Gemfile with Prettier #2605

Closed ndbroadbent closed 2 years ago

ndbroadbent commented 2 years ago

Summary

Prettier is disabled for Gemfile and I can't figure out how to enable it.

Screen Shot 2022-06-29 at 2 52 02 PM Screen Shot 2022-06-29 at 2 56 29 PM

How do I configure prettier-ruby with these other Ruby file names like Gemfile, Rakefile, etc.?

It works if I put this in my settings.json:

"files.associations": {
    "Gemfile": "ruby"
  },

But it looks like Gemfile is a special case that uses a gemfile language.

"Format Document (Forced)" works fine.

Expected result

Should format Gemfile

Actual result

Disabled on Gemfile

VS Code Version:

1.68.1

Prettier Extension Version:

v9.5.0

OS and version:

MacOS 12.3.1

Prettier Log Output

["INFO" - 2:49:56 PM] Extension Name: esbenp.prettier-vscode.
["INFO" - 2:49:56 PM] Extension Version: 9.5.0.
["DEBUG" - 2:49:56 PM] Enabling Prettier globally
{
  "languageSelector": [
    {
      "language": "javascript"
    },
    {
      "language": "mongo"
    },
    {
      "language": "javascriptreact"
    },
    {
      "language": "typescript"
    },
    {
      "language": "typescriptreact"
    },
    {
      "language": "json"
    },
    {
      "language": "jsonc"
    },
    {
      "language": "json5"
    },
    {
      "language": "css"
    },
    {
      "language": "postcss"
    },
    {
      "language": "less"
    },
    {
      "language": "scss"
    },
    {
      "language": "handlebars"
    },
    {
      "language": "graphql"
    },
    {
      "language": "markdown"
    },
    {
      "language": "mdx"
    },
    {
      "language": "html"
    },
    {
      "language": "vue"
    },
    {
      "language": "yaml"
    },
    {
      "language": "ansible"
    },
    {
      "language": "home-assistant"
    },
    {
      "language": "ruby"
    },
    {
      "language": "haml"
    },
    {
      "language": "jsonc",
      "scheme": "vscode-userdata"
    }
  ],
  "rangeLanguageSelector": [
    {
      "language": "javascript"
    },
    {
      "language": "javascriptreact"
    },
    {
      "language": "typescript"
    },
    {
      "language": "typescriptreact"
    },
    {
      "language": "json"
    },
    {
      "language": "graphql"
    },
    {
      "language": "handlebars"
    }
  ]
}
["DEBUG" - 2:49:59 PM] Local prettier module path: '/Users/ndbroadbent/code/app/example/node_modules/prettier/index.js'
["DEBUG" - 2:49:59 PM] Using prettier version 2.7.1
["DEBUG" - 2:49:59 PM] Enabling Prettier for Workspace /Users/ndbroadbent/code/app/example
{
  "languageSelector": [
    {
      "pattern": "/Users/ndbroadbent/code/app/example/**/*.{js,_js,bones,cjs,es,es6,frag,gs,jake,jsb,jscad,jsfl,jsm,jss,mjs,njs,pac,sjs,ssjs,xsjs,xsjslib,wxs,js.flow,jsx,ts,mts,cts,tsx,json,avsc,geojson,gltf,har,ice,JSON-tmLanguage,mcmeta,tfstate,tfstate.backup,topojson,webapp,webmanifest,yy,yyp,jsonc,sublime-build,sublime-commands,sublime-completions,sublime-keymap,sublime-macro,sublime-menu,sublime-mousemap,sublime-project,sublime-settings,sublime-theme,sublime-workspace,sublime_metrics,sublime_session,json5,css,wxss,pcss,postcss,less,scss,handlebars,hbs,graphql,gql,graphqls,md,markdown,mdown,mdwn,mkd,mkdn,mkdown,ronn,scd,workbook,mdx,component.html,html,htm,html.hl,inc,xht,xhtml,mjml,vue,yml,mir,reek,rviz,sublime-syntax,syntax,yaml,yaml-tmlanguage,yaml.sed,yml.mysql,arb,axlsx,builder,eye,fcgi,gemfile,gemspec,god,jb,jbuilder,mspec,opal,pluginspec,podspec,rabl,rake,rb,rbi,rbuild,rbw,rbx,ru,ruby,thor,watchr,rbs,haml,javascript,jslib,jspre,importmap,4DForm,4DProject,code-snippets,livemd,hta}",
      "scheme": "file"
    },
    {
      "language": "javascript"
    },
    {
      "language": "mongo"
    },
    {
      "language": "javascriptreact"
    },
    {
      "language": "typescript"
    },
    {
      "language": "typescriptreact"
    },
    {
      "language": "json"
    },
    {
      "language": "jsonc"
    },
    {
      "language": "json5"
    },
    {
      "language": "css"
    },
    {
      "language": "postcss"
    },
    {
      "language": "less"
    },
    {
      "language": "scss"
    },
    {
      "language": "handlebars"
    },
    {
      "language": "graphql"
    },
    {
      "language": "markdown"
    },
    {
      "language": "mdx"
    },
    {
      "language": "html"
    },
    {
      "language": "vue"
    },
    {
      "language": "yaml"
    },
    {
      "language": "ansible"
    },
    {
      "language": "home-assistant"
    },
    {
      "language": "ruby"
    },
    {
      "language": "haml"
    },
    {
      "language": "jsonc",
      "scheme": "vscode-userdata"
    }
  ],
  "rangeLanguageSelector": [
    {
      "language": "javascript"
    },
    {
      "language": "javascriptreact"
    },
    {
      "language": "typescript"
    },
    {
      "language": "typescriptreact"
    },
    {
      "language": "json"
    },
    {
      "language": "graphql"
    },
    {
      "language": "handlebars"
    }
  ]
}
["INFO" - 2:53:11 PM] Forced formatting will not use ignore files.
["INFO" - 2:53:11 PM] Formatting file:///Users/ndbroadbent/code/app/example/Gemfile
["INFO" - 2:53:11 PM] Using config file at '/Users/ndbroadbent/code/app/example/.prettierrc'
["DEBUG" - 2:53:11 PM] Local prettier module path: '/Users/ndbroadbent/code/app/example/node_modules/prettier/index.js'
["DEBUG" - 2:53:11 PM] Using prettier version 2.7.1
["INFO" - 2:53:11 PM] Using ignore file (if present) at /Users/ndbroadbent/code/app/example/.prettierignore
["INFO" - 2:53:11 PM] File Info:
{
  "ignored": false,
  "inferredParser": "ruby"
}
["INFO" - 2:53:11 PM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 2:53:11 PM] Prettier Options:
{
  "filepath": "/Users/ndbroadbent/code/app/example/Gemfile",
  "parser": "ruby"
}
["INFO" - 2:53:12 PM] Formatting completed in 1.019ms.
["DEBUG" - 2:53:40 PM] Local prettier module path: '/Users/ndbroadbent/code/app/example/node_modules/prettier/index.js'
["DEBUG" - 2:53:43 PM] Local prettier module path: '/Users/ndbroadbent/code/app/example/node_modules/prettier/index.js'
["DEBUG" - 2:54:12 PM] Local prettier module path: '/Users/ndbroadbent/code/app/example/node_modules/prettier/index.js'
["INFO" - 2:54:41 PM] Formatting file:///Users/ndbroadbent/code/app/example/.vscode/settings.json
["INFO" - 2:54:41 PM] Using config file at '/Users/ndbroadbent/code/app/example/.prettierrc'
["DEBUG" - 2:54:41 PM] Local prettier module path: '/Users/ndbroadbent/code/app/example/node_modules/prettier/index.js'
["INFO" - 2:54:41 PM] Using ignore file (if present) at /Users/ndbroadbent/code/app/example/.prettierignore
["INFO" - 2:54:41 PM] File Info:
{
  "ignored": false,
  "inferredParser": "json"
}
["INFO" - 2:54:41 PM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 2:54:41 PM] Prettier Options:
{
  "filepath": "/Users/ndbroadbent/code/app/example/.vscode/settings.json",
  "parser": "json"
}
["INFO" - 2:54:41 PM] Formatting completed in 0.034ms.
["INFO" - 2:54:57 PM] Formatting vscode-userdata:/Users/ndbroadbent/Library/Application%20Support/Code/User/settings.json
["DEBUG" - 2:54:57 PM] Using bundled version of prettier.
["INFO" - 2:54:57 PM] File Info:
{
  "ignored": false,
  "inferredParser": "json"
}
["INFO" - 2:54:57 PM] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 2:54:57 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": "/Users/ndbroadbent/Library/Application Support/Code/User/settings.json",
  "parser": "json"
}
["ERROR" - 2:54:57 PM] Error formatting document.
["ERROR" - 2:54:57 PM] Unexpected token, expected "," (22:5)
  20 |     "*.scpt": "applescript",
  21 |     "*.latex": "latex"
> 22 |     "Gemfile": "gemfile"
     |     ^
  23 |   },
  24 |   "java.errors.incompleteClasspath.severity": "ignore",
  25 |   "files.exclude": {
SyntaxError: Unexpected token, expected "," (22:5)
  20 |     "*.scpt": "applescript",
  21 |     "*.latex": "latex"
> 22 |     "Gemfile": "gemfile"
     |     ^
  23 |   },
  24 |   "java.errors.incompleteClasspath.severity": "ignore",
  25 |   "files.exclude": {
    at p (/Users/ndbroadbent/.vscode/extensions/esbenp.prettier-vscode-9.5.0/node_modules/prettier/parser-babel.js:22:1038)
    at d (/Users/ndbroadbent/.vscode/extensions/esbenp.prettier-vscode-9.5.0/node_modules/prettier/parser-babel.js:22:1271)
    at Object.parse (/Users/ndbroadbent/.vscode/extensions/esbenp.prettier-vscode-9.5.0/node_modules/prettier/parser-babel.js:27:47065)
    at Object.parse (/Users/ndbroadbent/.vscode/extensions/esbenp.prettier-vscode-9.5.0/node_modules/prettier/index.js:7330:23)
    at coreFormat (/Users/ndbroadbent/.vscode/extensions/esbenp.prettier-vscode-9.5.0/node_modules/prettier/index.js:8641:18)
    at formatWithCursor2 (/Users/ndbroadbent/.vscode/extensions/esbenp.prettier-vscode-9.5.0/node_modules/prettier/index.js:8833:18)
    at /Users/ndbroadbent/.vscode/extensions/esbenp.prettier-vscode-9.5.0/node_modules/prettier/index.js:39137:12
    at Object.Success [as format] (/Users/ndbroadbent/.vscode/extensions/esbenp.prettier-vscode-9.5.0/node_modules/prettier/index.js:39151:12)
    at t.default.format (/Users/ndbroadbent/.vscode/extensions/esbenp.prettier-vscode-9.5.0/src/PrettierEditService.ts:463:45)
    at t.PrettierEditProvider.provideEdits (/Users/ndbroadbent/.vscode/extensions/esbenp.prettier-vscode-9.5.0/src/PrettierEditService.ts:322:22)
    at M.provideDocumentFormattingEdits (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:83:137239)
["INFO" - 2:54:57 PM] Formatting completed in 0.065ms.
["INFO" - 2:54:58 PM] Formatting vscode-userdata:/Users/ndbroadbent/Library/Application%20Support/Code/User/settings.json
["DEBUG" - 2:54:58 PM] Using bundled version of prettier.
["INFO" - 2:54:58 PM] File Info:
{
  "ignored": false,
  "inferredParser": "json"
}
["INFO" - 2:54:58 PM] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 2:54:58 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": "/Users/ndbroadbent/Library/Application Support/Code/User/settings.json",
  "parser": "json"
}
["INFO" - 2:54:58 PM] Formatting completed in 0.019ms.
["DEBUG" - 2:55:00 PM] Local prettier module path: '/Users/ndbroadbent/code/app/example/node_modules/prettier/index.js'
github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.