Skip to content

Commit a20cd04

Browse files
committed
chore: styler 💅
1 parent c69e99d commit a20cd04

14 files changed

+76
-91
lines changed

.formatter.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
],
1010
line_length: 120,
1111
import_deps: [:gen_lsp],
12+
plugins: [Styler],
1213
inputs: [
1314
"{mix,.formatter}.exs",
1415
"{config,lib,}/**/*.{ex,exs}",

lib/next_ls.ex

Lines changed: 36 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,38 @@ defmodule NextLS do
22
@moduledoc false
33
use GenLSP
44

5+
alias GenLSP.Enumerations.ErrorCodes
6+
alias GenLSP.Enumerations.TextDocumentSyncKind
57
alias GenLSP.ErrorResponse
6-
7-
alias GenLSP.Enumerations.{
8-
ErrorCodes,
9-
TextDocumentSyncKind
10-
}
11-
12-
alias GenLSP.Notifications.{
13-
Exit,
14-
Initialized,
15-
TextDocumentDidChange,
16-
TextDocumentDidOpen,
17-
TextDocumentDidSave
18-
}
19-
20-
alias GenLSP.Requests.{
21-
Initialize,
22-
Shutdown,
23-
TextDocumentDocumentSymbol,
24-
TextDocumentDefinition,
25-
TextDocumentFormatting,
26-
WorkspaceSymbol
27-
}
28-
29-
alias GenLSP.Structures.{
30-
DidOpenTextDocumentParams,
31-
InitializeParams,
32-
InitializeResult,
33-
Location,
34-
Position,
35-
Range,
36-
SaveOptions,
37-
ServerCapabilities,
38-
SymbolInformation,
39-
TextDocumentItem,
40-
TextDocumentSyncOptions,
41-
TextEdit,
42-
WorkDoneProgressBegin,
43-
WorkDoneProgressEnd
44-
}
45-
8+
alias GenLSP.Notifications.Exit
9+
alias GenLSP.Notifications.Initialized
10+
alias GenLSP.Notifications.TextDocumentDidChange
11+
alias GenLSP.Notifications.TextDocumentDidOpen
12+
alias GenLSP.Notifications.TextDocumentDidSave
13+
alias GenLSP.Requests.Initialize
14+
alias GenLSP.Requests.Shutdown
15+
alias GenLSP.Requests.TextDocumentDefinition
16+
alias GenLSP.Requests.TextDocumentDocumentSymbol
17+
alias GenLSP.Requests.TextDocumentFormatting
18+
alias GenLSP.Requests.WorkspaceSymbol
19+
alias GenLSP.Structures.DidOpenTextDocumentParams
20+
alias GenLSP.Structures.InitializeParams
21+
alias GenLSP.Structures.InitializeResult
22+
alias GenLSP.Structures.Location
23+
alias GenLSP.Structures.Position
24+
alias GenLSP.Structures.Range
25+
alias GenLSP.Structures.SaveOptions
26+
alias GenLSP.Structures.ServerCapabilities
27+
alias GenLSP.Structures.SymbolInformation
28+
alias GenLSP.Structures.TextDocumentItem
29+
alias GenLSP.Structures.TextDocumentSyncOptions
30+
alias GenLSP.Structures.TextEdit
31+
alias GenLSP.Structures.WorkDoneProgressBegin
32+
alias GenLSP.Structures.WorkDoneProgressEnd
33+
alias NextLS.Definition
4634
alias NextLS.DiagnosticCache
4735
alias NextLS.Runtime
4836
alias NextLS.SymbolTable
49-
alias NextLS.Definition
5037

5138
def start_link(args) do
5239
{args, opts} =
@@ -222,7 +209,7 @@ defmodule NextLS do
222209
document = lsp.assigns.documents[uri]
223210

224211
{_, %{runtime: runtime}} =
225-
lsp.assigns.runtimes |> Enum.find(fn {_name, %{uri: wuri}} -> String.starts_with?(uri, wuri) end)
212+
Enum.find(lsp.assigns.runtimes, fn {_name, %{uri: wuri}} -> String.starts_with?(uri, wuri) end)
226213

227214
with {:ok, {formatter, _}} <- Runtime.call(runtime, {Mix.Tasks.Format, :formatter_for_file, [".formatter.exs"]}),
228215
{:ok, response} when is_binary(response) or is_list(response) <-
@@ -325,7 +312,7 @@ defmodule NextLS do
325312
end
326313

327314
refresh_refs =
328-
Enum.zip_with(tasks, runtimes, fn task, {_name, runtime} -> {task.ref, runtime.refresh_ref} end) |> Map.new()
315+
tasks |> Enum.zip_with(runtimes, fn task, {_name, runtime} -> {task.ref, runtime.refresh_ref} end) |> Map.new()
329316

330317
{:noreply,
331318
assign(lsp,
@@ -340,10 +327,7 @@ defmodule NextLS do
340327

341328
def handle_notification(
342329
%TextDocumentDidSave{
343-
params: %GenLSP.Structures.DidSaveTextDocumentParams{
344-
text: text,
345-
text_document: %{uri: uri}
346-
}
330+
params: %GenLSP.Structures.DidSaveTextDocumentParams{text: text, text_document: %{uri: uri}}
347331
},
348332
%{assigns: %{ready: true}} = lsp
349333
) do
@@ -363,7 +347,7 @@ defmodule NextLS do
363347
end
364348

365349
refresh_refs =
366-
Enum.zip_with(tasks, runtimes, fn task, {_name, runtime} -> {task.ref, runtime.refresh_ref} end) |> Map.new()
350+
tasks |> Enum.zip_with(runtimes, fn task, {_name, runtime} -> {task.ref, runtime.refresh_ref} end) |> Map.new()
367351

368352
{:noreply,
369353
lsp
@@ -376,12 +360,7 @@ defmodule NextLS do
376360
end
377361

378362
def handle_notification(
379-
%TextDocumentDidChange{
380-
params: %{
381-
text_document: %{uri: uri},
382-
content_changes: [%{text: text}]
383-
}
384-
},
363+
%TextDocumentDidChange{params: %{text_document: %{uri: uri}, content_changes: [%{text: text}]}},
385364
lsp
386365
) do
387366
for task <- Task.Supervisor.children(lsp.assigns.task_supervisor),
@@ -394,9 +373,7 @@ defmodule NextLS do
394373

395374
def handle_notification(
396375
%TextDocumentDidOpen{
397-
params: %DidOpenTextDocumentParams{
398-
text_document: %TextDocumentItem{text: text, uri: uri}
399-
}
376+
params: %DidOpenTextDocumentParams{text_document: %TextDocumentItem{text: text, uri: uri}}
400377
},
401378
lsp
402379
) do
@@ -531,14 +508,14 @@ defmodule NextLS do
531508
})
532509
end
533510

534-
defp token() do
511+
defp token do
535512
8
536513
|> :crypto.strong_rand_bytes()
537514
|> Base.url_encode64(padding: false)
538515
|> binary_part(0, 8)
539516
end
540517

541-
defp version() do
518+
defp version do
542519
case :application.get_key(:next_ls, :vsn) do
543520
{:ok, version} -> to_string(version)
544521
_ -> "dev"

lib/next_ls/definition.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
defmodule NextLS.Definition do
2+
@moduledoc false
23
def fetch(file, {line, col}, dets_symbol_table, dets_ref_table) do
34
ref =
45
:dets.select(

lib/next_ls/document_symbol.ex

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
defmodule NextLS.DocumentSymbol do
2-
alias GenLSP.Structures.{
3-
Position,
4-
Range,
5-
DocumentSymbol
6-
}
2+
@moduledoc false
3+
alias GenLSP.Structures.DocumentSymbol
4+
alias GenLSP.Structures.Position
5+
alias GenLSP.Structures.Range
76

87
# we set the literal encoder so that we can know when atoms and strings start and end
98
# this makes it useful for knowing the exact locations of struct field definitions
@@ -55,7 +54,7 @@ defmodule NextLS.DocumentSymbol do
5554
end
5655

5756
defp walker({:describe, meta, [name | children]}, mod) do
58-
name = ("describe " <> Macro.to_string(unliteral(name))) |> String.replace("\n", "")
57+
name = String.replace("describe " <> Macro.to_string(unliteral(name)), "\n", "")
5958

6059
%DocumentSymbol{
6160
name: name,
@@ -158,7 +157,7 @@ defmodule NextLS.DocumentSymbol do
158157

159158
defp walker({type, meta, [name | _children]}, _) when type in [:test, :feature, :property] do
160159
%DocumentSymbol{
161-
name: "#{type} #{Macro.to_string(unliteral(name))}" |> String.replace("\n", ""),
160+
name: String.replace("#{type} #{Macro.to_string(unliteral(name))}", "\n", ""),
162161
children: [],
163162
kind: GenLSP.Enumerations.SymbolKind.constructor(),
164163
range: %Range{
@@ -180,7 +179,7 @@ defmodule NextLS.DocumentSymbol do
180179

181180
defp walker({type, meta, [name | _children]}, _) when type in [:def, :defp, :defmacro, :defmacro] do
182181
%DocumentSymbol{
183-
name: "#{type} #{name |> unliteral() |> Macro.to_string()}" |> String.replace("\n", ""),
182+
name: String.replace("#{type} #{name |> unliteral() |> Macro.to_string()}", "\n", ""),
184183
children: [],
185184
kind: elixir_kind_to_lsp_kind(type),
186185
range: %Range{

lib/next_ls/logger.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
defmodule NextLS.Logger do
2+
@moduledoc false
23
use GenServer
34

45
def start_link(arg) do
@@ -16,7 +17,7 @@ defmodule NextLS.Logger do
1617
end
1718

1819
def handle_cast({:log, type, msg}, state) do
19-
apply(GenLSP, type, [state.lsp, "[NextLS] #{msg}" |> String.trim()])
20+
apply(GenLSP, type, [state.lsp, String.trim("[NextLS] #{msg}")])
2021
{:noreply, state}
2122
end
2223
end

lib/next_ls/runtime.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ defmodule NextLS.Runtime do
22
@moduledoc false
33
use GenServer
44

5-
@exe :code.priv_dir(:next_ls)
5+
@exe :next_ls
6+
|> :code.priv_dir()
67
|> Path.join("cmd")
78
|> Path.absname()
89

@@ -58,7 +59,7 @@ defmodule NextLS.Runtime do
5859
cd: working_dir,
5960
env: [
6061
{~c"LSP", ~c"nextls"},
61-
{~c"NEXTLS_PARENT_PID", :erlang.term_to_binary(parent) |> Base.encode64() |> String.to_charlist()},
62+
{~c"NEXTLS_PARENT_PID", parent |> :erlang.term_to_binary() |> Base.encode64() |> String.to_charlist()},
6263
{~c"MIX_ENV", ~c"dev"},
6364
{~c"MIX_BUILD_ROOT", ~c".elixir-tools/_build"}
6465
],

lib/next_ls/symbol_table.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ defmodule NextLS.SymbolTable do
33
use GenServer
44

55
defmodule Symbol do
6+
@moduledoc false
67
defstruct [:file, :module, :type, :name, :line, :col]
78

89
@type t :: %__MODULE__{
@@ -41,13 +42,13 @@ defmodule NextLS.SymbolTable do
4142

4243
{:ok, name} =
4344
:dets.open_file(symbol_table_name,
44-
file: Path.join(path, "symbol_table.dets") |> String.to_charlist(),
45+
file: path |> Path.join("symbol_table.dets") |> String.to_charlist(),
4546
type: :duplicate_bag
4647
)
4748

4849
{:ok, ref_name} =
4950
:dets.open_file(reference_table_name,
50-
file: Path.join(path, "reference_table.dets") |> String.to_charlist(),
51+
file: path |> Path.join("reference_table.dets") |> String.to_charlist(),
5152
type: :duplicate_bag
5253
)
5354

@@ -98,7 +99,8 @@ defmodule NextLS.SymbolTable do
9899
col = meta[:column] || 0
99100

100101
range =
101-
{{meta[:line], col}, {meta[:line], col + String.length(to_string(identifier) |> String.replace("Elixir.", ""))}}
102+
{{meta[:line], col},
103+
{meta[:line], col + String.length(identifier |> to_string() |> String.replace("Elixir.", ""))}}
102104

103105
:dets.insert(state.reference_table, {
104106
{file, range},

mix.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ defmodule NextLS.MixProject do
3535
defp deps do
3636
[
3737
{:gen_lsp, "~> 0.4"},
38+
{:styler, "~> 0.8", only: :dev},
3839
{:ex_doc, ">= 0.0.0", only: :dev},
3940
{:dialyxir, ">= 0.0.0", only: [:dev, :test], runtime: false}
4041
]
4142
end
4243

43-
defp package() do
44+
defp package do
4445
[
4546
maintainers: ["Mitchell Hanberg"],
4647
licenses: ["MIT"],

mix.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"nimble_options": {:hex, :nimble_options, "1.0.2", "92098a74df0072ff37d0c12ace58574d26880e522c22801437151a159392270e", [:mix], [], "hexpm", "fd12a8db2021036ce12a309f26f564ec367373265b53e25403f0ee697380f1b8"},
1212
"nimble_parsec": {:hex, :nimble_parsec, "1.3.1", "2c54013ecf170e249e9291ed0a62e5832f70a476c61da16f6aac6dca0189f2af", [:mix], [], "hexpm", "2682e3c0b2eb58d90c6375fc0cc30bc7be06f365bf72608804fb9cffa5e1b167"},
1313
"schematic": {:hex, :schematic, "0.2.0", "ac710efbd98b8f4b3d137f8ebac6f9a17da917bb4d1296b487ac4157fb74c806", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d4bc93bac2e7d04869fd6ced9df82c092c154fc648677512bc7c75d9a2655be3"},
14+
"styler": {:hex, :styler, "0.8.1", "f3c0f65023e4bfbf7e7aa752d128b8475fdabfd30f96ee7314b84480cc56e788", [:mix], [], "hexpm", "1aa48d3aa689a639289af3d8254d40e068e98c083d6e5e3d1a695e71a147b344"},
1415
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
1516
"typed_struct": {:hex, :typed_struct, "0.3.0", "939789e3c1dca39d7170c87f729127469d1315dcf99fee8e152bb774b17e7ff7", [:mix], [], "hexpm", "c50bd5c3a61fe4e198a8504f939be3d3c85903b382bde4865579bc23111d1b6d"},
1617
}

priv/monkey/_next_ls_private_compiler.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
defmodule NextLSPrivate.Tracer do
2+
@moduledoc false
23
def trace(:start, _env) do
34
:ok
45
end
@@ -106,15 +107,15 @@ defmodule NextLSPrivate.Tracer do
106107
:ok
107108
end
108109

109-
defp parent_pid() do
110+
defp parent_pid do
110111
"NEXTLS_PARENT_PID" |> System.get_env() |> Base.decode64!() |> :erlang.binary_to_term()
111112
end
112113
end
113114

114115
defmodule :_next_ls_private_compiler do
115116
@moduledoc false
116117

117-
def compile() do
118+
def compile do
118119
# keep stdout on this node
119120
Process.group_leader(self(), Process.whereis(:user))
120121

test/next_ls/extensions/elixir_extension_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
defmodule NextLS.ElixirExtensionTest do
22
use ExUnit.Case, async: true
33

4-
alias NextLS.ElixirExtension
54
alias NextLS.DiagnosticCache
5+
alias NextLS.ElixirExtension
66

77
setup do
88
cache = start_supervised!(DiagnosticCache)

test/next_ls/runtime_test.exs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
defmodule NextLs.RuntimeTest do
22
use ExUnit.Case, async: true
3+
4+
import ExUnit.CaptureLog
35
import NextLS.Support.Utils
46

5-
@moduletag :tmp_dir
7+
alias NextLS.Runtime
68

79
require Logger
8-
import ExUnit.CaptureLog
910

10-
alias NextLS.Runtime
11+
@moduletag :tmp_dir
1112

1213
setup %{tmp_dir: tmp_dir} do
1314
File.write!(Path.join(tmp_dir, "mix.exs"), mix_exs())

test/next_ls/symbol_table_test.exs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
defmodule NextLS.SymbolTableTest do
22
use ExUnit.Case, async: true
3-
@moduletag :tmp_dir
43

54
alias NextLS.SymbolTable
65

6+
@moduletag :tmp_dir
7+
78
setup %{tmp_dir: dir} do
89
File.mkdir_p!(dir)
910

@@ -19,13 +20,11 @@ defmodule NextLS.SymbolTableTest do
1920
end
2021

2122
defp try_start_supervised(spec, num) do
22-
try do
23-
start_supervised!(spec)
24-
rescue
25-
_ ->
26-
Process.sleep(250)
27-
try_start_supervised(spec, num - 1)
28-
end
23+
start_supervised!(spec)
24+
rescue
25+
_ ->
26+
Process.sleep(250)
27+
try_start_supervised(spec, num - 1)
2928
end
3029

3130
test "creates a dets table", %{dir: dir, pid: pid} do
@@ -66,7 +65,7 @@ defmodule NextLS.SymbolTableTest do
6665
] == SymbolTable.symbols(pid)
6766
end
6867

69-
defp symbols() do
68+
defp symbols do
7069
%{
7170
file: "/Users/alice/next_ls/lib/next_ls.ex",
7271
module: NextLS,

0 commit comments

Comments
 (0)