Skip to content

Commit

Permalink
Add support for renaming function from function clause
Browse files Browse the repository at this point in the history
  • Loading branch information
plux committed Apr 5, 2021
1 parent 6376403 commit 03660df
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions apps/els_lsp/src/els_rename_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ workspace_edits(Uri, [#{kind := variable} = POI| _], NewName) ->
#{changes => changes(Uri, POI, NewName)};
workspace_edits(Uri, [#{kind := function} = POI| _], NewName) ->
#{changes => changes(Uri, POI, NewName)};
workspace_edits(Uri, [#{kind := function_clause} = POI| _], NewName) ->
#{id := {F, A, _}} = POI,
#{changes => changes(Uri, #{kind => function, id => {F, A}}, NewName)};
workspace_edits(Uri, [#{kind := 'define'} = POI| _], NewName) ->
#{changes => changes(Uri, POI, NewName)};
workspace_edits(Uri, [#{kind := 'macro'} = POI| _], NewName) ->
Expand Down
29 changes: 29 additions & 0 deletions apps/els_lsp/test/els_rename_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
, rename_variable/1
, rename_function/1
, rename_function_quoted_atom/1
, rename_function_clause/1
, rename_parametrized_macro/1
, rename_macro_from_usage/1
]).
Expand Down Expand Up @@ -224,6 +225,34 @@ rename_function_quoted_atom(Config) ->
]}},
assert_changes(Expected, Result).

-spec rename_function_clause(config()) -> ok.
rename_function_clause(Config) ->
Uri = ?config(rename_function_uri, Config),
ImportUri = ?config(rename_function_import_uri, Config),
Line = 6,
Char = 2,
NewName = <<"new_function">>,
#{result := Result} = els_client:document_rename(Uri, Line, Char, NewName),
Expected = #{changes =>
#{binary_to_atom(Uri, utf8) =>
[ change(NewName, {12, 23}, {12, 26})
, change(NewName, {13, 10}, {13, 13})
, change(NewName, {15, 27}, {15, 30})
, change(NewName, {17, 11}, {17, 14})
, change(NewName, {18, 2}, {18, 5})
, change(NewName, {1, 9}, {1, 12})
, change(NewName, {3, 6}, {3, 9})
, change(NewName, {4, 0}, {4, 3})
, change(NewName, {6, 0}, {6, 3})
, change(NewName, {8, 0}, {8, 3})
],
binary_to_atom(ImportUri, utf8) =>
[ change(NewName, {7, 18}, {7, 21})
, change(NewName, {2, 26}, {2, 29})
, change(NewName, {6, 2}, {6, 5})
]}},
assert_changes(Expected, Result).

-spec rename_parametrized_macro(config()) -> ok.
rename_parametrized_macro(Config) ->
Uri = ?config(rename_h_uri, Config),
Expand Down

0 comments on commit 03660df

Please sign in to comment.