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 21, 2021
1 parent 42f3130 commit 72e84d6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
20 changes: 18 additions & 2 deletions src/frontend/query_commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,27 @@ let dispatch pipeline (type a) : a Query_protocol.t -> a =
in
aux [] p |> String.concat ~sep:"."
in
(* checks equality of longidents by checking whether the un-qualified path (string)
has same length as path before;
it works only if the identifier's start and end loc are on the same line
because computing length of a multiline identifier by start and end positions
is impossible (?) *)
let same_longident s { Location. loc_start; loc_end; _ } =
let old_longident_len = Lexing.column loc_end - Lexing.column loc_start in
if loc_start.Lexing.pos_lnum = loc_end.Lexing.pos_lnum then begin
(* Logger.notify ~section:"refactor-open" "s len = %d; loc diff = %d; pos_start = %s pos_end = %s" (String.length s) old_longident_len
(Lexing.print_position () loc_start) @@ Lexing.print_position () loc_end; *)
String.length s = old_longident_len
end else
false
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 72e84d6

Please sign in to comment.