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

Rename does not work properly with ppx_string #1671

Closed
ddickstein opened this issue Sep 6, 2023 · 2 comments · Fixed by ocaml/opam-repository#24499
Closed

Rename does not work properly with ppx_string #1671

ddickstein opened this issue Sep 6, 2023 · 2 comments · Fixed by ocaml/opam-repository#24499
Labels

Comments

@ddickstein
Copy link
Contributor

This bug was originally reported on ocaml/ocaml-lsp#1176, but it seems to be a problem with the response payload Merlin returns for ppx_string. Given a file with 1-indexed lines 242-246,

let f x =
  [%string
    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
     %{x}"]
;;

Here is the query & response with Merlin when the cursor is placed on the x argument and Merlin is asked to rename it to y:

# 0.11 occurrences - Occurrences paths
[
  {
    "start": { "line": 242, "col": 6 },
    "end": { "line": 242, "col": 7 },
    "under_cursor": true,
    "path": "x"
  }
]
# 0.11 New_merlin - run(result)
{
  "class": "return",
  "value": [
    { "start": { "line": 242, "col": 6 }, "end": { "line": 242, "col": 7 } },
    { "start": { "line": 244, "col": 4 }, "end": { "line": 245, "col": 10 } }
  ],
  ...
}

Applying these edits produces:

let f y =
  [%string
    y]
;;

(The :MerlinRename command in Vim does not actually apply this transformation faithfully, but ocaml-lsp does).

According to this comment, Merlin sometimes gives poor rename responses when there are location issues with the ppx. I see that ppx_string has
https://github.com/janestreet/ppx_string/blob/f2bf7353f9b1f4c92e180685018e88f25d3c3ec4/src/ppx_string.ml#L276-L277
Is this hiding the location information that Merlin needs?

@voodoos
Copy link
Collaborator

voodoos commented Sep 7, 2023

Yes, the AST output has a merlin.hide attribute since the generated locations are useless (for merlin) and should be ignored by occurrences (but apparently they are not).

For Merlin to work as expected, the locations in the generated AST should match with the original locations in the source.

I think two actions can be taken here:

  • Merlin should not rely on hidden nodes to return occurrences to prevent incorrect renaming.
  • ppx_string could improve the outputed locations to actually enable Merlin functionality.

@voodoos
Copy link
Collaborator

voodoos commented Sep 7, 2023

The merlin.locattribute might be useful in doing this, but the documentation does not mention that use case.

Doc: https://github.com/ocaml/merlin/blob/master/doc/dev/PROTOCOL.md#locations-in-ppx-rewriters

voodoos added a commit to voodoos/merlin that referenced this issue Sep 8, 2023
voodoos added a commit to voodoos/merlin that referenced this issue Sep 20, 2023
voodoos added a commit to voodoos/merlin that referenced this issue Sep 20, 2023
voodoos added a commit to voodoos/merlin that referenced this issue Sep 21, 2023
voodoos added a commit to voodoos/merlin that referenced this issue Sep 21, 2023
voodoos added a commit to voodoos/merlin that referenced this issue Sep 21, 2023
voodoos added a commit to voodoos/opam-repository that referenced this issue Sep 21, 2023
CHANGES:

Thu Sep 24 18:01:42 CEST 2023

  + merlin binary
    - Improve error messages for missing configuration reader (ocaml/merlin#1669)
    - Fix regression causing crash when using ppxes under Windows (ocaml/merlin#1673)
    - Fix confusion between aliased modules and module types (ocaml/merlin#1676,
      fixes ocaml/merlin#1667)
    - Ignore hidden branches when listing occurrences (ocaml/merlin#1677, fixes ocaml/merlin#1671)
  + editor modes
    - emacs: fix/improve keybindings (ocaml/merlin#1668, fixes ocaml/merlin#1386):
      Unbind <kbd>C-c C-r</kbd> (to avoid shadowing `tuareg-eval-region`)
      and bind <kbd>C-c C-v</kbd> instead to `merlin-error-check`;
      rebind <kbd>C-c C-d</kbd> to `merlin-document`
      and bind <kbd>C-c M-d</kbd> and <kbd>C-c |</kbd> instead to `merlin-destruct`;
      bind <kbd>C-u C-c C-t</kbd> to `merlin-type-expr`.
      See also <ocaml/merlin#1386 (comment)>
    - emacs: remove use of obsolete `defadvice` macro (ocaml/merlin#1675)
voodoos added a commit to voodoos/opam-repository that referenced this issue Sep 21, 2023
CHANGES:

Thu Sep 24 18:01:42 CEST 2023

  + merlin binary
    - Improve error messages for missing configuration reader (ocaml/merlin#1669)
    - Fix regression causing crash when using ppxes under Windows (ocaml/merlin#1673)
    - Fix confusion between aliased modules and module types (ocaml/merlin#1676,
      fixes ocaml/merlin#1667)
    - Ignore hidden branches when listing occurrences (ocaml/merlin#1677, fixes ocaml/merlin#1671)
  + editor modes
    - emacs: fix/improve keybindings (ocaml/merlin#1668, fixes ocaml/merlin#1386):
      Unbind <kbd>C-c C-r</kbd> (to avoid shadowing `tuareg-eval-region`)
      and bind <kbd>C-c C-v</kbd> instead to `merlin-error-check`;
      rebind <kbd>C-c C-d</kbd> to `merlin-document`
      and bind <kbd>C-c M-d</kbd> and <kbd>C-c |</kbd> instead to `merlin-destruct`;
      bind <kbd>C-u C-c C-t</kbd> to `merlin-type-expr`.
      See also <ocaml/merlin#1386 (comment)>
    - emacs: remove use of obsolete `defadvice` macro (ocaml/merlin#1675)
voodoos added a commit to voodoos/opam-repository that referenced this issue Sep 21, 2023
CHANGES:

Thu Sep 24 18:01:42 CEST 2023

  + merlin binary
    - Add support for OCaml 5.1
    - Improve error messages for missing configuration reader (ocaml/merlin#1669)
    - Fix regression causing crash when using ppxes under Windows (ocaml/merlin#1673)
    - Fix confusion between aliased modules and module types (ocaml/merlin#1676,
      fixes ocaml/merlin#1667)
    - Ignore hidden branches when listing occurrences (ocaml/merlin#1677, fixes ocaml/merlin#1671)
  + editor modes
    - emacs: fix/improve keybindings (ocaml/merlin#1668, fixes ocaml/merlin#1386):
      Unbind <kbd>C-c C-r</kbd> (to avoid shadowing `tuareg-eval-region`)
      and bind <kbd>C-c C-v</kbd> instead to `merlin-error-check`;
      rebind <kbd>C-c C-d</kbd> to `merlin-document`
      and bind <kbd>C-c M-d</kbd> and <kbd>C-c |</kbd> instead to `merlin-destruct`;
      bind <kbd>C-u C-c C-t</kbd> to `merlin-type-expr`.
      See also <ocaml/merlin#1386 (comment)>
    - emacs: remove use of obsolete `defadvice` macro (ocaml/merlin#1675)
voodoos added a commit to voodoos/opam-repository that referenced this issue Sep 21, 2023
CHANGES:

Thu Sep 24 18:01:42 CEST 2023

  + merlin binary
    - Improve error messages for missing configuration reader (ocaml/merlin#1669)
    - Fix regression causing crash when using ppxes under Windows (ocaml/merlin#1673)
    - Fix confusion between aliased modules and module types (ocaml/merlin#1676,
      fixes ocaml/merlin#1667)
    - Ignore hidden branches when listing occurrences (ocaml/merlin#1677, fixes ocaml/merlin#1671)
  + editor modes
    - emacs: fix/improve keybindings (ocaml/merlin#1668, fixes ocaml/merlin#1386):
      Unbind <kbd>C-c C-r</kbd> (to avoid shadowing `tuareg-eval-region`)
      and bind <kbd>C-c C-v</kbd> instead to `merlin-error-check`;
      rebind <kbd>C-c C-d</kbd> to `merlin-document`
      and bind <kbd>C-c M-d</kbd> and <kbd>C-c |</kbd> instead to `merlin-destruct`;
      bind <kbd>C-u C-c C-t</kbd> to `merlin-type-expr`.
      See also <ocaml/merlin#1386 (comment)>
    - emacs: remove use of obsolete `defadvice` macro (ocaml/merlin#1675)
nberth pushed a commit to nberth/opam-repository that referenced this issue Jun 18, 2024
CHANGES:

Thu Sep 24 18:01:42 CEST 2023

  + merlin binary
    - Improve error messages for missing configuration reader (ocaml/merlin#1669)
    - Fix regression causing crash when using ppxes under Windows (ocaml/merlin#1673)
    - Fix confusion between aliased modules and module types (ocaml/merlin#1676,
      fixes ocaml/merlin#1667)
    - Ignore hidden branches when listing occurrences (ocaml/merlin#1677, fixes ocaml/merlin#1671)
  + editor modes
    - emacs: fix/improve keybindings (ocaml/merlin#1668, fixes ocaml/merlin#1386):
      Unbind <kbd>C-c C-r</kbd> (to avoid shadowing `tuareg-eval-region`)
      and bind <kbd>C-c C-v</kbd> instead to `merlin-error-check`;
      rebind <kbd>C-c C-d</kbd> to `merlin-document`
      and bind <kbd>C-c M-d</kbd> and <kbd>C-c |</kbd> instead to `merlin-destruct`;
      bind <kbd>C-u C-c C-t</kbd> to `merlin-type-expr`.
      See also <ocaml/merlin#1386 (comment)>
    - emacs: remove use of obsolete `defadvice` macro (ocaml/merlin#1675)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants