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

[New Command] Expand PPX nodes #1745

Merged
merged 19 commits into from
Aug 2, 2024
Merged

[New Command] Expand PPX nodes #1745

merged 19 commits into from
Aug 2, 2024

Conversation

PizieDust
Copy link
Contributor

@PizieDust PizieDust commented Apr 2, 2024

closes #1744
This implementation has support for:

  • Ppx derivers written using ppxlib
  • Ppx derivers written using ppx_deriving
  • Ppx rewriters

src/frontend/query_commands.ml Outdated Show resolved Hide resolved
src/frontend/query_protocol.ml Outdated Show resolved Hide resolved
src/kernel/mbrowse.ml Outdated Show resolved Hide resolved
src/kernel/mbrowse.ml Outdated Show resolved Hide resolved
src/kernel/mbrowse.ml Outdated Show resolved Hide resolved
src/kernel/mbrowse.ml Outdated Show resolved Hide resolved
Copy link
Member

@pitag-ha pitag-ha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very nice and is a very useful feature. Thanks a lot, @PizieDust! two general comments:

As a suggestion for an addition to the tests: It would be interesting to test what happens when you use the feature on a deriver that's not registered via dune. Or when you use it on a deriver that triggers some other error, e.g. you call it with a flag, when it doesn't support flags, or it expects some value to be in scope that's not in scope. In those cases, do the errors appear as "derived code" or not?

And as a nit-pick: merlin-lib doesn't know about hover, so the title of the PR is a little misleading. The part of your work about hover is the related work you've done on ocaml-lsp.

src/frontend/query_commands.ml Outdated Show resolved Hide resolved
src/frontend/query_commands.ml Outdated Show resolved Hide resolved
src/kernel/mbrowse.ml Outdated Show resolved Hide resolved
@PizieDust PizieDust changed the title Expand PPX on hover [New Command] Expand PPX nodes Apr 16, 2024
@PizieDust PizieDust marked this pull request as draft May 10, 2024 22:23
@PizieDust PizieDust marked this pull request as ready for review May 27, 2024 05:50
@PizieDust PizieDust requested review from xvw and pitag-ha May 27, 2024 05:51
Copy link
Collaborator

@voodoos voodoos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dit a round of review. I did not tackle the heart of the PR yet

src/analysis/completion.ml Outdated Show resolved Hide resolved
src/commands/query_json.ml Outdated Show resolved Hide resolved
src/frontend/query_protocol.ml Outdated Show resolved Hide resolved
src/ocaml/merlin_specific/browse_raw.ml Outdated Show resolved Hide resolved
tests/test-dirs/expand_node/ppx-tests.t/rewriter/dune Outdated Show resolved Hide resolved
tests/test-dirs/expand_node/ppx-tests.t/run.t Show resolved Hide resolved
src/frontend/query_commands.ml Outdated Show resolved Hide resolved
src/frontend/query_commands.ml Outdated Show resolved Hide resolved
src/frontend/query_commands.ml Outdated Show resolved Hide resolved
src/frontend/query_commands.ml Outdated Show resolved Hide resolved
Add parsetree processing functions

Mbrowse for parsetrees

Browse_raw for parsetrees

expand node logic

add tests

refactor logic

better json response

use lexing locations

refactor type exceptions

discard tests of external dependencies

custom ppx deriver that just renames

tests for expand-node feature

ensure location invariants by setting loc_ghost to true

cover all ghost locations

updated changelog

add eof to tests

properly handle type_exceptions in browse_raw

add helper functions

remove private function from public scope

change logic to use typedtree

add helper functions for str items and sig items

more tests

remote unused variant

better naming

better linting

lint

unrelated test change due to type_exception fixup in the Typedtree

Remove Mbrowse and Browse raw modules for the Pasetree

better alignment

better tests

output with attribute loc range

refactoring of ppx-expand logic

refactor pretty print nodes

return list of ppx nodes and not just head

add ppx rewriter

refactor logic to use Ast_iterator

remove unused code

update test

remove unused code

remove redundant code

remove whitespace
src/analysis/ppx_expand.ml Outdated Show resolved Hide resolved
src/analysis/ppx_expand.ml Outdated Show resolved Hide resolved
src/analysis/ppx_expand.ml Outdated Show resolved Hide resolved
src/analysis/ppx_expand.ml Outdated Show resolved Hide resolved
src/analysis/ppx_expand.ml Outdated Show resolved Hide resolved
@PizieDust PizieDust requested a review from voodoos June 24, 2024 00:24
$ dune build

on attribute name deriving of type t
TODO: a cursor here should only output the derived t and now the whole module
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this todo, is there something we can do ? Was this behavior already the one of the current LSP implementation ?

Copy link
Contributor Author

@PizieDust PizieDust Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current LSP implementation will not give an output as it only works on type_declarations when you hover over the deriving attribute applied to the entire module. But it will display an output when you hover over the type contained in the module

Copy link
Collaborator

@voodoos voodoos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @PizieDust ! This looks like a great addition :-)

@voodoos voodoos merged commit 9fa77db into ocaml:main Aug 2, 2024
1 check passed
voodoos added a commit to voodoos/merlin that referenced this pull request Sep 25, 2024
voodoos added a commit to voodoos/merlin that referenced this pull request Sep 25, 2024
voodoos added a commit to voodoos/merlin that referenced this pull request Sep 25, 2024
voodoos added a commit that referenced this pull request Sep 26, 2024
voodoos added a commit to voodoos/opam-repository that referenced this pull request Sep 26, 2024
CHANGES:

Thu Sep 26 18:48:42 CEST 2024

  + merlin binary
    - A new `WRAPPING_PREFIX` configuration directive that can be used to tell Merlin
      what to append to the current unit name in the presence of wrapping (ocaml/merlin#1788)
    - Add `-unboxed-types` and `-no-unboxed-types` as ocaml ignored flags (ocaml/merlin#1795, fixes ocaml/merlin#1794)
    - destruct: Refinement in the presence of optional arguments (ocaml/merlin#1800 ocaml/merlin#1807, fixes ocaml/merlin#1770)
    - Implement new expand-node command for expanding PPX annotations (ocaml/merlin#1745)
    - Implement new inlay-hints command for adding hints on a sourcetree (ocaml/merlin#1812)
    - Implement new search-by-type command for searching values by types (ocaml/merlin#1828)
    - Canonicalize paths in occurrences. This helps deduplicate the results and
      show more user-friendly paths. (ocaml/merlin#1840)
    - Fix dot-merlin-reader ignoring `SOURCE_ROOT` and `STDLIB` directives
      (ocaml/merlin#1839, ocaml/merlin#1803)
  + editor modes
    - vim: fix python-3.12 syntax warnings in merlin.py (ocaml/merlin#1798)
    - vim: Dead code / doc removal for previously deleted MerlinPhrase command (ocaml/merlin#1804)
    - emacs: Improve the way that result of polarity search is displayed (ocaml/merlin#1814)
    - emacs: Add `merlin-search-by-type`, `merlin-search-by-polarity` and change the
	  behaviour of `merlin-search` to switch between `by-type` or `by-polarity`
	  depending on the query (ocaml/merlin#1828)
voodoos added a commit that referenced this pull request Sep 26, 2024
voodoos added a commit to voodoos/opam-repository that referenced this pull request Sep 26, 2024
CHANGES:

Thu Sep 26 18:48:42 CEST 2024

  + merlin binary
    - A new `WRAPPING_PREFIX` configuration directive that can be used to tell Merlin
      what to append to the current unit name in the presence of wrapping (ocaml/merlin#1788)
    - Add `-unboxed-types` and `-no-unboxed-types` as ocaml ignored flags (ocaml/merlin#1795, fixes ocaml/merlin#1794)
    - destruct: Refinement in the presence of optional arguments (ocaml/merlin#1800 ocaml/merlin#1807, fixes ocaml/merlin#1770)
    - Implement new expand-node command for expanding PPX annotations (ocaml/merlin#1745)
    - Implement new inlay-hints command for adding hints on a sourcetree (ocaml/merlin#1812)
    - Add `signature-help` command (ocaml/merlin#1720)
    - Implement new search-by-type command for searching values by types (ocaml/merlin#1828)
    - Fix dot-merlin-reader ignoring `SOURCE_ROOT` and `STDLIB` directives
      (ocaml/merlin#1839, ocaml/merlin#1803)
  + editor modes
    - vim: fix python-3.12 syntax warnings in merlin.py (ocaml/merlin#1798)
    - vim: Dead code / doc removal for previously deleted MerlinPhrase command (ocaml/merlin#1804)
    - emacs: Improve the way that result of polarity search is displayed (ocaml/merlin#1814)
    - emacs: Add `merlin-search-by-type`, `merlin-search-by-polarity` and change the
	  behaviour of `merlin-search` to switch between `by-type` or `by-polarity`
	  depending on the query (ocaml/merlin#1828)
voodoos added a commit to voodoos/opam-repository that referenced this pull request Sep 26, 2024
CHANGES:

Thu Sep 26 18:48:42 CEST 2024

  + merlin binary
    - A new `WRAPPING_PREFIX` configuration directive that can be used to tell Merlin
      what to append to the current unit name in the presence of wrapping (ocaml/merlin#1788)
    - Add `-unboxed-types` and `-no-unboxed-types` as ocaml ignored flags (ocaml/merlin#1795, fixes ocaml/merlin#1794)
    - destruct: Refinement in the presence of optional arguments (ocaml/merlin#1800 ocaml/merlin#1807, fixes ocaml/merlin#1770)
    - Implement new expand-node command for expanding PPX annotations (ocaml/merlin#1745)
    - Implement new inlay-hints command for adding hints on a sourcetree (ocaml/merlin#1812)
    - Add `signature-help` command (ocaml/merlin#1720)
    - Implement new search-by-type command for searching values by types (ocaml/merlin#1828)
    - Fix dot-merlin-reader ignoring `SOURCE_ROOT` and `STDLIB` directives
      (ocaml/merlin#1839, ocaml/merlin#1803)
  + editor modes
    - vim: fix python-3.12 syntax warnings in merlin.py (ocaml/merlin#1798)
    - vim: Dead code / doc removal for previously deleted MerlinPhrase command (ocaml/merlin#1804)
    - emacs: Improve the way that result of polarity search is displayed (ocaml/merlin#1814)
    - emacs: Add `merlin-search-by-type`, `merlin-search-by-polarity` and change the
	  behaviour of `merlin-search` to switch between `by-type` or `by-polarity`
	  depending on the query (ocaml/merlin#1828)
voodoos added a commit to voodoos/opam-repository that referenced this pull request Sep 27, 2024
CHANGES:

Fri Sep 27 12:02:42 CEST 2024

  + merlin binary
    - A new `WRAPPING_PREFIX` configuration directive that can be used to tell Merlin
      what to append to the current unit name in the presence of wrapping (ocaml/merlin#1788)
    - Add `-unboxed-types` and `-no-unboxed-types` as ocaml ignored flags (ocaml/merlin#1795, fixes ocaml/merlin#1794)
    - destruct: Refinement in the presence of optional arguments (ocaml/merlin#1800 ocaml/merlin#1807, fixes ocaml/merlin#1770)
    - Implement new expand-node command for expanding PPX annotations (ocaml/merlin#1745)
    - Implement new inlay-hints command for adding hints on a sourcetree (ocaml/merlin#1812)
    - Implement new search-by-type command for searching values by types (ocaml/merlin#1828)
    - Canonicalize paths in occurrences. This helps deduplicate the results and
      show more user-friendly paths. (ocaml/merlin#1840)
    - Fix dot-merlin-reader ignoring `SOURCE_ROOT` and `STDLIB` directives
      (ocaml/merlin#1839, ocaml/merlin#1803)
  + editor modes
    - vim: fix python-3.12 syntax warnings in merlin.py (ocaml/merlin#1798)
    - vim: Dead code / doc removal for previously deleted MerlinPhrase command (ocaml/merlin#1804)
    - emacs: Improve the way that result of polarity search is displayed (ocaml/merlin#1814)
    - emacs: Add `merlin-search-by-type`, `merlin-search-by-polarity` and change the
	  behaviour of `merlin-search` to switch between `by-type` or `by-polarity`
	  depending on the query (ocaml/merlin#1828)
voodoos added a commit to voodoos/opam-repository that referenced this pull request Sep 27, 2024
CHANGES:

Fri Sep 27 12:02:42 CEST 2024

  + merlin binary
    - A new `WRAPPING_PREFIX` configuration directive that can be used to tell Merlin
      what to append to the current unit name in the presence of wrapping (ocaml/merlin#1788)
    - Add `-unboxed-types` and `-no-unboxed-types` as ocaml ignored flags (ocaml/merlin#1795, fixes ocaml/merlin#1794)
    - destruct: Refinement in the presence of optional arguments (ocaml/merlin#1800 ocaml/merlin#1807, fixes ocaml/merlin#1770)
    - Implement new expand-node command for expanding PPX annotations (ocaml/merlin#1745)
    - Implement new inlay-hints command for adding hints on a sourcetree (ocaml/merlin#1812)
    - Add `signature-help` command (ocaml/merlin#1720)
    - Implement new search-by-type command for searching values by types (ocaml/merlin#1828)
    - Fix dot-merlin-reader ignoring `SOURCE_ROOT` and `STDLIB` directives
      (ocaml/merlin#1839, ocaml/merlin#1803)
  + editor modes
    - vim: fix python-3.12 syntax warnings in merlin.py (ocaml/merlin#1798)
    - vim: Dead code / doc removal for previously deleted MerlinPhrase command (ocaml/merlin#1804)
    - emacs: Improve the way that result of polarity search is displayed (ocaml/merlin#1814)
    - emacs: Add `merlin-search-by-type`, `merlin-search-by-polarity` and change the
	  behaviour of `merlin-search` to switch between `by-type` or `by-polarity`
	  depending on the query (ocaml/merlin#1828)
voodoos added a commit to voodoos/opam-repository that referenced this pull request Sep 27, 2024
CHANGES:

Fri Sep 27 12:02:42 CEST 2024

  + merlin binary
    - A new `WRAPPING_PREFIX` configuration directive that can be used to tell Merlin
      what to append to the current unit name in the presence of wrapping (ocaml/merlin#1788)
    - Add `-unboxed-types` and `-no-unboxed-types` as ocaml ignored flags (ocaml/merlin#1795, fixes ocaml/merlin#1794)
    - destruct: Refinement in the presence of optional arguments (ocaml/merlin#1800 ocaml/merlin#1807, fixes ocaml/merlin#1770)
    - Implement new expand-node command for expanding PPX annotations (ocaml/merlin#1745)
    - Implement new inlay-hints command for adding hints on a sourcetree (ocaml/merlin#1812)
    - Add `signature-help` command (ocaml/merlin#1720)
    - Implement new search-by-type command for searching values by types (ocaml/merlin#1828)
    - Fix dot-merlin-reader ignoring `SOURCE_ROOT` and `STDLIB` directives
      (ocaml/merlin#1839, ocaml/merlin#1803)
  + editor modes
    - vim: fix python-3.12 syntax warnings in merlin.py (ocaml/merlin#1798)
    - vim: Dead code / doc removal for previously deleted MerlinPhrase command (ocaml/merlin#1804)
    - emacs: Improve the way that result of polarity search is displayed (ocaml/merlin#1814)
    - emacs: Add `merlin-search-by-type`, `merlin-search-by-polarity` and change the
	  behaviour of `merlin-search` to switch between `by-type` or `by-polarity`
	  depending on the query (ocaml/merlin#1828)
voodoos added a commit to voodoos/opam-repository that referenced this pull request Sep 27, 2024
CHANGES:

Fri Sep 27 12:02:42 CEST 2024

  + merlin binary
    - A new `WRAPPING_PREFIX` configuration directive that can be used to tell Merlin
      what to append to the current unit name in the presence of wrapping (ocaml/merlin#1788)
    - Add `-unboxed-types` and `-no-unboxed-types` as ocaml ignored flags (ocaml/merlin#1795, fixes ocaml/merlin#1794)
    - destruct: Refinement in the presence of optional arguments (ocaml/merlin#1800 ocaml/merlin#1807, fixes ocaml/merlin#1770)
    - Implement new expand-node command for expanding PPX annotations (ocaml/merlin#1745)
    - Implement new inlay-hints command for adding hints on a sourcetree (ocaml/merlin#1812)
    - Implement new search-by-type command for searching values by types (ocaml/merlin#1828)
    - Canonicalize paths in occurrences. This helps deduplicate the results and
      show more user-friendly paths. (ocaml/merlin#1840)
    - Fix dot-merlin-reader ignoring `SOURCE_ROOT` and `STDLIB` directives
      (ocaml/merlin#1839, ocaml/merlin#1803)
  + editor modes
    - vim: fix python-3.12 syntax warnings in merlin.py (ocaml/merlin#1798)
    - vim: Dead code / doc removal for previously deleted MerlinPhrase command (ocaml/merlin#1804)
    - emacs: Improve the way that result of polarity search is displayed (ocaml/merlin#1814)
    - emacs: Add `merlin-search-by-type`, `merlin-search-by-polarity` and change the
	  behaviour of `merlin-search` to switch between `by-type` or `by-polarity`
	  depending on the query (ocaml/merlin#1828)

[new release] merlin (3 packages) (4.17.1-501)

CHANGES:

Fri Sep 27 12:02:42 CEST 2024

  + merlin binary
    - A new `WRAPPING_PREFIX` configuration directive that can be used to tell Merlin
      what to append to the current unit name in the presence of wrapping (ocaml/merlin#1788)
    - Add `-unboxed-types` and `-no-unboxed-types` as ocaml ignored flags (ocaml/merlin#1795, fixes ocaml/merlin#1794)
    - destruct: Refinement in the presence of optional arguments (ocaml/merlin#1800 ocaml/merlin#1807, fixes ocaml/merlin#1770)
    - Implement new expand-node command for expanding PPX annotations (ocaml/merlin#1745)
    - Implement new inlay-hints command for adding hints on a sourcetree (ocaml/merlin#1812)
    - Add `signature-help` command (ocaml/merlin#1720)
    - Implement new search-by-type command for searching values by types (ocaml/merlin#1828)
    - Fix dot-merlin-reader ignoring `SOURCE_ROOT` and `STDLIB` directives
      (ocaml/merlin#1839, ocaml/merlin#1803)
  + editor modes
    - vim: fix python-3.12 syntax warnings in merlin.py (ocaml/merlin#1798)
    - vim: Dead code / doc removal for previously deleted MerlinPhrase command (ocaml/merlin#1804)
    - emacs: Improve the way that result of polarity search is displayed (ocaml/merlin#1814)
    - emacs: Add `merlin-search-by-type`, `merlin-search-by-polarity` and change the
	  behaviour of `merlin-search` to switch between `by-type` or `by-polarity`
	  depending on the query (ocaml/merlin#1828)

[new release] merlin (3 packages) (4.17.1-414)

CHANGES:

Fri Sep 27 12:02:42 CEST 2024

  + merlin binary
    - A new `WRAPPING_PREFIX` configuration directive that can be used to tell Merlin
      what to append to the current unit name in the presence of wrapping (ocaml/merlin#1788)
    - Add `-unboxed-types` and `-no-unboxed-types` as ocaml ignored flags (ocaml/merlin#1795, fixes ocaml/merlin#1794)
    - destruct: Refinement in the presence of optional arguments (ocaml/merlin#1800 ocaml/merlin#1807, fixes ocaml/merlin#1770)
    - Implement new expand-node command for expanding PPX annotations (ocaml/merlin#1745)
    - Implement new inlay-hints command for adding hints on a sourcetree (ocaml/merlin#1812)
    - Add `signature-help` command (ocaml/merlin#1720)
    - Implement new search-by-type command for searching values by types (ocaml/merlin#1828)
    - Fix dot-merlin-reader ignoring `SOURCE_ROOT` and `STDLIB` directives
      (ocaml/merlin#1839, ocaml/merlin#1803)
  + editor modes
    - vim: fix python-3.12 syntax warnings in merlin.py (ocaml/merlin#1798)
    - vim: Dead code / doc removal for previously deleted MerlinPhrase command (ocaml/merlin#1804)
    - emacs: Improve the way that result of polarity search is displayed (ocaml/merlin#1814)
    - emacs: Add `merlin-search-by-type`, `merlin-search-by-polarity` and change the
	  behaviour of `merlin-search` to switch between `by-type` or `by-polarity`
	  depending on the query (ocaml/merlin#1828)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Planned for backporting
Status: 4.17-501
Development

Successfully merging this pull request may close these issues.

Implement Enhanced Hover Feature for PPXs in Merlin
4 participants