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

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

Open
Minnozz opened this issue Feb 27, 2024 · 4 comments
Open

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

Minnozz opened this issue Feb 27, 2024 · 4 comments

Comments

@Minnozz
Copy link
Contributor

Minnozz commented Feb 27, 2024

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
Copy link
Member

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

@Minnozz
Copy link
Contributor Author

Minnozz commented Feb 28, 2024

Seems like it should not be possible to use a globally installed formatter:

// It will try to use the user formatting binary.
// If not, use the one we ship with the analysis binary in the extension itself.

It shouldn't look outside of the project root for the bsc binary:

let projectRootPath = utils.findProjectRootOfFile(filePath);
let bscExeBinaryPath = findBscExeBinary(projectRootPath);

@Minnozz
Copy link
Contributor Author

Minnozz commented Feb 29, 2024

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

  • node_modules/.bin/bsc -color never -format Foo.res formats correctly
  • chenglou92.rescript-vscode/server/analysis_binaries/linux/rescript-editor-analysis.exe format Foo.res breaks the code

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.

@Minnozz Minnozz changed the title Format action breaks code returning a function in uncurried mode rescript-editor-analysis.exe format breaks code Feb 29, 2024
@fhammerschmidt
Copy link
Member

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

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

No branches or pull requests

2 participants