From af14a1ffaa4c2a8929f2be17b66a2ed509c05d6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Mon, 17 Jun 2024 16:04:08 +0200 Subject: [PATCH 1/4] test: add test showing issue with at origin occurrences Labels and constructors are not highlighted correctly when the cursor is on their declaration --- tests/test-dirs/occurrences/from-origin.t | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/test-dirs/occurrences/from-origin.t diff --git a/tests/test-dirs/occurrences/from-origin.t b/tests/test-dirs/occurrences/from-origin.t new file mode 100644 index 000000000..89e3dbe74 --- /dev/null +++ b/tests/test-dirs/occurrences/from-origin.t @@ -0,0 +1,49 @@ + $ cat >test.ml <<'EOF' + > type t = { + > label_a : int + > } + > + > let v = { label_a = 42 } + > let () = print_int v.label_a + > EOF + +When cursor on the usage, all occurrences are highlighted + $ $MERLIN single occurrences -identifier-at 6:25 -filename test.ml jq '.value[].start.line' + 2 + 5 + 6 + +FIXME: When cursor on the definition, occurrences are not highlighted + $ $MERLIN single occurrences -identifier-at 2:5 -filename test.ml jq '.value[].start.line' + +Same test for constructors: + $ cat >test.ml <<'EOF' + > type t = Constr_a of int | No_param + > + > let _ = Constr_a 42 + > let _ = No_param + > EOF + +When cursor on the usage, all occurrences are highlighted + $ $MERLIN single occurrences -identifier-at 4:10 -filename test.ml jq '.value[].start.line' + 1 + 4 + +FIXME: When cursor on the definition, occurrences are not highlighted + $ $MERLIN single occurrences -identifier-at 1:30 -filename test.ml jq '.value[].start.line' + 1 + 4 + +When cursor on the usage, all occurrences are highlighted + $ $MERLIN single occurrences -identifier-at 3:10 -filename test.ml jq '.value[].start.line' + 1 + 3 + +FIXME: When cursor on the definition, occurrences are not highlighted + $ $MERLIN single occurrences -identifier-at 1:10 -filename test.ml jq '.value[].start.line' From 7bd03f099607f6619cc36d360d15b3b742fbea28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Mon, 17 Jun 2024 16:05:30 +0200 Subject: [PATCH 2/4] Better context inference --- src/analysis/context.ml | 4 +++- src/analysis/occurrences.ml | 8 ++++---- .../locate/context-detection/cd-test.t/run.t | 10 ++-------- tests/test-dirs/occurrences/from-origin.t | 11 ++++++++--- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/analysis/context.ml b/src/analysis/context.ml index ec8daab26..cdcdc9f4e 100644 --- a/src/analysis/context.ml +++ b/src/analysis/context.ml @@ -153,7 +153,9 @@ let inspect_browse_tree ~cursor lid browse : t option = | Type_declaration _ | Extension_constructor _ | Module_binding_name _ - | Module_declaration_name _ -> + | Module_declaration_name _ + | Label_declaration _ + | Constructor_declaration _ -> None | Module_expr _ | Open_description _ -> Some Module_path diff --git a/src/analysis/occurrences.ml b/src/analysis/occurrences.ml index 9e3458476..a57200179 100644 --- a/src/analysis/occurrences.ml +++ b/src/analysis/occurrences.ml @@ -53,10 +53,10 @@ let uid_and_loc_of_node env node = Some (uid, name.loc) | Type_declaration { typ_type; typ_name; _ } -> Some (typ_type.type_uid, typ_name.loc) - | Label_declaration { ld_uid; ld_loc ; _ } -> - Some (ld_uid, ld_loc) - | Constructor_declaration { cd_uid; cd_loc ; _ } -> - Some (cd_uid, cd_loc) + | Label_declaration { ld_uid; ld_name ; _ } -> + Some (ld_uid, ld_name.loc) + | Constructor_declaration { cd_uid; cd_name ; _ } -> + Some (cd_uid, cd_name.loc) | Value_description { val_val; val_name; _ } -> Some (val_val.val_uid, val_name.loc) | _ -> None diff --git a/tests/test-dirs/locate/context-detection/cd-test.t/run.t b/tests/test-dirs/locate/context-detection/cd-test.t/run.t index 1dd96f14a..3e0131483 100644 --- a/tests/test-dirs/locate/context-detection/cd-test.t/run.t +++ b/tests/test-dirs/locate/context-detection/cd-test.t/run.t @@ -39,18 +39,12 @@ Trying them all: "notifications": [] } -FIXME this should say "Already at definition point" (we're defining the label): +This should say "Already at definition point" (we're defining the label): $ $MERLIN single locate -look-for ml -position 13:12 -filename ./test.ml < ./test.ml { "class": "return", - "value": { - "file": "$TESTCASE_ROOT/test.ml", - "pos": { - "line": 5, - "col": 4 - } - }, + "value": "Already at definition point", "notifications": [] } diff --git a/tests/test-dirs/occurrences/from-origin.t b/tests/test-dirs/occurrences/from-origin.t index 89e3dbe74..5c195a9c8 100644 --- a/tests/test-dirs/occurrences/from-origin.t +++ b/tests/test-dirs/occurrences/from-origin.t @@ -14,9 +14,12 @@ When cursor on the usage, all occurrences are highlighted 5 6 -FIXME: When cursor on the definition, occurrences are not highlighted +When cursor on the definition, occurrences are not highlighted $ $MERLIN single occurrences -identifier-at 2:5 -filename test.ml jq '.value[].start.line' + 2 + 5 + 6 Same test for constructors: $ cat >test.ml <<'EOF' @@ -32,7 +35,7 @@ When cursor on the usage, all occurrences are highlighted 1 4 -FIXME: When cursor on the definition, occurrences are not highlighted +When cursor on the definition, occurrences are not highlighted $ $MERLIN single occurrences -identifier-at 1:30 -filename test.ml jq '.value[].start.line' 1 @@ -44,6 +47,8 @@ When cursor on the usage, all occurrences are highlighted 1 3 -FIXME: When cursor on the definition, occurrences are not highlighted +When cursor on the definition, occurrences are not highlighted $ $MERLIN single occurrences -identifier-at 1:10 -filename test.ml jq '.value[].start.line' + 1 + 3 From ce84ce936300d06aac7b30591eb408274c48fcca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Mon, 17 Jun 2024 16:06:44 +0200 Subject: [PATCH 3/4] Add changelog entry for #1785 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index e23349773..1cb363cbe 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,8 @@ UNRELEASED interface file (#1781) - Reset uid counters when restoring the typer cache so that uids are stable across re-typing (#1779) + - Improve the behavior on occurrences when the cursor is on a label / + constructor declaration (#1785) + editor modes - emacs: add basic support for project-wide occurrences (#1766) - vim: add basic support for project-wide occurrences (#1767, @Julow) From 21b9f1db735e622ca788dbb2e909cdcabd5c2e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Mon, 17 Jun 2024 16:39:01 +0200 Subject: [PATCH 4/4] ci: update nix flake --- flake.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index d5a6035d2..f879d8fe1 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1687709756, - "narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -39,11 +39,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1715867414, - "narHash": "sha256-cu4UEffKkBByyGR6CFs9XP6iSNsKTkq1r66DA5BkYnE=", + "lastModified": 1718632497, + "narHash": "sha256-YtlyfqOdYMuu7gumZtK0Kg7jr4OKfHUhJkZfNUryw68=", "owner": "nixos", "repo": "nixpkgs", - "rev": "bf446f08bff6814b569265bef8374cfdd3d8f0e0", + "rev": "c58b4a9118498c1055c5908a5bbe666e56abe949", "type": "github" }, "original": {