rescript-lang / rescript-vscode

Official VSCode plugin for ReScript
MIT License
328 stars 56 forks source link

rescript-editor-analysis.exe format breaks code #931

Open Minnozz opened 8 months ago

Minnozz commented 8 months ago

When I compile this code with rescript v11.0.1, it works fine. npx rescript format -all does not change it:

type checker = int => bool

let makeChecker: int => checker = modulo => number => mod(number, modulo) == 0

let isEven = makeChecker(2)
Console.log(isEven(7)) // false

When I use the Format document action in VSCode with the v1.38.0 version of the extension, it is changed to this:

type checker = int => bool

let makeChecker: int => checker = (modulo, number) => mod(number, modulo) == 0

let isEven = makeChecker(2)
Console.log(isEven(7)) // false

This does not compile:

  We've found a bug for you!
  /path/to/Foo.res:3:35-78

  1 │ type checker = int => bool
  2 │ 
  3 │ let makeChecker: int => checker = (modulo, number) => mod(number, modulo
    │ ) == 0
  4 │ 
  5 │ let isEven = makeChecker(2)

  This function expected 1 argument, but got 2
fhammerschmidt commented 8 months ago

This looks like you are using an older (globally installed?) version of the formatter. I don't have this behavior.

Minnozz commented 8 months ago

Seems like it should not be possible to use a globally installed formatter: https://github.com/rescript-lang/rescript-vscode/blob/51b6c46abe283f7adad606e2bd43ca46210c85e9/server/src/utils.ts#L91-L92

It shouldn't look outside of the project root for the bsc binary: https://github.com/rescript-lang/rescript-vscode/blob/51b6c46abe283f7adad606e2bd43ca46210c85e9/server/src/server.ts#L775-L776

Minnozz commented 8 months ago

I've manually run the commands that the extension runs:

So for some reason, in my setup (which is unconventional due to NixOS), bsc can't be found and the shipped rescript-editor-analysis.exe binary is used for formatting, which has different semantics than bsc.

fhammerschmidt commented 8 months ago

Not 100 % sure, but I heard the parser itself still defaults to curried output. @cknitt may know more.

Also, did you try one of these?

// Path to the directory where cross-platform ReScript binaries are. You can use it if you haven't or don't want to use the installed ReScript from node_modules in your project.
"rescript.settings.binaryPath": null

// Path to the directory where platform-specific ReScript binaries are. You can use it if you haven't or don't want to use the installed ReScript from node_modules in your project.
"rescript.settings.platformPath": null