Skip to content

Commit 7d1dbf1

Browse files
lukaszsamsonaxelson
authored andcommitted
add @impl attributes to behaviour callbacks (elixir-editors#99)
1 parent ca6ef9d commit 7d1dbf1

File tree

12 files changed

+65
-14
lines changed

12 files changed

+65
-14
lines changed

apps/debugger/lib/debugger.ex

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ defmodule ElixirLS.Debugger do
55

66
use Application
77

8-
# See http://elixir-lang.org/docs/stable/elixir/Application.html
9-
# for more information on OTP Applications
8+
@impl Application
109
def start(_type, _args) do
1110
import Supervisor.Spec, warn: false
1211

@@ -15,16 +14,14 @@ defmodule ElixirLS.Debugger do
1514
ElixirLS.Debugger.Output.start(ElixirLS.Debugger.Output)
1615

1716
children = [
18-
# Define workers and child supervisors to be supervised
1917
worker(ElixirLS.Debugger.Server, [[name: ElixirLS.Debugger.Server]])
2018
]
2119

22-
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
23-
# for other strategies and supported options
2420
opts = [strategy: :one_for_one, name: ElixirLS.Debugger.Supervisor, max_restarts: 0]
2521
Supervisor.start_link(children, opts)
2622
end
2723

24+
@impl Application
2825
def stop(_state) do
2926
if ElixirLS.Utils.WireProtocol.io_intercepted?() do
3027
IO.puts(:standard_error, "ElixirLS debugger has crashed")

apps/debugger/lib/debugger/output.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,18 @@ defmodule ElixirLS.Debugger.Output do
3535

3636
## Server callbacks
3737

38+
@impl GenServer
3839
def init(:ok) do
3940
{:ok, 1}
4041
end
4142

43+
@impl GenServer
4244
def handle_call({:send_response, request_packet, body}, _from, seq) do
4345
send(response(seq, request_packet["seq"], request_packet["command"], body))
4446
{:reply, :ok, seq + 1}
4547
end
4648

49+
@impl GenServer
4750
def handle_call({:send_event, event, body}, _from, seq) do
4851
send(event(seq, event, body))
4952
{:reply, :ok, seq + 1}

apps/debugger/lib/debugger/server.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,21 @@ defmodule ElixirLS.Debugger.Server do
5252

5353
## Server Callbacks
5454

55+
@impl GenServer
5556
def init(opts) do
5657
:int.start()
5758
state = if opts[:output], do: %__MODULE__{output: opts[:output]}, else: %__MODULE__{}
5859
{:ok, state}
5960
end
6061

62+
@impl GenServer
6163
def handle_cast({:receive_packet, request(_, _) = packet}, state) do
6264
{response_body, state} = handle_request(packet, state)
6365
Output.send_response(packet, response_body)
6466
{:noreply, state}
6567
end
6668

69+
@impl GenServer
6770
def handle_cast({:breakpoint_reached, pid}, state) do
6871
{state, thread_id} = ensure_thread_id(state, pid)
6972

@@ -76,6 +79,7 @@ defmodule ElixirLS.Debugger.Server do
7679
{:noreply, state}
7780
end
7881

82+
@impl GenServer
7983
def handle_info({:DOWN, ref, :process, _pid, reason}, %{task_ref: ref} = state) do
8084
exit_code =
8185
case reason do
@@ -97,17 +101,20 @@ defmodule ElixirLS.Debugger.Server do
97101
{:noreply, %{state | task_ref: nil}}
98102
end
99103

104+
@impl GenServer
100105
def handle_info({:EXIT, _, :normal}, state) do
101106
{:noreply, state}
102107
end
103108

104109
# If we get the disconnect request from the client, we send :disconnect to the server so it will
105110
# die right after responding to the request
111+
@impl GenServer
106112
def handle_info(:disconnect, state) do
107113
System.halt(0)
108114
{:noreply, state}
109115
end
110116

117+
@impl GenServer
111118
def terminate(reason, _state) do
112119
if reason != :normal do
113120
IO.puts(:standard_error, "(Debugger) Terminating because #{Exception.format_exit(reason)}")

apps/elixir_ls_utils/lib/mix.tasks.elixir_ls.release.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
defmodule Mix.Tasks.ElixirLs.Release do
2+
use Mix.Task
3+
24
@switches [destination: :string, zip: :string]
35
@aliases [o: :destination, z: :zip]
46

7+
@impl Mix.Task
58
def run(args) do
69
version_warning()
710
{opts, _} = OptionParser.parse!(args, aliases: @aliases, switches: @switches)

apps/elixir_ls_utils/lib/output_device.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,36 @@ defmodule ElixirLS.Utils.OutputDevice do
2020

2121
## Server callbacks
2222

23+
@impl GenServer
2324
def init({device, output_fn}) do
2425
{:ok, {device, output_fn}}
2526
end
2627

28+
@impl GenServer
2729
def handle_info({:io_request, from, reply_as, {:put_chars, _encoding, characters}}, s) do
2830
output(from, reply_as, characters, s)
2931
{:noreply, s}
3032
end
3133

34+
@impl GenServer
3235
def handle_info({:io_request, from, reply_as, {:put_chars, characters}}, s) do
3336
output(from, reply_as, characters, s)
3437
{:noreply, s}
3538
end
3639

40+
@impl GenServer
3741
def handle_info({:io_request, from, reply_as, {:put_chars, _encoding, module, func, args}}, s) do
3842
output(from, reply_as, apply(module, func, args), s)
3943
{:noreply, s}
4044
end
4145

46+
@impl GenServer
4247
def handle_info({:io_request, from, reply_as, {:put_chars, module, func, args}}, s) do
4348
output(from, reply_as, apply(module, func, args), s)
4449
{:noreply, s}
4550
end
4651

52+
@impl GenServer
4753
def handle_info({:io_request, from, reply_as, {:requests, reqs}}, s) do
4854
for req <- reqs do
4955
handle_info({:io_request, from, reply_as, req}, s)
@@ -53,6 +59,7 @@ defmodule ElixirLS.Utils.OutputDevice do
5359
end
5460

5561
# Any other message (get_geometry, set_opts, etc.) goes directly to original device
62+
@impl GenServer
5663
def handle_info(msg, {device, _} = s) do
5764
send(device, msg)
5865
{:noreply, s}

apps/elixir_ls_utils/test/support/packet_capture.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ defmodule ElixirLS.Utils.PacketCapture do
1616

1717
## Server Callbacks
1818

19+
@impl GenServer
1920
def init(parent) do
2021
{:ok, parent}
2122
end
2223

24+
@impl GenServer
2325
def handle_info({:io_request, from, reply_as, {:put_chars, _encoding, chars}}, parent) do
2426
handle_output(to_string(chars), from, reply_as, parent)
2527
end
2628

29+
@impl GenServer
2730
def handle_info(
2831
{:io_request, from, reply_as, {:put_chars, _encoding, module, fun, args}},
2932
parent

apps/language_server/lib/language_server.ex

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,20 @@ defmodule ElixirLS.LanguageServer do
55
require Logger
66
use Application
77

8-
# See http://elixir-lang.org/docs/stable/elixir/Application.html
9-
# for more information on OTP Applications
8+
@impl Application
109
def start(_type, _args) do
1110
import Supervisor.Spec, warn: false
1211

1312
children = [
14-
# Define workers and child supervisors to be supervised
1513
worker(ElixirLS.LanguageServer.Server, [ElixirLS.LanguageServer.Server]),
1614
worker(ElixirLS.LanguageServer.JsonRpc, [[name: ElixirLS.LanguageServer.JsonRpc]])
1715
]
1816

19-
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
20-
# for other strategies and supported options
2117
opts = [strategy: :one_for_one, name: ElixirLS.LanguageServer.Supervisor, max_restarts: 0]
2218
Supervisor.start_link(children, opts)
2319
end
2420

21+
@impl Application
2522
def stop(_state) do
2623
if ElixirLS.Utils.WireProtocol.io_intercepted?() do
2724
ElixirLS.LanguageServer.JsonRpc.show_message(

apps/language_server/lib/language_server/dialyzer.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ defmodule ElixirLS.LanguageServer.Dialyzer do
9494

9595
# Server callbacks
9696

97+
@impl GenServer
9798
def init({parent, root_path}) do
9899
state = %__MODULE__{parent: parent, root_path: root_path}
99100

@@ -117,6 +118,7 @@ defmodule ElixirLS.LanguageServer.Dialyzer do
117118
{:ok, state}
118119
end
119120

121+
@impl GenServer
120122
def handle_call(
121123
{:analysis_finished, _status, active_plt, mod_deps, md5, warnings, timestamp, build_ref},
122124
_from,
@@ -147,11 +149,13 @@ defmodule ElixirLS.LanguageServer.Dialyzer do
147149
{:reply, :ok, state}
148150
end
149151

152+
@impl GenServer
150153
def handle_call({:suggest_contracts, files}, _from, %{plt: plt} = state) do
151154
specs = if is_nil(plt), do: [], else: SuccessTypings.suggest_contracts(plt, files)
152155
{:reply, specs, state}
153156
end
154157

158+
@impl GenServer
155159
def handle_cast({:analyze, build_ref, warn_opts, warning_format}, state) do
156160
state =
157161
ElixirLS.LanguageServer.Build.with_build_lock(fn ->
@@ -181,10 +185,12 @@ defmodule ElixirLS.LanguageServer.Dialyzer do
181185
{:noreply, state}
182186
end
183187

188+
@impl GenServer
184189
def handle_info({:"ETS-TRANSFER", _, _, _}, state) do
185190
{:noreply, state}
186191
end
187192

193+
@impl GenServer
188194
def terminate(reason, _state) do
189195
if reason != :normal do
190196
JsonRpc.show_message(

apps/language_server/lib/language_server/dialyzer/supervisor.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ defmodule ElixirLS.LanguageServer.Dialyzer.Supervisor do
66
Supervisor.start_link(__MODULE__, {parent, root_path})
77
end
88

9+
@impl Supervisor
910
def init({parent, root_path}) do
1011
Supervisor.init(
1112
[

apps/language_server/lib/language_server/json_rpc.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ defmodule ElixirLS.LanguageServer.JsonRpc do
123123

124124
## Server callbacks
125125

126+
@impl GenServer
126127
def init(opts) do
127128
state =
128129
if language_server = opts[:language_server] do
@@ -134,30 +135,35 @@ defmodule ElixirLS.LanguageServer.JsonRpc do
134135
{:ok, state}
135136
end
136137

138+
@impl GenServer
137139
def handle_call({:packet, notification(_) = packet}, _from, state) do
138140
ElixirLS.LanguageServer.Server.receive_packet(packet)
139141
{:reply, :ok, state}
140142
end
141143

144+
@impl GenServer
142145
def handle_call({:packet, request(_, _, _) = packet}, _from, state) do
143146
ElixirLS.LanguageServer.Server.receive_packet(packet)
144147
{:reply, :ok, state}
145148
end
146149

150+
@impl GenServer
147151
def handle_call({:packet, response(id, result)}, _from, state) do
148152
%{^id => from} = state.outgoing_requests
149153
GenServer.reply(from, {:ok, result})
150154
state = update_in(state.outgoing_requests, &Map.delete(&1, id))
151155
{:reply, :ok, state}
152156
end
153157

158+
@impl GenServer
154159
def handle_call({:packet, error_response(id, code, message)}, _from, state) do
155160
%{^id => from} = state.outgoing_requests
156161
GenServer.reply(from, {:error, code, message})
157162
state = update_in(state.outgoing_requests, &Map.delete(&1, id))
158163
{:reply, :ok, state}
159164
end
160165

166+
@impl GenServer
161167
def handle_call({:request, method, params}, from, state) do
162168
send(request(state.next_id, method, params))
163169
state = update_in(state.outgoing_requests, &Map.put(&1, state.next_id, from))

apps/language_server/lib/language_server/mix_shell.ex

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@ defmodule ElixirLS.LanguageServer.MixShell do
99

1010
@behaviour Mix.Shell
1111

12-
defdelegate(print_app, to: Mix.Shell.IO)
13-
defdelegate(cmd(command, opts \\ []), to: Mix.Shell.IO)
14-
defdelegate(info(message), to: Mix.Shell.IO)
15-
defdelegate(error(message), to: Mix.Shell.IO)
12+
@impl Mix.Shell
13+
defdelegate print_app, to: Mix.Shell.IO
1614

15+
@impl Mix.Shell
16+
defdelegate cmd(command, opts \\ []), to: Mix.Shell.IO
17+
18+
@impl Mix.Shell
19+
defdelegate info(message), to: Mix.Shell.IO
20+
21+
@impl Mix.Shell
22+
defdelegate error(message), to: Mix.Shell.IO
23+
24+
@impl Mix.Shell
1725
def prompt(message) do
1826
if WireProtocol.io_intercepted?() do
1927
IO.puts(message)
@@ -29,6 +37,7 @@ defmodule ElixirLS.LanguageServer.MixShell do
2937
end
3038
end
3139

40+
@impl Mix.Shell
3241
def yes?(message) do
3342
if WireProtocol.io_intercepted?() do
3443
response =

0 commit comments

Comments
 (0)