Vim Rescript with Yarn Workspaces not working

Hey guys, I have got everything working with vim-rescript and also the vs-code language server working with vim-coc but when ever I am in my main mono-repo project using yarn workspaces, the RescriptFormat command fails with an error message: rescript format returned an error.

Again, this works perfectly fine in a fresh simple flat app using create-react-app with no problems.

Thanks in advance!


Can you open your vim project and give me the output of the following:



:echo g:resc_command

also it would be interesting how the project is structured (where did you put the bsconfig.json files, where is bs-platform installed, etc).

@ryyppy @dan003400 I was just looking into this problem.
The thing is that yarn workspaces puts the compiler and formatter in a very specific position, which is currently not taken care of by the heuristics.

Looking into a way of fixing this atm.

ReScript version: 0
Detected Config File:
Detected Project Root: /Users/dan/Developer/App/my-monorepo-app
ReScript Type Hint Binary: ~/dotfiles/nvim/lang_servers/reason-language-server/bin.exe

I believe this resc_command output is what is not working correctly, as that is not located in the sub-package, its in the main root directory node_modules.

Creating a symlink to the bsc.exe in the sub-package allows the format on save to work, but then causes issues with duplicate dependencies and the package.json is also needed or compile errors happen.

Working on a fix here:

The LSP and vanilla vim functionality are independent here. Formatting via :RescriptFormat runs our g:resc_command, which is calculated here.

The question is how the editor integration should behave, since it depends on when and where you open a file. If you are e.g. opening the vim editor in the root folder of the project, where does the vim-rescript plugin find the right binary?

I think yarn workspaces does a few funky things, such as dependency hoisting into the root project node_modules or something?

How would packages with multiple different bs-platform versions work? Kinda tricky questions.

Any hints on design ideas would be great, because I don’t have a lot of experience with typical lerna / yarn setups.

Edit: if there are any public ReScript / yarn workspace projects on github, would appreciate some link so I can have a look at it.

I’m working off this repo, provides a pretty good example.
The compiler exe seems to be located in the top folder’s node_modules, the build artefacts in the subfolder

1 Like

Yes, you are correct when using yarn workspaces, it hosts all the node_modules in the top level root directory.

It doesnt seem to matter where I open vim, but I think best practice would be to open vim from the root directory when working on projects using workspaces.

I am not 100% sure how this would work if using multiple versions of bs-platform across sub-packages in the workspace.

Could we possibly add configuration for vim when a file is opened to set the correct path to use for g:res_bin_dir ?

I guess the build artifacts always land next to the bsconfig.json. @Hongbo is currently working on better monorepo support, I wonder if this will stay the same?

Yeah we probably will need another vim function that allows calculating new g:res_bin_dir, g:resc_command, etc. … that way we could use autocmd to automatically look for a new bin dir root whenever you edit a res file.

1 Like

Is there a hack cmd to get the g:res_bin_dir working with the current setup in the meantime?

We have this working for now with symlinks but this causes a ton of duplicate dependencies since we needed to symlink the bs-platform/package.json file as well to get it working. But once those warnings pass we at least have auto formatting.

g:res_bin_dir is not really used for anything else after initialization. You need to set g:resc_command and g:resb_command accordingly, which can be done by

:let resc_command = "my/path/bsc.exe"
:let resb_command = "my/path/bsb.exe"

If you are using Plug, you could also just go into the vim-rescript directory and modify the autoload/rescript.vim by copying the rescript#Init function (e.g. rescript#ChangeBinPaths), and then you could use an autocommand to automatically run it on every file open:

" in your vimrc
augroup rescriptFixes
    autocmd FileType rescript call rescript#ChangeBinPaths()
augroup END
1 Like

Any update on this?

I have tried this branch, but it did not seem to do anything:



Any updates on the yarn workspaces mono repo solutions?

If anyone else is having this issue, I believe I have a quick fix PR up that will allow your workspaces project to work :slight_smile:

Let me know if you have any issues or if this fixes your issue!


We have pushed up a version that has a preview for the fix:

Plug 'rescript-lang/vim-rescript', {'branch': 'monorepo-support'}