Ale: Scala support with SBT

Created on 13 Jan 2018  路  6Comments  路  Source: dense-analysis/ale

It'd be nice if Scala projects could be linted by SBT, as currently the scalac checker basically just checks syntax. SBT recently announced support for the language server protocol, so maybe that could be leveraged to help integrating with it?

I'd be willing to do some leg work on this if I can get some general pointers on how to go about it.

new tool

Most helpful comment

I have a working prototype of this, but it needs some polishing before it's ready.

All 6 comments

I have a working prototype of this, but it needs some polishing before it's ready.

@Ophirr33 Are you still working on this?

I tried this but didn't get it to work. Here is some documentation about sbt language server protocol: https://www.scala-sbt.org/1.x/docs/sbt-server.html

There seems to be two different modes

  • Unix domain socket (on windows: named pipe)
  • TCP socket

The first mode is the default in sbt 1.1.x and a bit simpler. It's the default mode and doesn't require token authentication, but ch_open doesn't seem to have implementation for Unix domain sockets. Is there a way to connect to unix domain sockets in ALE/vim?

The TCP mode can be activated by setting serverConnectionType to ConnectionType.Tcp and seems to require an authentication token in initializationOptions which can be read from a file.

I would be happy to help with this, but I'm quite beginner with vimscript and vim plugins, so I appreciate if someone can help or give me pointers.

EDIT: It seems that token is not needed atm despite the documentation (sbt version 1.2.1), it doesn't even exist in the active.json

Hey @TK009, I had dropped this but was actually thinking about picking it back up since I'm back to full time scala dev. You can see some of the old stuff I did over in https://github.com/ophirr33/ale. It currently works if you set the sbt server to tcp mode (and I have some debug printing stuff you'll want to delete), but unix sockets ofc don't work.
The three solutions I see going forward are:

  1. create a program that connects to the sbt server and lets ale communicate to it over stdin and stdout (might need to implement file watching on active.json)
  2. submit a patch to implement this stdin/stdout functionality into sbt itself
  3. submit a patch to allow vim to open channels from unix sockets
    Option 1 is probably the easiest solution, but it does make distribution a bit of a pain.
    If I do jump back into this I'll comment back here

Got this to work pretty well by making a little stdio wrapper for sbtServer (https://github.com/Ophirr33/sbtio). I'm gonna clean it up / set up some installation options, then I'll set up a PR. If you wanna play with it now you can use the sbtio branch in my ale fork and cargo install sbtio directly.

You can write a linter which connects to a TCP socket. See this recently added linter: https://github.com/w0rp/ale/blob/master/ale_linters/ruby/solargraph.vim

That will work on all platforms with Vim 8.0, or new enough NeoVim versions. We could consider adding support for connecting to Unix domain sockets, but Unix domain socket connections would only work in some versions of BSD or Linux for Vim 8.0 and up, (netcat -U would be needed) or in newer versions of NeoVim on any Unix system. I recommend using TCP instead.

@Ophirr33 has implemented this now. You may need to change the address setting to tell it how to connect to the server, and you'll have to start the server yourself.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sodiumjoe picture sodiumjoe  路  4Comments

ilyakopy picture ilyakopy  路  4Comments

chauncey-garrett picture chauncey-garrett  路  3Comments

aressler38 picture aressler38  路  3Comments

garand picture garand  路  4Comments