Skip to content

Commit

Permalink
testcases update, erlfmt ast handle, maybe_match_expr
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkoMin committed Sep 16, 2024
1 parent c0e3323 commit 827bc10
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
-feature(maybe_expr, enable).
-endif.

-export([foo/0, maybe_expr/0]).
-export([foo/0, maybe_expr/0, no_else/0]).

foo() ->
maybe
foo ?= bar()
X ?= bar(),
X == foo
else
e = Error -> Error
% ^- Bound variable in pattern: Error
Expand All @@ -27,3 +28,12 @@ maybe_expr() ->
else
Y -> Y
end.

no_else() ->
Y = 1,
maybe
{ok, Y} ?= 2,
X = 4,
Z ?= 8,
X == Z
end.
4 changes: 4 additions & 0 deletions apps/els_lsp/src/els_bound_var_in_pattern_diagnostics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ find_vars_in_tree(Tree, Acc) ->
Pattern = erl_syntax:match_expr_pattern(Tree),
NewAcc = fold_pattern(Pattern, Acc),
find_vars_in_tree(erl_syntax:match_expr_body(Tree), NewAcc);
maybe_match_expr ->
Pattern = erl_syntax:maybe_match_expr_pattern(Tree),
NewAcc = fold_pattern(Pattern, Acc),
find_vars_in_tree(erl_syntax:maybe_match_expr_body(Tree), NewAcc);
clause ->
Patterns = erl_syntax:clause_patterns(Tree),
NewAcc = fold_pattern_list(Patterns, Acc),
Expand Down
2 changes: 2 additions & 0 deletions apps/els_lsp/src/els_erlfmt_ast.erl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ erlfmt_to_st(Node) ->
%% The special `match` node is encoded as a regular binary operator
{op, Pos, '=', Left, Right} ->
erlfmt_to_st_1({match, Pos, Left, Right});
{op, Pos, '?=', Left, Right} ->
erlfmt_to_st_1({maybe_match, Pos, Left, Right});
%% The special `catch` node is encoded as a regular unary operator
{op, Pos, 'catch', Expr} ->
erlfmt_to_st_1({'catch', Pos, Expr});
Expand Down
22 changes: 13 additions & 9 deletions apps/els_lsp/test/els_diagnostics_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,19 @@ bound_var_in_pattern_maybe(_Config) ->
Errors = [],
Warnings = [],
Hints = [
#{
message => <<"Bound variable in pattern: X">>,
range => {{24, 9}, {24, 10}}
},
#{
message => <<"Bound variable in pattern: Y">>,
range => {{27, 9}, {27, 10}}
}
],
#{
message => <<"Bound variable in pattern: X">>,
range => {{26, 8}, {26, 9}}
},
#{
message => <<"Bound variable in pattern: Y">>,
range => {{28, 8}, {28, 9}}
},
#{
message => <<"Bound variable in pattern: Y">>,
range => {{34, 13}, {34, 14}}
}
],
els_test:run_diagnostics_test(Path, Source, Errors, Warnings, Hints).

-spec bound_var_in_pattern_cannot_parse(config()) -> ok.
Expand Down
5 changes: 2 additions & 3 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
debug_info,
warnings_as_errors,
warn_export_vars,
warn_unused_import,
warn_missing_spec_all
warn_unused_import
]}.

{deps, [
Expand All @@ -15,7 +14,7 @@
{docsh, "0.7.2"},
{elvis_core, "~> 3.2.2"},
{rebar3_format, "0.8.2"},
{erlfmt, "1.3.0"},
{erlfmt, "1.5.0"},
{ephemeral, "2.0.4"},
{tdiff, "0.1.2"},
{uuid, "2.0.1", {pkg, uuid_erl}},
Expand Down
6 changes: 3 additions & 3 deletions rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{<<"docsh">>,{pkg,<<"docsh">>,<<"0.7.2">>},0},
{<<"elvis_core">>,{pkg,<<"elvis_core">>,<<"3.2.2">>},0},
{<<"ephemeral">>,{pkg,<<"ephemeral">>,<<"2.0.4">>},0},
{<<"erlfmt">>,{pkg,<<"erlfmt">>,<<"1.3.0">>},0},
{<<"erlfmt">>,{pkg,<<"erlfmt">>,<<"1.5.0">>},0},
{<<"getopt">>,{pkg,<<"getopt">>,<<"1.0.1">>},2},
{<<"gradualizer">>,
{git,"https://github.com/josefs/Gradualizer.git",
Expand All @@ -28,7 +28,7 @@
{<<"docsh">>, <<"F893D5317A0E14269DD7FE79CF95FB6B9BA23513DA0480EC6E77C73221CAE4F2">>},
{<<"elvis_core">>, <<"D5AE5FB7ACDF9D23A2AA3F6E4610490A06F7E8FB33EE65E09C5EA3A0ECF64A73">>},
{<<"ephemeral">>, <<"B3E57886ADD5D90C82FE3880F5954978222A122CB8BAA123667401BBAAEC51D6">>},
{<<"erlfmt">>, <<"672994B92B1A809C04C46F0B781B447BF9AB7A515F5856A96177BC1962F100A9">>},
{<<"erlfmt">>, <<"5DDECA120A6E8E0A0FAB7D0BB9C2339D841B1C9E51DD135EE583256DEF20DE25">>},
{<<"getopt">>, <<"C73A9FA687B217F2FF79F68A3B637711BB1936E712B521D8CE466B29CBF7808A">>},
{<<"jsx">>, <<"20A170ABD4335FC6DB24D5FAD1E5D677C55DADF83D1B20A8A33B5FE159892A39">>},
{<<"katana_code">>, <<"0C42BDCD7E59995876AED9F678CF62E3D12EF42E0FBB2190556E64BFEBDD15C6">>},
Expand All @@ -44,7 +44,7 @@
{<<"docsh">>, <<"4E7DB461BB07540D2BC3D366B8513F0197712D0495BB85744F367D3815076134">>},
{<<"elvis_core">>, <<"3786F027751CC265E7389BF5AC1329DB547510D80F499B45EFE771BDAF889B36">>},
{<<"ephemeral">>, <<"4B293D80F75F9C4575FF4B9C8E889A56802F40B018BF57E74F19644EFEE6C850">>},
{<<"erlfmt">>, <<"2A84AA1EBA2F4FCD7DD31D5C57E9DE2BC2705DDA18DA4553F27DF7114CFAA052">>},
{<<"erlfmt">>, <<"3933A40CFBE790AD94E5B650B36881DE70456319263C1479B556E9AFDBD80C75">>},
{<<"getopt">>, <<"53E1AB83B9CEB65C9672D3E7A35B8092E9BDC9B3EE80721471A161C10C59959C">>},
{<<"jsx">>, <<"37BECA0435F5CA8A2F45F76A46211E76418FBEF80C36F0361C249FC75059DC6D">>},
{<<"katana_code">>, <<"AE3BBACA187511588F69695A9FF22251CB2CC672FDCCC180289779BDD25175EF">>},
Expand Down

0 comments on commit 827bc10

Please sign in to comment.