Soilihi BEN SOILIHI BOINA pushed to branch minimal-server at Stefan / Typer
Commits: debc7c1f by Soilih at 2022-07-13T23:43:43-04:00 searching better the element's type the cursor is on
- - - - -
1 changed file:
- src/typer_lsp_server.ml
Changes:
===================================== src/typer_lsp_server.ml ===================================== @@ -281,6 +281,16 @@ let update_the_context (ctx: Debruijn.lexp_context) (liste : syntax_tree ) : (De
in foo lstr cursor
+ (*Check if the cursor is in a location*) + let cursor_in_a_loc (lxp_loc: location) (cursor: location) : bool = + if ((cursor.start_line >= lxp_loc.start_line) + && (cursor.end_line <= lxp_loc.end_line) + && (cursor.start_column >= lxp_loc.start_column) + && (cursor.end_column <= lxp_loc.end_column) + ) + then true + else false + (* Take a list of the results of browse_lexp and return the nearest to the cursor *) let browse_list_lexp (tab:(Debruijn.lexp_context * (((Source.Location.t * string option) * int) option) * Lexp.lexp * Lexp.lexp option * Source.Location.t * vname list) list) (cursor:Source.Location.t) = @@ -291,31 +301,37 @@ let update_the_context (ctx: Debruijn.lexp_context) (liste : syntax_tree ) : (De | [hd;tl] -> let (_, _, lhd, _, loc_hd, _) = hd in let (_, _, ltl, _, loc_tl, _) = tl in let open Source.Location in - if ((Int.equal loc_hd.start_line cursor.start_line) - && (Int.equal loc_tl.start_line cursor.start_line)) - then ( - if (dist loc_hd cursor < dist loc_tl cursor ) then hd - else tl - ) - else ( - if ((Int.equal loc_hd.start_line cursor.start_line) - && (not (Int.equal loc_tl.start_line cursor.start_line))) - then ( - hd - ) - else( - if ((not (Int.equal loc_hd.start_line cursor.start_line)) - && (Int.equal loc_tl.start_line cursor.start_line)) - then ( - tl - ) + + if (cursor_in_a_loc loc_hd cursor) + then hd + else ( + if (cursor_in_a_loc loc_tl cursor) + then tl else ( - if (dist loc_hd cursor < dist loc_tl cursor ) then hd - else tl + if ((Int.equal loc_hd.start_line cursor.start_line) + && (Int.equal loc_tl.start_line cursor.start_line)) + then ( + if (dist loc_hd cursor < dist loc_tl cursor ) then hd + else tl + ) + else ( + if ((Int.equal loc_hd.start_line cursor.start_line) + && (not (Int.equal loc_tl.start_line cursor.start_line))) + then ( + hd + ) + else ( + if ((not (Int.equal loc_hd.start_line cursor.start_line)) + && (Int.equal loc_tl.start_line cursor.start_line)) + then tl + else ( + if (dist loc_hd cursor < dist loc_tl cursor ) then hd + else tl + ) + ) + ) ) - ) - ) - + ) |hd::ml::tl -> let (_, _, _, _, loc_hd, _) = hd in let (_, _, _, _, loc_ml, _) = ml in if (dist loc_hd cursor < dist loc_ml cursor ) then (foo (hd::tl) cursor) @@ -377,8 +393,8 @@ let update_the_context (ctx: Debruijn.lexp_context) (liste : syntax_tree ) : (De defs in let tab' = List.map - (fun (vn, _, ltp) -> - (ctx', None, ltp, None, Lexp.lexp_location ltp, (vn::lst_in)) + (fun ((l, _), _, ltp) -> + (ctx', None, ltp, None, l, lst_in) ) defs in @@ -789,7 +805,6 @@ let browse_list_defs (tab : Source.Location.t list) (cursor:Source.Location.t) = else foo (ml::tl) cursor in foo tab cursor
- let vn_on_the_cursor (vn:vname) (cursor:location) : bool = let (l,_) = vn in if ((cursor.start_column >= l.start_column)
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/debc7c1fc74f9b220c2b4446fe38140593...
Afficher les réponses par date