tonini / alchemist-server

Editor/IDE independent background server to inform about Elixir mix projects
193 stars 12 forks source link

Implement communication with server via socket #9

Closed slashmili closed 8 years ago

slashmili commented 8 years ago

Implement Server.IO and Server.Socket which each handles writing to clients separately and move the logic of executing the commands to Helpers.ProcessCommands. Refactor the commands to return the response as string.

Also introduce options: --listen runs Alchemist Server and listens to a random port --no-ansi disable :iex colors --env set the environment which loads the build file from

Starting the server

$ cd elixir_project
$ elixir path/to/alchemist-server/run.exs --env=dev --listen
ok|localhost:55580

Then the client connects and talk to the server like this:

$ nc localhost 55580
PING
PONG
END-OF-PING
COMP { "def", [ context: Elixir, imports: [Enum], aliases: [{MyList, List}] ] }
def
defexception/1
defoverridable/1
defstruct/1
def/2
defdelegate/2
defmacro/2
defmacrop/2
defmodule/2
defp/2
defprotocol/2
defimpl/3
END-OF-COMP
msaraiva commented 8 years ago

@slashmili I spent a couple of hours reviewing/testing your code. The only weird thing I've noticed while testing was that the number of processes kept increasing for every single request. After a very helpful :observer.start, I found this: https://github.com/slashmili/alchemist-server/blob/socket-server/lib/server/socket.exs#L41. Removing this line fixes the problem.

BTW, I really like this feature. AtomElixir will definitely use it. Thanks!

slashmili commented 8 years ago

Thanks @msaraiva, that code was left over after refactoring APIs to return string. I'll make the change.

Great! BTW with this change alchemist always listen to localhost to a random port. Do you see yourself using it with binding to a specific ip/port?

slashmili commented 8 years ago

@tonini I believe we are good to go!

msaraiva commented 8 years ago

@slashmili I think It would be nice to have a command line option to define the ip/port. This could be useful for people running elixir in a VM or container, like this. In those cases, the editor will not be able to start the server, which will be started manually, I guess. So if we had that option, we could save the values somehow and then reuse them even after a server restart. Anyway, it would be a nice feature but can be definitely done some other time. No need to rush on that.

tonini commented 8 years ago

@slashmili Thanks a lot for all your patience :)

Thanks for the awesome contribution 👍 💚 💛 💙 ❤️

slashmili commented 8 years ago

Thanks!