prettier / prettier-vscode

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

Extension 'Prettier - Code formatter' is configured as formatter but it cannot format 'Astro'-files #3247

Closed testersen closed 5 months ago

testersen commented 5 months ago

When editor.formatOnSave is enabled and I save an astro file, nothing happens.

When I use the Format Document command I the error I put as title: Extension 'Prettier - Code formatter' is configured as formatter but it cannot format 'Astro'-files.

When I use the Format Document (Forced) command it works.

Expected result, format on save option should work along with the Format Document command.

Versions

# VS Code Extensions
esbenp.prettier-vscode = "10.1.0"
astro-build.astro-vscode = "2.5.4"

# package.json
prettier = "3.1.1"
prettier-plugin-astro = "0.12.2"

VS Code

Version: 1.85.1
Commit: 0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2
Date: 2023-12-13T09:48:16.874Z (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 arm64 22.6.0
anxpara commented 5 months ago

i think this repo is dead

@ntotten

cryptominnow commented 5 months ago

To fix this, you need to install the official astro vscode plugin then configure it as the default formatter for files ending with the .astro extension in settings.json

After you've installed the plugin, running the Format Document command on an astro component should warn you and provide a prompt to configure a default formatter. Select astro-build.astro-vscode and it should automatically configure this for you.

Alternatively, you can do so manually by opening the command palette with ctrl + shift + p and searching for Preferences: Open Settings (JSON) (select the command variant corresponding to whichever scope you wish to configure). Add the following key-value pair to the root json object:

"[astro]": {
  "editor.defaultFormatter": "astro-build.astro-vscode"
}

Save and exit and you may need to reload your editor but prettier should recognize astro files and format them as expected.

testersen commented 5 months ago

Yup, that did solve the issue, thank you! :)

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