diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 3106730237..d7da2f0b85 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -8,6 +8,6 @@ on: jobs: Changelog-Entry-Check: name: Check Changelog Action - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: tarides/changelog-check-action@v3 diff --git a/CHANGES.md b/CHANGES.md index c803046e61..9d8068409f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,8 @@ unreleased fixes #1913) - Downstreamed a typer fix from 5.3.X that would trigger assertions linked to scopes bit masks when backtracking the typer cache (#1935) + - Add a new selection field to outline results that contains the location of + the symbol itself. (#1942) + ocaml-index - Improve the granularity of index reading by segmenting the marshalization of the involved data-structures. (#1889) diff --git a/src/analysis/outline.ml b/src/analysis/outline.ml index 5087d51395..2d2d170b6a 100644 --- a/src/analysis/outline.ml +++ b/src/analysis/outline.ml @@ -35,16 +35,18 @@ open Typedtree open Browse_raw open Browse_tree -let id_of_patt = function - | { pat_desc = Tpat_var (id, _, _); _ } -> Some id +let name_of_patt = function + | { pat_desc = Tpat_var (_, name, _); _ } -> Some name | _ -> None -let mk ?(children = []) ~location ~deprecated outline_kind outline_type id = +let mk ?(children = []) ~location ~deprecated outline_kind outline_type + (name : string Location.loc) = { Query_protocol.outline_kind; outline_type; location; + selection = name.loc; children; - outline_name = Ident.name id; + outline_name = name.txt; deprecated } @@ -69,38 +71,38 @@ let rec summarize node = in let deprecated = Type_utils.is_deprecated vb.vb_attributes in begin - match id_of_patt vb.vb_pat with + match name_of_patt vb.vb_pat with | None -> None - | Some ident -> + | Some name -> let typ = outline_type ~env:node.t_env vb.vb_pat.pat_type in - Some (mk ~children ~location ~deprecated `Value typ ident) + Some (mk ~children ~location ~deprecated `Value typ name) end | Value_description vd -> let deprecated = Type_utils.is_deprecated vd.val_attributes in let typ = outline_type ~env:node.t_env vd.val_val.val_type in - Some (mk ~location ~deprecated `Value typ vd.val_id) + Some (mk ~location ~deprecated `Value typ vd.val_name) | Module_declaration md -> let children = get_mod_children node in begin - match md.md_id with - | None -> None - | Some id -> + match md.md_name with + | { txt = None; _ } -> None + | { txt = Some txt; loc } -> let deprecated = Type_utils.is_deprecated md.md_attributes in - Some (mk ~children ~location ~deprecated `Module None id) + Some (mk ~children ~location ~deprecated `Module None { txt; loc }) end | Module_binding mb -> let children = get_mod_children node in begin - match mb.mb_id with - | None -> None - | Some id -> + match mb.mb_name with + | { txt = None; _ } -> None + | { txt = Some txt; loc } -> let deprecated = Type_utils.is_deprecated mb.mb_attributes in - Some (mk ~children ~location ~deprecated `Module None id) + Some (mk ~children ~location ~deprecated `Module None { txt; loc }) end | Module_type_declaration mtd -> let children = get_mod_children node in let deprecated = Type_utils.is_deprecated mtd.mtd_attributes in - Some (mk ~deprecated ~children ~location `Modtype None mtd.mtd_id) + Some (mk ~deprecated ~children ~location `Modtype None mtd.mtd_name) | Type_declaration td -> let children = List.concat_map (Lazy.force node.t_children) ~f:(fun child -> @@ -110,15 +112,15 @@ let rec summarize node = match x.t_node with | Constructor_declaration c -> let deprecated = Type_utils.is_deprecated c.cd_attributes in - mk `Constructor None c.cd_id ~deprecated ~location:c.cd_loc + mk `Constructor None c.cd_name ~deprecated ~location:c.cd_loc | Label_declaration ld -> let deprecated = Type_utils.is_deprecated ld.ld_attributes in - mk `Label None ld.ld_id ~deprecated ~location:ld.ld_loc + mk `Label None ld.ld_name ~deprecated ~location:ld.ld_loc | _ -> assert false (* ! *)) | _ -> []) in let deprecated = Type_utils.is_deprecated td.typ_attributes in - Some (mk ~children ~location ~deprecated `Type None td.typ_id) + Some (mk ~children ~location ~deprecated `Type None td.typ_name) | Type_extension te -> let name = Path.name te.tyext_path in let children = @@ -132,25 +134,25 @@ let rec summarize node = outline_kind = `Type; outline_type = None; location; + selection = te.tyext_txt.loc; children; deprecated } | Extension_constructor ec -> let deprecated = Type_utils.is_deprecated ec.ext_attributes in - Some (mk ~location `Exn None ec.ext_id ~deprecated) + Some (mk ~location `Exn None ec.ext_name ~deprecated) | Class_declaration cd -> let children = List.concat_map (Lazy.force node.t_children) ~f:get_class_elements in let deprecated = Type_utils.is_deprecated cd.ci_attributes in - Some (mk ~children ~location `Class None cd.ci_id_class_type ~deprecated) + Some (mk ~children ~location `Class None cd.ci_id_name ~deprecated) | Class_type_declaration ctd -> let children = List.concat_map (Lazy.force node.t_children) ~f:get_class_elements in let deprecated = Type_utils.is_deprecated ctd.ci_attributes in - Some - (mk ~children ~location `ClassType None ctd.ci_id_class_type ~deprecated) + Some (mk ~children ~location `ClassType None ctd.ci_id_name ~deprecated) | _ -> None and get_val_elements node = @@ -175,6 +177,7 @@ and get_class_elements node = outline_kind; outline_type = None; location = str_loc.Location.loc; + selection = str_loc.loc; children; deprecated }) @@ -192,6 +195,7 @@ and get_class_elements node = outline_kind; outline_type = None; location = field.ctf_loc; + selection = field.ctf_loc; (* TODO: could we have more precised location information? *) children = []; deprecated diff --git a/src/commands/query_json.ml b/src/commands/query_json.ml index d108b20e3f..f0c0939bec 100644 --- a/src/commands/query_json.ml +++ b/src/commands/query_json.ml @@ -323,6 +323,7 @@ let rec json_of_outline outline = outline_kind; outline_type; location; + selection; children; deprecated } = @@ -334,7 +335,8 @@ let rec json_of_outline outline = | None -> `Null | Some typ -> `String typ ); ("children", `List (json_of_outline children)); - ("deprecated", `Bool deprecated) + ("deprecated", `Bool deprecated); + ("selection", with_location selection []) ] in List.map ~f:json_of_item outline diff --git a/src/frontend/query_protocol.ml b/src/frontend/query_protocol.ml index 75c00c3c6e..ba845dfb26 100644 --- a/src/frontend/query_protocol.ml +++ b/src/frontend/query_protocol.ml @@ -92,7 +92,8 @@ and item = | `Method ]; outline_type : string option; deprecated : bool; - location : Location_aux.t; + location : Location.t; + selection : Location.t; children : outline } diff --git a/tests/test-dirs/outline-recovery.t b/tests/test-dirs/outline-recovery.t index 9aff32a063..ea23206392 100644 --- a/tests/test-dirs/outline-recovery.t +++ b/tests/test-dirs/outline-recovery.t @@ -36,7 +36,17 @@ "kind": "Module", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 4, + "col": 9 + }, + "end": { + "line": 4, + "col": 10 + } + } }, { "start": { @@ -51,7 +61,17 @@ "kind": "Module", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 3, + "col": 9 + }, + "end": { + "line": 3, + "col": 10 + } + } }, { "start": { @@ -66,10 +86,30 @@ "kind": "Module", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 2, + "col": 9 + }, + "end": { + "line": 2, + "col": 10 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 1, + "col": 7 + }, + "end": { + "line": 1, + "col": 11 + } + } } ], "notifications": [] diff --git a/tests/test-dirs/outline.t/run.t b/tests/test-dirs/outline.t/run.t index 3744b31ee0..490a3c402b 100644 --- a/tests/test-dirs/outline.t/run.t +++ b/tests/test-dirs/outline.t/run.t @@ -42,13 +42,43 @@ "kind": "Method", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 70, + "col": 13 + }, + "end": { + "line": 70, + "col": 16 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 68, + "col": 6 + }, + "end": { + "line": 68, + "col": 7 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 67, + "col": 4 + }, + "end": { + "line": 67, + "col": 13 + } + } }, { "start": { @@ -63,7 +93,17 @@ "kind": "ClassType", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 65, + "col": 4 + }, + "end": { + "line": 65, + "col": 6 + } + } }, { "start": { @@ -91,10 +131,30 @@ "kind": "Method", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 62, + "col": 2 + }, + "end": { + "line": 62, + "col": 35 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 61, + "col": 11 + }, + "end": { + "line": 61, + "col": 13 + } + } }, { "start": { @@ -122,7 +182,17 @@ "kind": "Method", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 58, + "col": 11 + }, + "end": { + "line": 58, + "col": 14 + } + } }, { "start": { @@ -137,10 +207,30 @@ "kind": "Value", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 57, + "col": 8 + }, + "end": { + "line": 57, + "col": 11 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 55, + "col": 4 + }, + "end": { + "line": 55, + "col": 5 + } + } }, { "start": { @@ -194,16 +284,56 @@ "kind": "Value", "type": "int", "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 50, + "col": 14 + }, + "end": { + "line": 50, + "col": 26 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 49, + "col": 15 + }, + "end": { + "line": 49, + "col": 25 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 47, + "col": 8 + }, + "end": { + "line": 47, + "col": 9 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 45, + "col": 6 + }, + "end": { + "line": 45, + "col": 7 + } + } }, { "start": { @@ -218,7 +348,17 @@ "kind": "Class", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 43, + "col": 4 + }, + "end": { + "line": 43, + "col": 5 + } + } }, { "start": { @@ -246,7 +386,17 @@ "kind": "Method", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 40, + "col": 11 + }, + "end": { + "line": 40, + "col": 14 + } + } }, { "start": { @@ -261,10 +411,30 @@ "kind": "Value", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 39, + "col": 8 + }, + "end": { + "line": 39, + "col": 11 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 37, + "col": 6 + }, + "end": { + "line": 37, + "col": 7 + } + } }, { "start": { @@ -279,7 +449,17 @@ "kind": "ClassType", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 35, + "col": 4 + }, + "end": { + "line": 35, + "col": 6 + } + } }, { "start": { @@ -294,7 +474,17 @@ "kind": "ClassType", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 33, + "col": 11 + }, + "end": { + "line": 33, + "col": 13 + } + } }, { "start": { @@ -309,7 +499,17 @@ "kind": "Class", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 31, + "col": 4 + }, + "end": { + "line": 31, + "col": 5 + } + } }, { "start": { @@ -324,7 +524,17 @@ "kind": "Class", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 29, + "col": 4 + }, + "end": { + "line": 29, + "col": 5 + } + } }, { "start": { @@ -339,7 +549,17 @@ "kind": "Class", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 27, + "col": 6 + }, + "end": { + "line": 27, + "col": 7 + } + } }, { "start": { @@ -367,7 +587,17 @@ "kind": "Label", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 25, + "col": 34 + }, + "end": { + "line": 25, + "col": 35 + } + } }, { "start": { @@ -382,7 +612,17 @@ "kind": "Label", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 25, + "col": 26 + }, + "end": { + "line": 25, + "col": 27 + } + } }, { "start": { @@ -397,10 +637,30 @@ "kind": "Label", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 25, + "col": 18 + }, + "end": { + "line": 25, + "col": 19 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 25, + "col": 8 + }, + "end": { + "line": 25, + "col": 13 + } + } }, { "start": { @@ -428,7 +688,17 @@ "kind": "Constructor", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 23, + "col": 38 + }, + "end": { + "line": 23, + "col": 44 + } + } }, { "start": { @@ -443,10 +713,30 @@ "kind": "Constructor", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 23, + "col": 24 + }, + "end": { + "line": 23, + "col": 29 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 23, + "col": 14 + }, + "end": { + "line": 23, + "col": 21 + } + } }, { "start": { @@ -461,7 +751,17 @@ "kind": "Exn", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 21, + "col": 10 + }, + "end": { + "line": 21, + "col": 12 + } + } }, { "start": { @@ -489,10 +789,30 @@ "kind": "Method", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 18, + "col": 11 + }, + "end": { + "line": 18, + "col": 12 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 16, + "col": 6 + }, + "end": { + "line": 16, + "col": 13 + } + } }, { "start": { @@ -520,10 +840,30 @@ "kind": "Method", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 13, + "col": 2 + }, + "end": { + "line": 13, + "col": 23 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 12, + "col": 11 + }, + "end": { + "line": 12, + "col": 23 + } + } }, { "start": { @@ -551,7 +891,17 @@ "kind": "ClassType", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 9, + "col": 13 + }, + "end": { + "line": 9, + "col": 14 + } + } }, { "start": { @@ -579,7 +929,17 @@ "kind": "Value", "type": "t -> int", "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 6, + "col": 8 + }, + "end": { + "line": 6, + "col": 11 + } + } }, { "start": { @@ -594,10 +954,30 @@ "kind": "Type", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 4, + "col": 9 + }, + "end": { + "line": 4, + "col": 10 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 3, + "col": 14 + }, + "end": { + "line": 3, + "col": 16 + } + } }, { "start": { @@ -612,10 +992,30 @@ "kind": "Type", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 2, + "col": 7 + }, + "end": { + "line": 2, + "col": 8 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 1, + "col": 7 + }, + "end": { + "line": 1, + "col": 10 + } + } } ], "notifications": [] @@ -643,7 +1043,17 @@ "kind": "Value", "type": "< foo : int >", "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 56, + "col": 4 + }, + "end": { + "line": 56, + "col": 13 + } + } }, { "start": { @@ -658,7 +1068,17 @@ "kind": "ClassType", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 54, + "col": 4 + }, + "end": { + "line": 54, + "col": 6 + } + } }, { "start": { @@ -686,10 +1106,30 @@ "kind": "Method", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 51, + "col": 2 + }, + "end": { + "line": 51, + "col": 35 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 50, + "col": 11 + }, + "end": { + "line": 50, + "col": 13 + } + } }, { "start": { @@ -704,7 +1144,17 @@ "kind": "ClassType", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 32, + "col": 4 + }, + "end": { + "line": 32, + "col": 6 + } + } }, { "start": { @@ -719,7 +1169,17 @@ "kind": "ClassType", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 30, + "col": 11 + }, + "end": { + "line": 30, + "col": 13 + } + } }, { "start": { @@ -747,7 +1207,17 @@ "kind": "Label", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 22, + "col": 34 + }, + "end": { + "line": 22, + "col": 35 + } + } }, { "start": { @@ -762,7 +1232,17 @@ "kind": "Label", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 22, + "col": 26 + }, + "end": { + "line": 22, + "col": 27 + } + } }, { "start": { @@ -777,10 +1257,30 @@ "kind": "Label", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 22, + "col": 18 + }, + "end": { + "line": 22, + "col": 19 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 22, + "col": 8 + }, + "end": { + "line": 22, + "col": 13 + } + } }, { "start": { @@ -808,7 +1308,17 @@ "kind": "Constructor", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 20, + "col": 38 + }, + "end": { + "line": 20, + "col": 44 + } + } }, { "start": { @@ -823,10 +1333,30 @@ "kind": "Constructor", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 20, + "col": 24 + }, + "end": { + "line": 20, + "col": 29 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 20, + "col": 14 + }, + "end": { + "line": 20, + "col": 21 + } + } }, { "start": { @@ -841,7 +1371,17 @@ "kind": "Exn", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 18, + "col": 10 + }, + "end": { + "line": 18, + "col": 12 + } + } }, { "start": { @@ -869,10 +1409,30 @@ "kind": "Method", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 11, + "col": 2 + }, + "end": { + "line": 11, + "col": 23 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 10, + "col": 11 + }, + "end": { + "line": 10, + "col": 23 + } + } }, { "start": { @@ -913,7 +1473,17 @@ "kind": "Value", "type": "t -> int", "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 6, + "col": 8 + }, + "end": { + "line": 6, + "col": 11 + } + } }, { "start": { @@ -928,10 +1498,30 @@ "kind": "Type", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 5, + "col": 9 + }, + "end": { + "line": 5, + "col": 10 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 4, + "col": 14 + }, + "end": { + "line": 4, + "col": 16 + } + } }, { "start": { @@ -946,10 +1536,30 @@ "kind": "Type", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 2, + "col": 7 + }, + "end": { + "line": 2, + "col": 8 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 1, + "col": 7 + }, + "end": { + "line": 1, + "col": 10 + } + } } ], "notifications": [] @@ -972,7 +1582,17 @@ "kind": "Value", "type": "A.a", "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 5, + "col": 4 + }, + "end": { + "line": 5, + "col": 5 + } + } }, { "start": { @@ -1000,10 +1620,30 @@ "kind": "Type", "type": null, "children": [], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 2, + "col": 7 + }, + "end": { + "line": 2, + "col": 8 + } + } } ], - "deprecated": false + "deprecated": false, + "selection": { + "start": { + "line": 1, + "col": 7 + }, + "end": { + "line": 1, + "col": 8 + } + } } ], "notifications": []