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

[Folding ranges]: support more AST nodes #692

Merged
merged 38 commits into from
Jun 13, 2022

Conversation

tatchi
Copy link
Collaborator

@tatchi tatchi commented Apr 26, 2022

I'm wondering if we couldn't improve the result of these tests to be more visual. We could try indicates the locations directly on the code block itself.

So given the following code:

    match 
      Some 
        "large expr" 
    with 
    | None -> 
      () 
    | Some _ -> 
      print_endline "foo";
      print_endline "bar"

With the produced locations:

      Array [
        Object {
          "endCharacter": 21,
          "endLine": 8,
          "kind": "region",
          "startCharacter": 0,
          "startLine": 0,
        },
        Object {
          "endCharacter": 4,
          "endLine": 5,
          "kind": "region",
          "startCharacter": 6,
          "startLine": 4,
        },
        Object {
          "endCharacter": 21,
          "endLine": 8,
          "kind": "region",
          "startCharacter": 8,
          "startLine": 6,
        },
      ]

We could produce:

>   match 
      Some 
        "large expr" 
    with 
>   | None -> 
      () 
>   | Some _ -> 
      print_endline "foo";
      print_endline "bar"

The problem is that we only see the startLine but not the endLine.

Another option might be to copy what vscode does: https://github.com/microsoft/vscode/blob/main/extensions/html-language-features/server/src/test/folding.test.ts#L42

It doesn't use snapshot testing but manually assert on what should be the {start,end}Line. A comment with the line number is also added to the code snippet.

@rgrinberg any thoughts ?

@tatchi tatchi force-pushed the folding-ranges-traverse-more-nodes branch 3 times, most recently from 34d942c to c44b883 Compare April 27, 2022 17:33
@tatchi tatchi marked this pull request as ready for review April 28, 2022 06:54
@tatchi tatchi requested a review from rgrinberg April 28, 2022 06:54
@tatchi
Copy link
Collaborator Author

tatchi commented Apr 30, 2022

I tried to identify more use cases where folding would make sense (together with some tests to cover them). Hopefully it does make sense.

@rgrinberg
Copy link
Member

@ulugbekna could you take over reviewing this PR? I don't have time to look closely

@ulugbekna
Copy link
Collaborator

@rgrinberg sure

Copy link
Collaborator

@ulugbekna ulugbekna left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @tatchi ! :-)

@rgrinberg rgrinberg added this to the 1.12.0 milestone Jun 1, 2022
@ulugbekna ulugbekna force-pushed the folding-ranges-traverse-more-nodes branch from bafc7c9 to 84b45de Compare June 12, 2022 10:29
@ulugbekna
Copy link
Collaborator

ulugbekna commented Jun 12, 2022

Ready to be merged as soon as CI runs

re: more visual tests

I'm all for it. Maybe we could have something like this, ie we use IDs to see start and end of folds:

>1     match 
           Some  "large expr" 
         with 
>2     | None -> 
<2       () 
>3     | Some _ -> 
            print_endline "foo";
<1 <3   print_endline "bar"

What vscode does is also cool

@rgrinberg
Copy link
Member

Can we squash the commits before mergin?

@ulugbekna ulugbekna merged commit fa64091 into ocaml:master Jun 13, 2022
rgrinberg added a commit to rgrinberg/opam-repository that referenced this pull request Jun 20, 2022
CHANGES:

## Features

- Fix cancellation mechanism for all requests (ocaml/ocaml-lsp#707)

- Allow cancellation of formatting requests (ocaml/ocaml-lsp#707)

- Add `--fallback-read-dot-merlin` to the LSP Server (ocaml/ocaml-lsp#705). If `ocamllsp` is
  started with this new flag, it will fall back to looking for Merlin
  configuration in `.merlin` files rather than calling `dune ocaml-merlin`.
  (ocaml/ocaml-lsp#705)

- Support folding more ranges (ocaml/ocaml-lsp#692)
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.

3 participants