Skip to content

Commit cc66d60

Browse files
authored
adding harhat-solidity to the integration with VSCode (#707)
* adding harhat-solidity to the integration with VSCode * feedback * using Solidity instead of solidity
1 parent 966101f commit cc66d60

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

README.md

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ If you like this project, please consider contributing to our [Gitcoin grant](ht
1515

1616
Install both `prettier` and `prettier-plugin-solidity`:
1717

18-
```
18+
```Bash
1919
npm install --save-dev prettier prettier-plugin-solidity
2020
```
2121

2222
Run prettier in your contracts:
2323

24-
```
24+
```Bash
2525
npx prettier --write 'contracts/**/*.sol'
2626
```
2727

@@ -56,7 +56,7 @@ These are some of the projects using Prettier Solidity:
5656
Prettier provides a flexible system to configure the formatting rules of a project. For more information please refer to the [documentation](https://prettier.io/docs/en/configuration.html).
5757
The following is the default configuration internally used by this plugin.
5858

59-
```json
59+
```JSON
6060
{
6161
"overrides": [
6262
{
@@ -122,7 +122,7 @@ Many versions of the Solidity compiler have changes that affect how the code sho
122122

123123
One example of this are import directives. Before `0.7.4`, the compiler didn't accept multi-line import statements, so we always format them in a single line. But if you use the `compiler` option to indicate that you are using a version greater or equal than `0.7.4`, the plugin will use multi-line imports when it makes sense.
124124

125-
The solidity versions taken into consideration during formatting are:
125+
The Solidity versions taken into consideration during formatting are:
126126

127127
- `v0.7.4`: Versions prior `0.7.4` had a bug that would not interpret correctly imports unless they are formatted in a single line.
128128

@@ -178,7 +178,7 @@ The solidity versions taken into consideration during formatting are:
178178

179179
You might have a multi-version project, where different files are compiled with different compilers. If that's the case, you can use [overrides](https://prettier.io/docs/en/configuration.html#configuration-overrides) to have a more granular configuration:
180180

181-
```
181+
```JSON
182182
{
183183
"overrides": [
184184
{
@@ -237,7 +237,7 @@ version installed in the vim plugin's directory. The vim-plug directory depends
237237
let g:prettier#exec_cmd_path = '~/.vim/plugged/vim-prettier/node_modules/.bin/prettier'
238238
```
239239

240-
To check that everything is working, open a solidity file and run `:Prettier`.
240+
To check that everything is working, open a Solidity file and run `:Prettier`.
241241

242242
If you also want to autoformat every time you write the buffer, add these lines:
243243

@@ -250,16 +250,24 @@ Now Prettier will be run every time the file is saved.
250250

251251
### VSCode
252252

253-
VSCode is not familiar with the solidity language, so [`solidity`](https://marketplace.visualstudio.com/items?itemName=JuanBlanco.solidity) support needs to be installed.
253+
VSCode is not familiar with the Solidity language.
254+
There are 2 extensions that you can install to provide support for Solidity:
255+
256+
- [`solidity`](https://marketplace.visualstudio.com/items?itemName=JuanBlanco.solidity)
257+
- [`hardhat-solidity`](https://marketplace.visualstudio.com/items?itemName=NomicFoundation.hardhat-solidity)
254258

255259
```Bash
256260
code --install-extension JuanBlanco.solidity
261+
# or
262+
code --install-extension NomicFoundation.hardhat-solidity
257263
```
258264

259-
This extension provides basic integration with Prettier for most cases no further action is needed.
265+
> :warning: **These 2 extensions offer similar functionality and will clash with each other**: Please choose which one matches your projects better.
266+
267+
These extensions provide basic integration with Prettier; in most cases, no further action is needed.
260268

261269
Make sure your editor has format on save set to true.
262-
When you save VSCode will ask you what formatter would you like to use for the solidity language, you can choose `JuanBlanco.solidity`.
270+
When you save VSCode will ask you what formatter would you like to use for the Solidity language, you can choose `JuanBlanco.solidity` or `NomicFoundation.hardhat-solidity`.
263271

264272
At this point VSCode's `settings.json` should have a configuration similar to this:
265273

@@ -268,7 +276,8 @@ At this point VSCode's `settings.json` should have a configuration similar to th
268276
"editor.formatOnSave": true,
269277
"solidity.formatter": "prettier", // This is the default so it might be missing.
270278
"[solidity]": {
271-
"editor.defaultFormatter": "JuanBlanco.solidity"
279+
// "editor.defaultFormatter": "JuanBlanco.solidity"
280+
// "editor.defaultFormatter": "NomicFoundation.hardhat-solidity"
272281
}
273282
}
274283
```
@@ -281,7 +290,7 @@ code --install-extension esbenp.prettier-vscode
281290

282291
To interact with 3rd party plugins, `prettier-vscode` will look in the project's npm modules, so you'll need to have `prettier` and `prettier-plugin-solidity` in your `package.json`
283292

284-
```
293+
```Bash
285294
npm install --save-dev prettier prettier-plugin-solidity
286295
```
287296

@@ -318,7 +327,7 @@ Prettier Solidity does its best to be pretty and consistent, but in some cases i
318327

319328
Modifiers with no arguments are formatted with their parentheses removed, except for constructors. The reason for this is that Prettier Solidity cannot always tell apart a modifier from a base constructor. So modifiers in constructors are not modified. For example, this:
320329

321-
```solidity
330+
```Solidity
322331
contract Foo is Bar {
323332
constructor() Bar() modifier1 modifier2() modifier3(42) {}
324333
@@ -328,7 +337,7 @@ contract Foo is Bar {
328337

329338
will be formatted as
330339

331-
```solidity
340+
```Solidity
332341
contract Foo is Bar {
333342
constructor() Bar() modifier1 modifier2() modifier3(42) {}
334343

0 commit comments

Comments
 (0)