Skip to content

Commit

Permalink
context: improve detection of cursor position
Browse files Browse the repository at this point in the history
need_parenthesis idents are tricky...
  • Loading branch information
voodoos committed May 2, 2024
1 parent 23e9de3 commit d3c200d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/analysis/context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,16 @@ let cursor_on_longident_end
match lid with
| Longident.Lident _ -> true
| _ ->
let end_offset = loc.loc_end.pos_cnum in
let cstr_name_size = String.length name in
let end_offset =
loc.loc_end.pos_cnum in
let cstr_name_size =
(* FIXME: this is britle, but lids don't have precise enough location
information to handle these cases correctly. *)
let name_lenght = String.length name in
if Pprintast.needs_parens name then
name_lenght + 2
else name_lenght
in
let constr_pos =
{ loc.loc_end
with pos_cnum = end_offset - cstr_name_size }
Expand Down Expand Up @@ -107,6 +115,7 @@ let inspect_expression ~cursor ~lid e : t =
else Module_path
| Texp_ident (p, lid_loc, _) ->
let name = Path.last p in
log ~title:"inspect_context" "name is: [%s]" name;
if name = "*type-error*" then
(* For type_enclosing: it is enough to return Module_path here.
- If the cursor was on the end of the lid typing should fail anyway
Expand Down

0 comments on commit d3c200d

Please sign in to comment.