7

I am coming from languages that don't use semicolons by default and I keep forgetting adding them all the time. Also it's annoying to type ; all the time.

Is there any VS Code plugin that will add semicolons on save automatically?

If it's not possible in VS Code, is it possible in some other editor like IntelliJ or something?

kipkipe
  • 121
  • 2
  • 4

3 Answers3

22

For anyone looking for an answer to this problem, add this to your settings.json in VSCode:

"editor.codeActionsOnSave": {
  "quickfix.insertSemicolon": true,
},
Matheus Mendes
  • 221
  • 2
  • 3
0

That's not directly possible at the moment. You may try this extension: https://marketplace.visualstudio.com/items?itemName=vmsynkov.colonize

Gpack
  • 1,878
  • 3
  • 18
  • 45
  • Wow, that's super weird it is not possible. Hmm, another blow into my plans. Perhaps I should try Kotlin. Hmm. – kipkipe Jun 09 '21 at 07:30
  • 2
    @kipkipe The semicolons in Dart is part of the semantics of the language, which have then been designed based on the fact you have semicolons, and you can't therefore not, in all situations, automatically determine where the semicolon should be placed since it can change how your program are being executed. – julemand101 Jun 09 '21 at 09:21
  • 3
    As @julemand101 says, it's not possible to automatically add missing semicolons to a Dart file and be certain to not break an otherwise correct program. The syntax is not semicolon-agnostic enough for that to be possible. There are places where you can *safely* insert a semicolon, where the program is "correct" (syntactically and for static-type-analysis) both with and with the semicolon, but where the *meaning* changes if you add it. If you are OK with potential false positives in the "should I insert semicolon here" algorithm, I'm sure it's possible to do *something* heuristically. – lrn Jun 09 '21 at 11:00
  • 1
    @kipkipe are you going to switch language because of this? – Dani Dec 14 '22 at 10:04
0

First, go to the command palette, then search for "setting.json" and add the following in that file:

"editor.codeActionsOnSave": {
  "quickfix.insertSemicolon": true,
}
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83