Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

At origin occurrences #1785

Merged
merged 4 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/analysis/context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/analysis/occurrences.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions tests/test-dirs/locate/context-detection/cd-test.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}

Expand Down
54 changes: 54 additions & 0 deletions tests/test-dirs/occurrences/from-origin.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
$ 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 <test.ml |
> jq '.value[].start.line'
2
5
6

When cursor on the definition, occurrences are not highlighted
$ $MERLIN single occurrences -identifier-at 2:5 -filename test.ml <test.ml |
> jq '.value[].start.line'
2
5
6

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 <test.ml |
> jq '.value[].start.line'
1
4

When cursor on the definition, occurrences are not highlighted
$ $MERLIN single occurrences -identifier-at 1:30 -filename test.ml <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 <test.ml |
> jq '.value[].start.line'
1
3

When cursor on the definition, occurrences are not highlighted
$ $MERLIN single occurrences -identifier-at 1:10 -filename test.ml <test.ml |
> jq '.value[].start.line'
1
3
Loading