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

Completion: use type information #1276

Merged
merged 3 commits into from
Mar 9, 2021
Merged

Completion: use type information #1276

merged 3 commits into from
Mar 9, 2021

Conversation

trefis
Copy link
Contributor

@trefis trefis commented Feb 26, 2021

Type recovery on record degraded over the past few years, which in turns degraded completion results when inside a record expression.
I reintroduced a naïve recovery for record, but it needs to be reviewed (in particular: I am not calling Msupport.erroneous_type_register, should I?).

The other commit extends constructor completion candidates with the constructor from the expected type which matches the given prefix.

Instead of the generic `*type-error*` ident node, we get an empty record
expression `{ }`. Which is useful for various analysis which look at the
typedtree/browsetree to decide in which context they are working.

We could make the analysis less naïve by keeping all the sub expressions
which typechecked correctly (currently, we would drop all of them if one
field is missing, or if one extra field is present).
Copy link
Contributor

@let-def let-def left a comment

Choose a reason for hiding this comment

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

The only purpose of erroneous type register is to silence the unused argument warning. Not using it seems fine for the current purpose.

(Worst case I can think of: ty_expected is '_a, typing the record fails and it is immediately passed to e.g ignore -- I am not 100% sure the conditions for the unused argument warning)

@trefis
Copy link
Contributor Author

trefis commented Mar 9, 2021

The only purpose of erroneous type register is to silence the unused argument warning. Not using it seems fine for the current purpose.

Ah, indeed!
Thanks.

@trefis trefis merged commit 4cd7971 into master Mar 9, 2021
@trefis trefis deleted the disambiguate-completion branch March 9, 2021 13:58
@trefis trefis mentioned this pull request Mar 17, 2021
@voodoos voodoos mentioned this pull request Apr 2, 2021
32 tasks
voodoos added a commit to voodoos/merlin that referenced this pull request Apr 6, 2021
Merge pull request ocaml#1276 from ocaml/disambiguate-completion
voodoos added a commit to voodoos/opam-repository that referenced this pull request Apr 13, 2021
CHANGES:

Tue Apr 12 11:44:22 AM CET 2021

  + merlin binary
    - external configuration reading:
      + use relative paths to communicate with Dune when possible. This solves
        issues related to symlinks on Unix and improve Windows support (ocaml/merlin#1271,
        fixes ocaml/merlin#1288)
      + make the `workdir` configuration value when using the
        `dune ocaml-merlin` configuration provider the same as when using
        `dot-merlin-reader` so that ppxes behaves in the same way as before
        (ocaml/merlin#1284, fixes ocaml/dune#4479, discussion in ocaml/merlin#1292)
    - destruct:
      + improve prefixing of generated constructors in Destruct by filtering
        opened modules (ocaml/merlin#1277)
      + make the destruct command more resilient to ill-typed expressions and
        when called without nodes (ocaml/merlin#1304, fixes ocaml/merlin#1300)
    - reintroduce some record recovery and improve completion (ocaml/merlin#1276)
    - introduce a new AST node for holes (`_`), allow correct typing of these
      holes and add a new `holes` command that returns the locations of all
      holes in the current file along with their types (ocaml/merlin#1242, ocaml/merlin#1289)
    - Mppx: don't restore cookies after invocation. Ppx are invoked only once
      so there is no need to manage cookies. This small change should increase
      performance and should not change any other behavior (ocaml/merlin#1309)
    - Windows: system command variant: do not open a window console when
      launching a ppx (ocaml/merlin#1270, fixes ocaml/merlin#714)
    - fix same file documentation bug (ocaml/merlin#1265 by @ulugbekna, fixes ocaml/merlin#1261)
  + editor modes
    - vim: Add `MerlinNextHole` and `MerlinPreviousHole` commands to navigate
      between holes. Jump to the first hole after destruct (ocaml/merlin#1287, ocaml/merlin#1303)
    - emacs: Add `merlin-next-hole` and `merlin-previous-hole` commands to
      navigate holes. Jump to the first hole after calling destruct. (ocaml/merlin#1291)
    - emacs: modernization of the elisp code and conformance with coding
      guidelines (ocaml/merlin#1247, ocaml/merlin#1310 by Steve Purcell )
    - vim & emacs : new client-side "merlin use package" commands, restoring
      previous behavior (ocaml/merlin#1272, fixes ocaml/merlin#1191)
  + test suite
    - cover constructor disambiguation and record fields (ocaml/merlin#1276)
    - cover the new `holes` command and AST node (ocaml/merlin#1242, ocaml/merlin#1289)
    - cover the document fix (ocaml/merlin#1265, ocaml/merlin#1315)
voodoos added a commit to voodoos/opam-repository that referenced this pull request Apr 13, 2021
CHANGES:

Tue Apr 12 11:44:22 AM CET 2021

  + merlin binary
    - external configuration reading:
      + use relative paths to communicate with Dune when possible. This solves
        issues related to symlinks on Unix and improve Windows support (ocaml/merlin#1271,
        fixes ocaml/merlin#1288)
      + make the `workdir` configuration value when using the
        `dune ocaml-merlin` configuration provider the same as when using
        `dot-merlin-reader` so that ppxes behaves in the same way as before
        (ocaml/merlin#1284, fixes ocaml/dune#4479, discussion in ocaml/merlin#1292)
    - destruct:
      + improve prefixing of generated constructors in Destruct by filtering
        opened modules (ocaml/merlin#1277)
      + make the destruct command more resilient to ill-typed expressions and
        when called without nodes (ocaml/merlin#1304, fixes ocaml/merlin#1300)
    - reintroduce some record recovery and improve completion (ocaml/merlin#1276)
    - introduce a new AST node for holes (`_`), allow correct typing of these
      holes and add a new `holes` command that returns the locations of all
      holes in the current file along with their types (ocaml/merlin#1242, ocaml/merlin#1289)
    - Mppx: don't restore cookies after invocation. Ppx are invoked only once
      so there is no need to manage cookies. This small change should increase
      performance and should not change any other behavior (ocaml/merlin#1309)
    - Windows: system command variant: do not open a window console when
      launching a ppx (ocaml/merlin#1270, fixes ocaml/merlin#714)
    - fix same file documentation bug (ocaml/merlin#1265 by @ulugbekna, fixes ocaml/merlin#1261)
  + editor modes
    - vim: Add `MerlinNextHole` and `MerlinPreviousHole` commands to navigate
      between holes. Jump to the first hole after destruct (ocaml/merlin#1287, ocaml/merlin#1303)
    - emacs: Add `merlin-next-hole` and `merlin-previous-hole` commands to
      navigate holes. Jump to the first hole after calling destruct. (ocaml/merlin#1291)
    - emacs: modernization of the elisp code and conformance with coding
      guidelines (ocaml/merlin#1247, ocaml/merlin#1310 by Steve Purcell )
    - vim & emacs : new client-side "merlin use package" commands, restoring
      previous behavior (ocaml/merlin#1272, fixes ocaml/merlin#1191)
  + test suite
    - cover constructor disambiguation and record fields (ocaml/merlin#1276)
    - cover the new `holes` command and AST node (ocaml/merlin#1242, ocaml/merlin#1289)
    - cover the document fix (ocaml/merlin#1265, ocaml/merlin#1315)
voodoos added a commit to voodoos/opam-repository that referenced this pull request Apr 13, 2021
CHANGES:

Tue Apr 12 11:44:22 AM CET 2021

  + merlin binary
    - external configuration reading:
      + use relative paths to communicate with Dune when possible. This solves
        issues related to symlinks on Unix and improve Windows support (ocaml/merlin#1271,
        fixes ocaml/merlin#1288)
      + make the `workdir` configuration value when using the
        `dune ocaml-merlin` configuration provider the same as when using
        `dot-merlin-reader` so that ppxes behaves in the same way as before
        (ocaml/merlin#1284, fixes ocaml/dune#4479, discussion in ocaml/merlin#1292)
    - destruct:
      + improve prefixing of generated constructors in Destruct by filtering
        opened modules (ocaml/merlin#1277)
      + make the destruct command more resilient to ill-typed expressions and
        when called without nodes (ocaml/merlin#1304, fixes ocaml/merlin#1300)
    - reintroduce some record recovery and improve completion (ocaml/merlin#1276)
    - introduce a new AST node for holes (`_`), allow correct typing of these
      holes and add a new `holes` command that returns the locations of all
      holes in the current file along with their types (ocaml/merlin#1242, ocaml/merlin#1289)
    - Mppx: don't restore cookies after invocation. Ppx are invoked only once
      so there is no need to manage cookies. This small change should increase
      performance and should not change any other behavior (ocaml/merlin#1309)
    - Windows: system command variant: do not open a window console when
      launching a ppx (ocaml/merlin#1270, fixes ocaml/merlin#714)
    - fix same file documentation bug (ocaml/merlin#1265 by @ulugbekna, fixes ocaml/merlin#1261)
  + editor modes
    - vim: Add `MerlinNextHole` and `MerlinPreviousHole` commands to navigate
      between holes. Jump to the first hole after destruct (ocaml/merlin#1287, ocaml/merlin#1303)
    - emacs: Add `merlin-next-hole` and `merlin-previous-hole` commands to
      navigate holes. Jump to the first hole after calling destruct. (ocaml/merlin#1291)
    - emacs: modernization of the elisp code and conformance with coding
      guidelines (ocaml/merlin#1247, ocaml/merlin#1310 by Steve Purcell )
    - vim & emacs : new client-side "merlin use package" commands, restoring
      previous behavior (ocaml/merlin#1272, fixes ocaml/merlin#1191)
  + test suite
    - cover constructor disambiguation and record fields (ocaml/merlin#1276)
    - cover the new `holes` command and AST node (ocaml/merlin#1242, ocaml/merlin#1289)
    - cover the document fix (ocaml/merlin#1265, ocaml/merlin#1315)
voodoos added a commit to voodoos/opam-repository that referenced this pull request Apr 13, 2021
    CHANGES:

    Tue Apr 12 11:44:22 AM CET 2021

      + merlin binary
        - external configuration reading:
          + use relative paths to communicate with Dune when possible. This solves
            issues related to symlinks on Unix and improve Windows support (ocaml/merlin#1271,
            fixes ocaml/merlin#1288)
          + make the `workdir` configuration value when using the
            `dune ocaml-merlin` configuration provider the same as when using
            `dot-merlin-reader` so that ppxes behaves in the same way as before
            (ocaml/merlin#1284, fixes ocaml/dune#4479, discussion in ocaml/merlin#1292)
        - destruct:
          + improve prefixing of generated constructors in Destruct by filtering
            opened modules (ocaml/merlin#1277)
          + make the destruct command more resilient to ill-typed expressions and
            when called without nodes (ocaml/merlin#1304, fixes ocaml/merlin#1300)
        - reintroduce some record recovery and improve completion (ocaml/merlin#1276)
        - introduce a new AST node for holes (`_`), allow correct typing of these
          holes and add a new `holes` command that returns the locations of all
          holes in the current file along with their types (ocaml/merlin#1242, ocaml/merlin#1289)
        - Mppx: don't restore cookies after invocation. Ppx are invoked only once
          so there is no need to manage cookies. This small change should increase
          performance and should not change any other behavior (ocaml/merlin#1309)
        - Windows: system command variant: do not open a window console when
          launching a ppx (ocaml/merlin#1270, fixes ocaml/merlin#714)
        - fix same file documentation bug (ocaml/merlin#1265 by @ulugbekna, fixes ocaml/merlin#1261)
      + editor modes
        - vim: Add `MerlinNextHole` and `MerlinPreviousHole` commands to navigate
          between holes. Jump to the first hole after destruct (ocaml/merlin#1287, ocaml/merlin#1303)
        - emacs: Add `merlin-next-hole` and `merlin-previous-hole` commands to
          navigate holes. Jump to the first hole after calling destruct. (ocaml/merlin#1291)
        - emacs: modernization of the elisp code and conformance with coding
          guidelines (ocaml/merlin#1247, ocaml/merlin#1310 by Steve Purcell )
        - vim & emacs : new client-side "merlin use package" commands, restoring
          previous behavior (ocaml/merlin#1272, fixes ocaml/merlin#1191)
      + test suite
        - cover constructor disambiguation and record fields (ocaml/merlin#1276)
        - cover the new `holes` command and AST node (ocaml/merlin#1242, ocaml/merlin#1289)
        - cover the document fix (ocaml/merlin#1265, ocaml/merlin#1315)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants