prettier-plugin-solidity
prettier-plugin-solidity copied to clipboard
"Format on Save" and "Format Document" are broken with the latest VS Code
Right after upgrading to VS Code 1.85.1, "Format on Save" and "Format Document" no longer work with a repo that worked perfectly with this plugin before.
Trying to Format Document results in a dialog:
Ttle: Configure Default Formatter
Description: Extension 'Prettier - Code formatter' is configured as formatter but it cannot format 'Solidity'-files
can you also post the version of the vsCode Prettier extension you have?
I'm running this setup:
Editor
VS Code v1.85.1
Prettier VS Code extension v10.1.0
Project
[email protected]
[email protected]
and "Format on Save" and "Format Document" work properly.
Haven't been able to replicate this.
macOS
14.1.1 (23B81)
Visual Studi Code
Version: 1.85.1
Commit: 0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2
Date: 2023-12-13T09:48:06.308Z (5 days 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 23.1.0
Prettier - Code formatter
v10.1.0
Node
$ node --version
v18.19.0
prettier
3.1.1
prettier-plugin-solidity
1.2.0
DEBUG
["INFO" - 4:56:44 PM] Extension Name: esbenp.prettier-vscode.
["INFO" - 4:56:44 PM] Extension Version: 10.1.0.
["DEBUG" - 4:56:44 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": "jsonc",
"scheme": "vscode-userdata"
}
],
"rangeLanguageSelector": [
{
"language": "javascript"
},
{
"language": "javascriptreact"
},
{
"language": "typescript"
},
{
"language": "typescriptreact"
},
{
"language": "json"
},
{
"language": "jsonc"
},
{
"language": "graphql"
}
]
}
["DEBUG" - 4:56:44 PM] Local prettier module path: '/Users/USER/PROJECT/node_modules/prettier/index.cjs'
["DEBUG" - 4:56:45 PM] Using prettier version 3.1.1
["DEBUG" - 4:56:45 PM] Enabling Prettier for Workspace /Users/USER/PROJECT
{
"languageSelector": [
{
"pattern": "/Users/USER/PROJECT/**/*.{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"
}
]
}
Where is your prettier
and prettier=plugin-solidity
installed? globally or in the current project's node_modules
folder?
Also what package manager are you using?
Ok, so just for uniformity, I switched to the same node
version as VS Code. I have prettier
and prettier-plugin-solidity
installed globally and locally, but I do use nvm
.
$ node --version
v18.15.0
$ npm list -g
/Users/USER/.nvm/versions/node/v18.15.0/lib
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
Still having the same issue with VS Code, even after a full OS restart.
Could it be that VS Code uses a separate instance of node
that does not have those plugins installed globally, which I cannot access via nvm
?
I have not yet tried uninstalling all prettier packages and extensions, restarting, and then reinstalling everything. I can do that, but just holding off in case you wanted debug info from the current state.
For what it's worth, I have another project with
$ npm ls
@PROJECT@VERSION /Users/USER/PROJECT2
├── [email protected]
├── [email protected]
└── [email protected]
and even with no globally installed prettier
and prettier-plugin-solidity
$ node --version
v18.15.0
$ npm list -g
/Users/USER/.nvm/versions/node/v18.15.0/lib
├── [email protected]
└── [email protected]
"Format Document" and "Format on Save" does work, even after a OS restart.
I have to say I could not reproduce this, I tried many combinations of location of the prettier
and prettier-plugin-solidity
libraries and formatting on save always worked.
Is this issue still relevant with the new version of VSCode 1.85.2
?
I also encounter this error:
Extension 'Prettier - Code formatter' is configured as formatter but it cannot format 'solidity'-files
My vscode version:
Version: 1.86.0
Commit: 05047486b6df5eb8d44b2ecd70ea3bdf775fd937
Date: 2024-01-31T10:27:46.147Z
Electron: 27.2.3
ElectronBuildId: 26495564
Chromium: 118.0.5993.159
Node.js: 18.17.1
V8: 11.8.172.18-electron.0
OS: Linux x64 6.5.0-15-generic
I solved this problem according to:
- https://github.com/prettier/prettier/issues/15092
- https://github.com/prettier/prettier-vscode/issues/3235
Add the below line:
"prettier.configPath": "./.prettierrc.js",
into file .vscode/settings.json
.