dart-lang/dart-vim-plugin

Auto format add semicolon?

npearson72 opened this issue · 2 comments

Is it possible for the auto formatting to automatically add the needed semi-colons? Currently the vim lsp tool I'm using only lints those problems. Would be nice if it just added them for me.

Or is this further upstream at the sdk?

dartfmt itself is written such that it only ever makes changes to whitespace but never to the program AST it manipulates. I believe it now includes --fix-* flags that may make changes to the code itself but I haven't given that a go so am unfamiliar with how those work.

Inserting missing semi-colons feels like a pretty tricky problem in general, but I'm sure there's a subset of missing semi-colon scenarios the analyzer can catch pretty well. Overall, I don't think it'd be a fit for the vim plugin and I admit my initial reaction is that I wouldn't want to provide a feature that would encourage people to get lazy about semi-colons when fixing them isn't always straightforward.

But -- a few possibilities here:

  • On the off chance that dartfmt has a --fix option that does this, I believe we already support custom flags for dartfmt (e.g. for number of columns), so you could add the flag there
  • The analyzer has an API for quick fixes if I recall correctly, which is what's used in IDE support, if the analyzer already has a quick-fix for missing semicolon errors, it's possible that could be wired through via the LSP plugin

The analyzer/linter includes support for quickfixes in its API, if I recall correctly. @natebosch would know if there's an easy way to wire those into vim. See the bit of the readme on LSP plugins.

TL;DR I suspect the answer is wontfix in this plugin, but there may be other ways to achieve what you want.

dartfmt does not have an option to insert semicolons. The analyzer does indeed have a quick fix for these. If you are using vim-lsc you can invoke it by hitting ga or :LSClientFindCodeActions while the cursor is on a line with a diagnostic about a missing semicolon, then tap the number corresponding to the fix. Other LSP clients likely have options for this, search for "code actions" in the docs for your client to get started.