How to hide "dev" directories from module auto-complete

I keep my tests in a separate folder than my code. Following a recommendation from create-react-app it looks like…

\src
\src\__tests__

So I set up my bsconfig.json like this…

"sources": [
    { "dir": "src", "subdirs": false },
    { "dir": "src/__tests__", "subdirs": true, "type": "dev" }
  ],

I compile using the watcher like rescript build -w. If I attempt to reference __tests__ modules from anything in the src folder I get a compile error The module or file ... can't be found. But I can access my main code from the tests folder. So this is all good and expected.

The problem is auto-complete for the ReScript extension is polluted by the modules in the test folder. Ideally when I’m editing a file in the tests folder my auto-complete would show modules in the main code. But when I’m editing a module in the main src folder the auto-complete would NOT show any modules from the test folder so I see fewer and only the relevant module choices.

I wanted my module auto-complete to not be polluted so I prefaced EVERY test module file with an underscore. So if the main file is SomeFunctions I’ve got a test file _SomeFunctions. This way my autocomplete only shows the test modules if I type a _ to start with, which I never do. I’m not sure of the meaning of modules that start with _ but it seems like they compile fine but can not be referenced. I find this “hack” to be a bit ugly. I have some test utilities that must be referenced by other test files, and so those have regular names without the underscore prefix.

Is there some better way to do this? Ideally I think I’d want the rescript extension to be smart about what it suggests in autocomplete based on which file I’m editing. Alternatively it would be nice if my test file could have the exact same name as the main file, but it gets automatically prefixed with some kind of namespace like Test.SomeFunctions.

Overall this isn’t a big deal, just a minor annoyance, but I’m curious how other people organize things. Do they just accept the namespace pollution? Give every test file a name like Test_...? Use multiple “projects”, so the test project includes files from the main code but not vice versa? Is there some kind of namespace feature I’m not aware of? And what are the semantics of a module with a name that starts with underscore?

Hmm, it really works this way. Haven’t noticed it before. I think you can create an issue to improve autocomplete in the IDE extension repo https://github.com/rescript-lang/rescript-vscode.

Personally, I just add _test at the end of the test file. This way, it’s shown after the main module in the autocomplete list. It never caused a problem for me this way.

Also, for applications, I prefer having test files close to the tested code instead of having them in the __tests__ directory. You can use the repo as an example: https://github.com/DZakh/rescript-stdlib-vendorer