From d3c200d47590e157363e247ed8b33ec285a465c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Thu, 2 May 2024 10:07:15 +0200 Subject: [PATCH] context: improve detection of cursor position need_parenthesis idents are tricky... --- src/analysis/context.ml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/analysis/context.ml b/src/analysis/context.ml index 30806301c0..7d0e1a433b 100644 --- a/src/analysis/context.ml +++ b/src/analysis/context.ml @@ -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 } @@ -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