Skip to content

Commit

Permalink
Merge pull request #19 from synic/synic/add-stdio-option
Browse files Browse the repository at this point in the history
feat: add --stdio option
  • Loading branch information
gp-pereira authored Dec 28, 2024
2 parents 4b849b7 + e9cb7b0 commit db6e703
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
7 changes: 7 additions & 0 deletions bin/start-stdio
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

# used for mason.nvim

cd "$(dirname "$0")"/.. || exit 1

./bin/start --stdio "$0"
20 changes: 17 additions & 3 deletions lib/refactorex/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Refactorex.Application do
[
{
GenLSP.Buffer,
[communication: {GenLSP.Communication.TCP, [port: port()]}]
[communication: communication_config()]
},
{Refactorex.Logger, []},
{Refactorex.NameCache, []},
Expand All @@ -20,10 +20,24 @@ defmodule Refactorex.Application do
)
end

defp port do
defp parse_opts do
System.argv()
|> OptionParser.parse(strict: [port: :integer])
|> OptionParser.parse(strict: [port: :integer, stdio: :boolean])
|> elem(0)
end

defp port do
parse_opts()
|> Keyword.get(:port, @default_port)
end

defp communication_config do
opts = parse_opts()

if Keyword.get(opts, :stdio, false) do
{GenLSP.Communication.Stdio, []}
else
{GenLSP.Communication.TCP, [port: port()]}
end
end
end

0 comments on commit db6e703

Please sign in to comment.