Skip to content

Commit

Permalink
do not return an edit if longident hasn't changed
Browse files Browse the repository at this point in the history
(works only for single-line idents)
  • Loading branch information
ulugbekna committed Apr 25, 2021
1 parent 42f3130 commit e70715c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 28 deletions.
15 changes: 13 additions & 2 deletions src/frontend/query_commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,22 @@ let dispatch pipeline (type a) : a Query_protocol.t -> a =
in
aux [] p |> String.concat ~sep:"."
in
(* checks if the (un)qualified longident has a different length, i.e., has changed
XXX(Ulugbek): computes longident length using [loc_start] and [loc_end], hence
it doesn't work for multiline longidents because we can't compute their length *)
let same_longident new_lident { Location. loc_start; loc_end; _ } =
let old_longident_len = Lexing.column loc_end - Lexing.column loc_start in
loc_start.Lexing.pos_lnum = loc_end.Lexing.pos_lnum &&
String.length new_lident = old_longident_len
in
List.filter_map paths ~f:(fun {Location. txt = path; loc} ->
if not loc.Location.loc_ghost &&
Location_aux.compare_pos pos loc <= 0 then
try Some (qual_or_unqual_path path, loc)
with Not_found -> None
match qual_or_unqual_path path with
| s when same_longident s loc -> None
| s -> Some (s, loc)
| exception Not_found -> None
else None
)
|> List.sort_uniq
Expand Down
28 changes: 2 additions & 26 deletions tests/test-dirs/refactor-open/unqualify.t
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,7 @@ FIXME shouldn't return anything, as nothing to unqualify
> EOF
{
"class": "return",
"value": [
{
"start": {
"line": 2,
"col": 12
},
"end": {
"line": 2,
"col": 17
},
"content": "times"
}
],
"value": [],
"notifications": []
}

Expand All @@ -111,19 +99,7 @@ FIXME shouldn't return anything, as nothing to unqualify for multiline paths
> EOF
{
"class": "return",
"value": [
{
"start": {
"line": 3,
"col": 12
},
"end": {
"line": 3,
"col": 21
},
"content": "tms_stime"
}
],
"value": [],
"notifications": []
}

Expand Down

0 comments on commit e70715c

Please sign in to comment.