Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code formatting feature #155

Closed
poslegm opened this issue Jan 15, 2019 · 4 comments
Closed

Code formatting feature #155

poslegm opened this issue Jan 15, 2019 · 4 comments

Comments

@poslegm
Copy link

poslegm commented Jan 15, 2019

There is a great tool for automatic code formatting called scalafmt.

It will be great to be able to call it on current open file with one command like :ScalaFmt.

Similar feature realized in vim-go plugin for go fmt and it works well.

@derekwyatt
Copy link
Owner

I dunno if you'd want to spawn a JVM every time you wanted to format a file; this is something that is far more appropriate for SBT to do, IMHO. At any rate, I probably won't be writing this one, but if someone has a decent implementation, a PR would be fine.

@poslegm
Copy link
Author

poslegm commented Jan 15, 2019

Oh, while writing this issue I relied on my experience with a scalafmt-intellij plugin which works very fast. But I missed out that Intellij plugin just call scalafmt functions from already running JVM.

I measured the launch time of scalafmt-cli and it will obviously annoy the user 😒
In this case, I see no reason to keep this issue open.

@poslegm poslegm closed this as completed Jan 15, 2019
@ches
Copy link
Collaborator

ches commented Jan 20, 2019

FWIW there may be alternative ways to get this, through language server processes that stay active so are fast to invoke:

  • Metals supports scalafmt.
  • ENSIME had work in progress on scalafmt before, I'm not sure where it stands now.

@poslegm
Copy link
Author

poslegm commented Jan 21, 2019

Eventually I achive it in the following way:

  1. vim-autoformat plugin with config
let g:formatdef_scalafmt = "'scalafmt --stdin'"
let g:formatters_scala = ['scalafmt']
  1. scalafmt built with GraalVM. GraalVM allows instant scalafmt CLI launch:
scalafmt --help  0,01s user 0,02s system 15% cpu 0,199 total

But without GraalVM it is unviable idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants