prettier / prettier-vscode

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

Prettier-VSCode doesn't format selections in HTML documents #3241

Closed markchagers closed 6 months ago

markchagers commented 9 months ago

Summary

When formatting html files with prettier-vscode configured as html-formatter, the VSCode command "Format selection" does not work. The command "Format Document" works as expected.

Github Repository to Reproduce Issue

issue-repo

Steps To Reproduce:

  1. Select part of the contents of an html file
  2. Open Command Palette (Ctrl-shift-P)
  3. Choose "Format Selection"

Expected result

The selected line(s) in the html file should be formatted

Actual result

An error pops up with the following text: Configure Default Formatter Extension 'Prettier - Code formatter' is configured as formatter but it cannot format 'HTML'-files Sometimes, usually right after starting VSCode, the error does not appear, but the command still does nothing. On all subsequent attempts the error appears.

Additional information

image

VS Code Version:

Version: 1.85.1 Commit: 0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2 Date: 2023-12-13T09:48:06.308Z (1 wk ago) Electron: 25.9.7 ElectronBuildId: 25551756 Chromium: 114.0.5735.289 Node.js: 18.15.0 V8: 11.4.183.29-electron.0 OS: Darwin x64 22.6.0

Prettier Extension Version:

v10.1.0

OS and version:

Mac OS Ventura 13.6.3 13.6.3 (22G436)

Prettier Log Output

["INFO" - 14:27:14] Extension Name: esbenp.prettier-vscode.
["INFO" - 14:27:14] Extension Version: 10.1.0.
["DEBUG" - 14:27:14] 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": "jsonc",
      "scheme": "vscode-userdata"
    }
  ],
  "rangeLanguageSelector": [
    {
      "language": "javascript"
    },
    {
      "language": "javascriptreact"
    },
    {
      "language": "typescript"
    },
    {
      "language": "typescriptreact"
    },
    {
      "language": "json"
    },
    {
      "language": "jsonc"
    },
    {
      "language": "graphql"
    }
  ]
}
["DEBUG" - 14:27:14] Local prettier module path: '/Users/mark/dev/visionweb_frontend/node_modules/prettier/index.cjs'
["DEBUG" - 14:27:14] Using prettier version 3.1.1
["DEBUG" - 14:27:14] Enabling Prettier for Workspace /Users/mark/dev/visionweb_frontend
{
  "languageSelector": [
    {
      "pattern": "/Users/mark/dev/visionweb_frontend/./src/**/*.html",
      "scheme": "file"
    },
    {
      "pattern": "/Users/mark/dev/visionweb_frontend/**/*.{js,_js,bones,cjs,es,es6,frag,gs,jake,javascript,jsb,jscad,jsfl,jslib,jsm,jspre,jss,mjs,njs,pac,sjs,ssjs,xsjs,xsjslib,wxs,js.flow,jsx,ts,cts,mts,tsx,importmap,json,4DForm,4DProject,avsc,geojson,gltf,har,ice,JSON-tmLanguage,mcmeta,tfstate,tfstate.backup,topojson,webapp,webmanifest,yy,yyp,jsonc,code-snippets,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,livemd,markdown,mdown,mdwn,mkd,mkdn,mkdown,ronn,scd,workbook,mdx,component.html,html,hta,htm,html.hl,inc,xht,xhtml,mjml,vue,yml,mir,reek,rviz,sublime-syntax,syntax,yaml,yaml-tmlanguage,yaml.sed,yml.mysql,code-workspace}",
      "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": "jsonc",
      "scheme": "vscode-userdata"
    }
  ],
  "rangeLanguageSelector": [
    {
      "language": "javascript"
    },
    {
      "language": "javascriptreact"
    },
    {
      "language": "typescript"
    },
    {
      "language": "typescriptreact"
    },
    {
      "language": "json"
    },
    {
      "language": "jsonc"
    },
    {
      "language": "graphql"
    }
  ]
}
markchagers commented 9 months ago

I noticed that HTML does appear in the languageSelector array, but is absent from the rangeLanguageSelector. Could that have anything to do with this issue? I searched for a way to add it to this array, but could not find anything.

mattparrilla commented 8 months ago

I'm having the same issue but with CSS files.

(Format document works, format selection shows me the "Configure Default Formatter" popup)

ntotten commented 6 months ago

Its not supported.

github-actions[bot] commented 3 months 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.