Skip to content

Commit

Permalink
Fix context
Browse files Browse the repository at this point in the history
  • Loading branch information
liam923 committed Jan 16, 2025
1 parent 4b21242 commit 14d1873
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
21 changes: 14 additions & 7 deletions src/analysis/context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ type t =
path (cf. #486, #794). *)
| Unknown_constructor
| Expr
| Label of Types.label_description (* Similar to constructors. *)
| Unknown_label
| Label :
'rep Types.gen_label_description * 'rep Types.record_form
-> t (* Similar to constructors. *)
| Unknown_label : 'rep Types.record_form -> t
| Module_path
| Module_type
| Patt
Expand All @@ -50,8 +52,11 @@ let to_string = function
| Constructor (cd, _) -> Printf.sprintf "constructor %s" cd.cstr_name
| Unknown_constructor -> Printf.sprintf "unknown constructor"
| Expr -> "expression"
| Label lbl -> Printf.sprintf "record field %s" lbl.lbl_name
| Unknown_label -> Printf.sprintf "record field"
| Label (lbl, Legacy) -> Printf.sprintf "record field %s" lbl.lbl_name
| Unknown_label Legacy -> Printf.sprintf "record field"
| Label (lbl, Unboxed_product) ->
Printf.sprintf "unboxed record field %s" lbl.lbl_name
| Unknown_label Unboxed_product -> Printf.sprintf "unboxed record field"
| Module_path -> "module path"
| Module_type -> "module type"
| Patt -> "pattern"
Expand All @@ -67,7 +72,8 @@ let of_locate_context : Query_protocol.Locate_context.t -> t = function
| Type -> Type
| Constant -> Constant
| Constructor -> Unknown_constructor
| Label -> Unknown_label
| Label -> Unknown_label Legacy
| Unboxed_label -> Unknown_label Unboxed_product
| Unknown -> Unknown

(* Distinguish between "Mo[d]ule.something" and "Module.some[t]hing" *)
Expand Down Expand Up @@ -158,9 +164,10 @@ let inspect_browse_tree ?let_pun_behavior ~cursor lid browse : t option =
| Module_type _ -> Some Module_type
| Core_type { ctyp_desc = Ttyp_package _; _ } -> Some Module_type
| Core_type _ -> Some Type
| Record_field (_, lbl, _) when Longident.last lid = lbl.lbl_name ->
| Record_field (_, lbl, record_form, _)
when Longident.last lid = lbl.lbl_name ->
(* if we stopped here, then we're on the label itself, and whether or
not punning is happening is not important *)
Some (Label lbl)
Some (Label (lbl, record_form))
| Expression e -> Some (inspect_expression ~cursor ~lid e)
| _ -> Some Unknown)
6 changes: 4 additions & 2 deletions src/analysis/context.mli
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ type t =
path (cf. #486, #794). *)
| Unknown_constructor
| Expr
| Label of Types.label_description (* Similar to constructors. *)
| Unknown_label
| Label :
'rep Types.gen_label_description * 'rep Types.record_form
-> t (* Similar to constructors. *)
| Unknown_label : 'rep Types.record_form -> t
| Module_path
| Module_type
| Patt
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/query_protocol.ml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ module Locate_context = struct
| Constant
| Constructor
| Label
| Unboxed_label
| Unknown

let to_string = function
Expand All @@ -150,6 +151,7 @@ module Locate_context = struct
| Constant -> "constant"
| Constructor -> "constructor"
| Label -> "label"
| Unboxed_label -> "unboxed_label"
| Unknown -> "unknown"

let of_string = function
Expand All @@ -161,6 +163,7 @@ module Locate_context = struct
| "constant" -> Some Constant
| "constructor" -> Some Constructor
| "label" -> Some Label
| "unboxed_label" -> Some Label
| "unknown" -> Some Unknown
| _ -> None

Expand All @@ -173,6 +176,7 @@ module Locate_context = struct
Constant;
Constructor;
Label;
Unboxed_label;
Unknown
]
end
Expand Down

0 comments on commit 14d1873

Please sign in to comment.