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 release] ocaml-lsp-server, lsp and jsonrpc (1.8.0) #19286

Merged
merged 3 commits into from
Sep 10, 2021

Conversation

rgrinberg
Copy link
Member

@rgrinberg rgrinberg commented Aug 19, 2021

LSP Server for OCaml

CHANGES:

Features

  • Add a new code action Add missing rec keyword, which is available when
    adding a rec keyword can fix Unbound value ... error, e.g.,

    let fact n = if n = 0 then 1 else n * fact (n - 1)
                                       (* ^^^^ Unbound value fact *)

    Adding rec to the definition of fact will fix the problem. The new code
    action offers adding rec.

  • Use ocamlformat to properly format type snippets. This feature requires the
    ocamlformat-rpc opam package to be installed. (OCamlformat RPC ocaml-lsp#386)

  • Add completion support for polymorphic variants, when it is possible to pin
    down the precise type. Examples (<|> stands for the cursor) when completion
    will work (Fix completion for polymorphic variants ocaml-lsp#473)

    Function application:

    let foo (a: [`Alpha | `Beta]) = ()
    
    foo `A<|>
    

    Type explicitly shown:

    let a : [`Alpha | `Beta] = `B<|>
    

    Note: this is actually a bug fix, since we were ignoring the backtick when
    constructing the prefix for completion.

  • Parse merlin errors (best effort) into a more structured form. This allows
    reporting all locations as "related information" (Improve display of merlin errors ocaml-lsp#475)

  • Add support for Merlin Construct command as completion suggestions, i.e.,
    show complex expressions that could complete the typed hole. (Construct as completion suggestions ocaml-lsp#472)

  • Add a code action Construct an expression that is shown when the cursor is
    at the end of the typed hole, i.e., _|, where | is the cursor. The code
    action simply triggers the client (currently only VS Code is supported) to
    show completion suggestions. (Construct as completion suggestions ocaml-lsp#472)

  • Change the formatting-on-save error notification to a warning notification
    (Construct as completion suggestions ocaml-lsp#472)

  • Code action to qualify ("put module name in identifiers") and unqualify
    ("remove module name from identifiers") module names in identifiers (add support for refactor-open (qualify and unqualify) code action ocaml-lsp#399)

    Starting from:

    open Unix
    
    let times = Unix.times ()
    let f x = x.Unix.tms_stime, x.Unix.tms_utime

    Calling "remove module name from identifiers" with the cursor on the open
    statement will produce:

    open Unix
    
    let times = times ()
    let f x = x.tms_stime, x.tms_utime

    Calling "put module name in identifiers" will restore:

    open Unix
    
    let times = Unix.times ()
    let f x = x.Unix.tms_stime, x.Unix.tms_utime

Fixes

Copy link
Member

@kit-ty-kate kit-ty-kate left a comment

Choose a reason for hiding this comment

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

#=== ERROR while compiling lsp.1.8.0 ==========================================#
# context              2.0.9 | linux/x86_64 | ocaml-base-compiler.4.12.0 | pinned(https://github.com/ocaml/ocaml-lsp/releases/download/1.8.0/jsonrpc-1.8.0.tbz)
# path                 ~/.opam/4.12/.opam-switch/build/lsp.1.8.0
# command              ~/.opam/opam-init/hooks/sandbox.sh build dune build -p lsp -j 71 @install
# exit-code            1
# env-file             ~/.opam/log/lsp-3305-c61e7b.env
# output-file          ~/.opam/log/lsp-3305-c61e7b.out
### output ###
# File "dune", line 21, characters 5-90:
# 21 |      %{workspace_root}/submodules/dune/otherlibs/stdune-unstable/dune_filesystem_stubs/*.*)
#           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# Error: Cannot find directory:
# submodules/dune/otherlibs/stdune-unstable/dune_filesystem_stubs

"pp" {>= "1.1.2"}
"csexp" {>= "1.4"}
"result" {>= "1.5"}
"ocamlformat-rpc-lib" {= "0.18.0"}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"ocamlformat-rpc-lib" {= "0.18.0"}
"ocamlformat-rpc-lib" {>= "0.18.0" & < "0.19.0"}

or

Suggested change
"ocamlformat-rpc-lib" {= "0.18.0"}
"ocamlformat-rpc-lib" {>= "0.18.0"}

?

Copy link
Member Author

Choose a reason for hiding this comment

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

@voodoos would know best. Your first suggestions seems reasonable to me. I'll backport whatever we end deciding here.

Copy link
Member Author

Choose a reason for hiding this comment

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

@voodoos ping

CHANGES:

## Features

- Add a new code action `Add missing rec keyword`, which is available when
  adding a `rec` keyword can fix `Unbound value ...` error, e.g.,

  ```ocaml
  let fact n = if n = 0 then 1 else n * fact (n - 1)
                                     (* ^^^^ Unbound value fact *)
  ```

  Adding `rec` to the definition of `fact` will fix the problem. The new code
  action offers adding `rec`.

- Use ocamlformat to properly format type snippets. This feature requires the
  `ocamlformat-rpc` opam package to be installed. (ocaml/ocaml-lsp#386)

- Add completion support for polymorphic variants, when it is possible to pin
  down the precise type. Examples (`<|>` stands for the cursor) when completion
  will work (ocaml/ocaml-lsp#473)

  Function application:

  ```
  let foo (a: [`Alpha | `Beta]) = ()

  foo `A<|>
  ```

  Type explicitly shown:

  ```
  let a : [`Alpha | `Beta] = `B<|>
  ```

  Note: this is actually a bug fix, since we were ignoring the backtick when
  constructing the prefix for completion.

- Parse merlin errors (best effort) into a more structured form. This allows
  reporting all locations as "related information" (ocaml/ocaml-lsp#475)

- Add support for Merlin `Construct` command as completion suggestions, i.e.,
  show complex expressions that could complete the typed hole. (ocaml/ocaml-lsp#472)

- Add a code action `Construct an expression` that is shown when the cursor is
  at the end of the typed hole, i.e., `_|`, where `|` is the cursor. The code
  action simply triggers the client (currently only VS Code is supported) to
  show completion suggestions. (ocaml/ocaml-lsp#472)

- Change the formatting-on-save error notification to a warning notification
  (ocaml/ocaml-lsp#472)

- Code action to qualify ("put module name in identifiers") and unqualify
  ("remove module name from identifiers") module names in identifiers (ocaml/ocaml-lsp#399)

  Starting from:

  ```ocaml
  open Unix

  let times = Unix.times ()
  let f x = x.Unix.tms_stime, x.Unix.tms_utime
  ```

  Calling "remove module name from identifiers" with the cursor on the open
  statement will produce:

  ```ocaml
  open Unix

  let times = times ()
  let f x = x.tms_stime, x.tms_utime
  ```

  Calling "put module name in identifiers" will restore:

  ```ocaml
  open Unix

  let times = Unix.times ()
  let f x = x.Unix.tms_stime, x.Unix.tms_utime
  ```

## Fixes

- Do not show "random" documentation on hover

  - fixed by [merlin#1364](ocaml/merlin#1364)
  - fixes duplicate:
    - [ocaml-lsp#344](ocaml/ocaml-lsp#344)
    - [vscode-ocaml-platform#111](ocamllabs/vscode-ocaml-platform#111)

- Correctly rename a variable used as a named/optional argument (ocaml/ocaml-lsp#478)

- When reporting an error at the beginning of the file, use the first line not
  the second (ocaml/ocaml-lsp#489)
@rgrinberg
Copy link
Member Author

rgrinberg commented Aug 25, 2021

> #=== ERROR while compiling lsp.1.8.0 ==========================================#
> # context              2.0.9 | linux/x86_64 | ocaml-base-compiler.4.12.0 | pinned(https://github.com/ocaml/ocaml-lsp/releases/download/1.8.0/jsonrpc-1.8.0.tbz)
> # path                 ~/.opam/4.12/.opam-switch/build/lsp.1.8.0
> # command              ~/.opam/opam-init/hooks/sandbox.sh build dune build -p lsp -j 71 @install
> # exit-code            1
> # env-file             ~/.opam/log/lsp-3305-c61e7b.env
> # output-file          ~/.opam/log/lsp-3305-c61e7b.out
> ### output ###
> # File "dune", line 21, characters 5-90:
> # 21 |      %{workspace_root}/submodules/dune/otherlibs/stdune-unstable/dune_filesystem_stubs/*.*)
> #           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> # Error: Cannot find directory:
> # submodules/dune/otherlibs/stdune-unstable/dune_filesystem_stubs

Oops. Looks like I used some old version of dune-release that didn't create the archive correctly. Should be working now.

@kit-ty-kate
Copy link
Member

There seems to be an issue here:

#=== ERROR while compiling ocaml-lsp-server.1.8.0 =============================#
# context              2.1.0 | linux/x86_64 | ocaml-base-compiler.4.12.0 | pinned(https://github.com/ocaml/ocaml-lsp/releases/download/1.8.0/jsonrpc-1.8.0.tbz)
# path                 ~/.opam/4.12/.opam-switch/build/ocaml-lsp-server.1.8.0
# command              ~/.opam/opam-init/hooks/sandbox.sh build dune build -j 47 ocaml-lsp-server.install --release
# exit-code            1
# env-file             ~/.opam/log/ocaml-lsp-server-4585-4ccbb1.env
# output-file          ~/.opam/log/ocaml-lsp-server-4585-4ccbb1.out
### output ###
# File "ocaml-lsp-server/vendor/merlin/dune-project", line 1, characters 11-14:
# 1 | (lang dune 2.9)
#                ^^^
# Error: Version 2.9 of the dune language is not supported.
# Supported versions of this extension in version 2.9 of the dune language:
# - 1.0 to 1.12
# - 2.0 to 2.8

- File "ocaml-lsp-server/vendor/merlin/dune-project", line 1, characters 11-14:
- 1 | (lang dune 2.9)
-                ^^^
- Error: Version 2.9 of the dune language is not supported.
- Supported versions of this extension in version 2.9 of the dune language:
- - 1.0 to 1.12
- - 2.0 to 2.8

Should "dune" {>= "2.9"} be used everywhere or just for this particular package?

@rgrinberg
Copy link
Member Author

Everywhere sounds good to me.

… 2.9) + Relax ocamlformat-rpc-lib constraints
@rgrinberg
Copy link
Member Author

I looked at the errors and it looks like we need a lower bound on re. >= 1.5.0 should work.

@Kakadu
Copy link
Contributor

Kakadu commented Sep 10, 2021

@rgrinberg Should we expect that all new code actions of ocaml-lsp will be available in most of the editors automatically? (I personally more interested in VsCode)

@kit-ty-kate kit-ty-kate merged commit a6def62 into ocaml:master Sep 10, 2021
@kit-ty-kate
Copy link
Member

Thanks! @rgrinberg could you return the fixes to the opam files upstream?

@rgrinberg
Copy link
Member Author

Should we expect that all new code actions of ocaml-lsp will be available in most of the editors automatically? (I personally more interested in VsCode)

Yes.

Thanks! @rgrinberg could you return the fixes to the opam files upstream?

Done. Thanks.

@rgrinberg rgrinberg deleted the release-lsp-1.8.0 branch September 10, 2021 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants