Skip to content

Commit 4816ebe

Browse files
committed
wip
1 parent 51e66f4 commit 4816ebe

File tree

6 files changed

+44
-13
lines changed

6 files changed

+44
-13
lines changed

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
elixir 1.12.3
1+
elixir 1.13.3
22
erlang 24.1

examples/simple_app/.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
elixir 1.11.4
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
defmodule SimpleApp.PipeOp do
2+
3+
use Gradient.TypeAnnotation
4+
5+
@spec int_inc(integer()) :: integer()
6+
def int_inc(int) do
7+
int + 1
8+
end
9+
10+
def easy_pipe do
11+
'1'
12+
|> int_inc()
13+
'1'
14+
|> int_inc()
15+
'1'
16+
|> int_inc()
17+
'1'
18+
|> int_inc()
19+
end
20+
21+
def easy_pipe2 do
22+
int_inc(
23+
{%{a: 1, b: 2, c: 3},
24+
%{a: 1, b: 2, c: 3},
25+
%{a: 1, b: 2, c: 3}})
26+
27+
end
28+
29+
end

lib/gradient/elixir_fmt.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ defmodule Gradient.ElixirFmt do
308308
@spec highlight_in_context(tuple(), [String.t()], options()) :: iodata()
309309
def highlight_in_context(expression, context, opts) do
310310
anno = elem(expression, 1)
311+
IO.inspect(expression)
311312

312313
context
313314
|> Enum.with_index(1)

test/gradient/ast_specifier_test.exs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ defmodule Gradient.AstSpecifierTest do
3737

3838
[block, inline | _] = AstSpecifier.run_mappers(ast, tokens) |> Enum.reverse()
3939

40-
assert {:function, 2, :int, 0, [{:clause, 2, [], [], [{:integer, 2, 1}]}]} = inline
40+
assert {:function, 2, :int, 0, [{:clause, 2, [], [], [{:integer, [location: {2, 16}, end_location: {2, 17}], 1}]}]} = inline
4141

4242
assert {:function, 4, :int_block, 0, [{:clause, 4, [], [], [{:integer, 5, 2}]}]} = block
4343
end
@@ -46,7 +46,7 @@ defmodule Gradient.AstSpecifierTest do
4646
{tokens, ast} = load("Elixir.Basic.Float.beam", "basic/float.ex")
4747

4848
[block, inline | _] = AstSpecifier.run_mappers(ast, tokens) |> Enum.reverse()
49-
assert {:function, 2, :float, 0, [{:clause, 2, [], [], [{:float, 2, 0.12}]}]} = inline
49+
assert {:function, 2, :float, 0, [{:clause, 2, [], [], [{:float, [location: {2, 18}, end_location: {2, 22}], 0.12}]}]} = inline
5050

5151
assert {:function, 4, :float_block, 0, [{:clause, 4, [], [], [{:float, 5, 0.12}]}]} = block
5252
end
@@ -56,9 +56,9 @@ defmodule Gradient.AstSpecifierTest do
5656

5757
[block, inline | _] = AstSpecifier.run_mappers(ast, tokens) |> Enum.reverse()
5858

59-
assert {:function, 2, :atom, 0, [{:clause, 2, [], [], [{:atom, 2, :ok}]}]} = inline
59+
assert {:function, 2, :atom, 0, [{:clause, 2, [], [], [{:atom, [location: {2, 17}, end_location: {2, 19}], :ok}]}]} = inline
6060

61-
assert {:function, 4, :atom_block, 0, [{:clause, 4, [], [], [{:atom, 5, :ok}]}]} = block
61+
assert {:function, 4, :atom_block, 0, [{:clause, 4, [], [], [{:atom, [location: {5, 5}, end_location: {5, 7}], :ok}]}]} = block
6262
end
6363

6464
test "char" do
@@ -516,10 +516,10 @@ defmodule Gradient.AstSpecifierTest do
516516
{tokens, _} = example_data()
517517
opts = [end_line: -1]
518518

519-
assert {{:integer, 21, 12}, tokens} =
519+
assert {{:integer, [location: {21, 9}, end_location: {21, 11}], 12}, tokens} =
520520
AstSpecifier.specify_line({:integer, 21, 12}, tokens, opts)
521521

522-
assert {{:integer, 22, 12}, _tokens} =
522+
assert {{:integer, [location: {22, 5}, end_location: {22, 7}], 12}, _tokens} =
523523
AstSpecifier.specify_line({:integer, 20, 12}, tokens, opts)
524524
end
525525

@@ -1043,8 +1043,8 @@ defmodule Gradient.AstSpecifierTest do
10431043
[
10441044
{:map, 7,
10451045
[
1046-
{:map_field_assoc, 7, {:atom, 7, :a}, {:integer, 7, 12}},
1047-
{:map_field_assoc, 7, {:atom, 7, :b}, {:call, 7, {:atom, 7, :empty_map}, []}}
1046+
{:map_field_assoc, 7, {:atom, {:atom, [location: {7, 7}, end_location: {7, 8}], :a}, :a}, {:integer, {:atom, [location: {7, 10}, end_location: {7, 12}], :a}, 12}},
1047+
{:map_field_assoc, 7, {:atom, [location: {7, 14}, end_location: {7, 15}], :b}, {:call, [location: {7, 17}, end_location: {7, 27}], {:atom, 7, :empty_map}, []}}
10481048
]}
10491049
]}
10501050
]} = test_map
@@ -1633,13 +1633,13 @@ defmodule Gradient.AstSpecifierTest do
16331633
{tokensB, astB} = load("Elixir.NestedModules.ModuleB.beam", "nested_modules.ex")
16341634
{tokens, ast} = load("Elixir.NestedModules.beam", "nested_modules.ex")
16351635

1636-
assert {:function, 3, :name, 0, [{:clause, 3, [], [], [{:atom, 4, :module_a}]}]} =
1636+
assert {:function, 3, :name, 0, [{:clause, 3, [], [], [{:atom, [location: {4, 7}, end_location: {4, 15}], :module_a}]}]} =
16371637
List.last(AstSpecifier.run_mappers(astA, tokensA))
16381638

1639-
assert {:function, 9, :name, 0, [{:clause, 9, [], [], [{:atom, 10, :module_b}]}]} =
1639+
assert {:function, 9, :name, 0, [{:clause, 9, [], [], [{:atom, [location: {10, 7}, end_location: {10, 15}], :module_b}]}]} =
16401640
List.last(AstSpecifier.run_mappers(astB, tokensB))
16411641

1642-
assert {:function, 14, :name, 0, [{:clause, 14, [], [], [{:atom, 15, :module}]}]} =
1642+
assert {:function, 14, :name, 0, [{:clause, 14, [], [], [{:atom, [location: {15, 5}, end_location: {15, 11}], :module}]}]} =
16431643
List.last(AstSpecifier.run_mappers(ast, tokens))
16441644
end
16451645

test/gradient/elixir_fmt_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ defmodule Gradient.ElixirFmtTest do
2121
res = ElixirFmt.try_highlight_in_context(expression, opts)
2222

2323
expected =
24-
{:ok, "29 def bool_id(x) do\n30 _x = 13\n\e[4m\e[31m31 12\e[0m\n32 end\n33 "}
24+
{:ok, "29 def bool_id(x) do\n30 _x = 13\n31\e[4m\e[31m 12\e[0m\n32 end\n33 "}
2525

2626
assert res == expected
2727
end

0 commit comments

Comments
 (0)