-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issues with rename variable involving specs #1183
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,8 @@ foo(_Var) -> | |
|
||
bar(Var) -> | ||
Var. | ||
|
||
-spec baz(Var) -> Var | ||
when Var :: atom(). | ||
baz(Var) -> | ||
Var. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,18 +222,29 @@ new_name(_, NewName) -> | |
|
||
-spec function_clause_range(poi_range(), els_dt_document:item()) -> poi_range(). | ||
function_clause_range(VarRange, Document) -> | ||
FunPOIs = els_poi:sort(els_dt_document:pois(Document, [function_clause])), | ||
%% Find beginning of first function clause before VarRange | ||
From = case [R || #{range := R} <- FunPOIs, els_range:compare(R, VarRange)] of | ||
[] -> {0, 0}; % Beginning of document | ||
FunRanges -> maps:get(from, lists:last(FunRanges)) | ||
end, | ||
%% Find beginning of first function clause after VarRange | ||
To = case [R || #{range := R} <- FunPOIs, els_range:compare(VarRange, R)] of | ||
[] -> {999999999, 999999999}; % End of document | ||
[#{from := End}|_] -> End | ||
end, | ||
#{from => From, to => To}. | ||
POIs = els_poi:sort(els_dt_document:pois(Document, [ function_clause | ||
, spec | ||
])), | ||
SpecPOIs = els_poi:sort(els_dt_document:pois(Document, [spec])), | ||
case [R || #{range := R} <- SpecPOIs, els_range:in(VarRange, R)] of | ||
[SpecRange] -> | ||
%% Renaming variable in spec | ||
SpecRange; | ||
[] -> | ||
%% Find beginning of first function clause before VarRange | ||
From = | ||
case [R || #{range := R} <- POIs, els_range:compare(R, VarRange)] of | ||
[] -> {0, 0}; % Beginning of document | ||
FunRanges -> maps:get(from, lists:last(FunRanges)) | ||
end, | ||
%% Find beginning of first function clause after VarRange | ||
To = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just an idea: the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe a better idea is for els_parser to store the full range of a function clause in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, I will see if I can implement an upper bound using the function wrapping_range. |
||
case [R || #{range := R} <- POIs, els_range:compare(VarRange, R)] of | ||
[] -> {999999999, 999999999}; % End of document | ||
[#{from := End}|_] -> End | ||
end, | ||
#{from => From, to => To} | ||
end. | ||
|
||
-spec convert_references_to_pois([els_dt_references:item()], [poi_kind()]) -> | ||
[{uri(), poi()}]. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably consider all possible top-level forms. I haven't checked, but I'd imagine similar issue will happen with things like:
and other top-level items (like
-callback
and-type
).TBH, I'm not sure why the logic tries to look for the beginning point of the next form. Wouldn't it be enough to look for the end point of the current clause?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remember correctly, it's to ensure that:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points, I will add support for other top-level forms as well.
The reason for the currently implemented logic is that function_clause ranges don't contain the beginning and the end of the body of the clause, but rather just the function clause head.