Skip to content

Commit

Permalink
Prioritize non-ghost nodes when looking for best node. (ocaml#1664)
Browse files Browse the repository at this point in the history
from voodoos/issue1660 Fixes ocaml#1660
  • Loading branch information
voodoos authored Aug 24, 2023
2 parents be09845 + f51bd73 commit 517895e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ unreleased
- Fix construct not working with inline records (#1658)
- Improve behavior of `type-enclosing` on let/and operators (#1653)
- Fix occurrences of extension constructors (#1662)
- Improve node selection when ghosts are present (#1664, fixes #1660)
+ editor modes
- emacs: call merlin-client-logger with "interrupted" if the
merlin binary itself is interrupted, not just the parsing of the
Expand Down
3 changes: 3 additions & 0 deletions src/kernel/mbrowse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ let compare_locations pos l1 l2 =
with
| 0, 0 ->
(* Cursor inside both locations: favor closer to the end *)
if l1.Location.loc_ghost then 1
else if l2.Location.loc_ghost then -1
else
Lexing.compare_pos l1.Location.loc_end l2.Location.loc_end
(* Cursor inside one location: it has priority *)
| 0, _ -> t1_first
Expand Down
4 changes: 4 additions & 0 deletions tests/test-dirs/with-ppx/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
(cram
(applies_to :whole_subtree)
(locks ../server-tests/merlin_server))

(cram
(applies_to issue1660-deriving-compare)
(enabled_if (= %{env:MERLIN_TESTS=default} all)))
36 changes: 36 additions & 0 deletions tests/test-dirs/with-ppx/issue1660-deriving-compare.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
$ cat >dune-project <<EOF
> (lang dune 2.0)
> EOF

$ cat >main.ml <<EOF
> module M = struct
> type t =
> | Foo
> | Bar
> end
> EOF

$ $MERLIN single type-enclosing -position 2:7 \
> -filename main.ml < main.ml | jq '.value[0].type'
"type t = Foo | Bar"


$ cat >main.ml <<EOF
> module M = struct
> type t =
> | Foo
> | Bar
> [@@deriving compare]
> end
> EOF

$ cat >dune <<EOF
> (library
> (name main)
> (preprocess (pps ppx_compare)))

$ dune build

$ $MERLIN single type-enclosing -position 2:7 \
> -filename main.ml < main.ml | jq '.value[0].type'
"type t =o | Bar"

0 comments on commit 517895e

Please sign in to comment.