|
| 1 | +# Contributing |
| 2 | + |
| 3 | +Thanks for your interest. Below is an informal spec of how the plugin's server communicates with the actual compiler. If you're a ReScript editor plugin implementor, you should probably read this to understand the various important nuances. |
| 4 | + |
| 5 | +## Editor Diagnostics |
| 6 | + |
| 7 | +They should be synced in from the `bsb` build. Don't take them from other places. |
| 8 | + |
| 9 | +### `.compiler.log` |
| 10 | + |
| 11 | +The build output is streamed into `lib/bs/.compiler.log`. Here are its various states: |
| 12 | + |
| 13 | +- Doesn't exist: artifacts not built yet, or cleaned away. |
| 14 | +- Present but empty: currently building, no error yet. |
| 15 | +- Present, non-empty, without a final line `# Done`: still building. |
| 16 | +- Present, with the final line `# Done`: finished building. |
| 17 | + |
| 18 | +Barring FS errors, there should be no other state to `.compiler.log`. |
| 19 | + |
| 20 | +### States of Diagnostics |
| 21 | + |
| 22 | +- Artifacts cleaning through `bsb -clean` removes `.compiler.log`, as mentioned above. If that's the case, remove the diagnostics in the editor too. One could argue that they should be kept, but that's misleading UX-wise, and harder to implement correctly. |
| 23 | + |
| 24 | +### Files from Other Projects |
| 25 | + |
| 26 | +It's possible to open files from different projects into the same editor instance. In that case, also read _that_ file's project's `.compiler.log`. |
| 27 | + |
| 28 | +The bad alternatives are: |
| 29 | +- Not show that file's project's errors. That's wrong for several reasons (looks like the file has no error, assumes an editor window has a default project, etc.). |
| 30 | +- Show only that file's error. That's just weird, the errors are already read from that project's `.compiler.log`. Might as well show all of them (?). |
| 31 | + |
| 32 | +## Format |
| 33 | + |
| 34 | +To find the location of `bsc` to run: |
| 35 | +- Look for the nearest `bsconfig.json`. That's the root of the project. \* |
| 36 | +- Search in that directory's `node_modules/bs-platform/{platform}/bsc.exe`. |
| 37 | + - Do **not** directly use `node_modules/.bin/bsc` if you can help it. That's a Nodejs wrapper. Slow startup. We don't want our formatting to be momentarily stalled because some Nodejs cache went cold. |
| 38 | + - `platform` can be `darwin`, `linux`, `win32` or `freebsd`. |
| 39 | + |
| 40 | +\* Maybe we'll do this differently in the future because asking for a `bsconfig.json` just to format some files is rough. |
| 41 | + |
| 42 | +### Formatting Newline |
| 43 | + |
| 44 | +The formatted result should be taken as-is, without any extra string trimming and newline addition/removal by the editor plugin. |
| 45 | + |
| 46 | +### Formatting Errors |
| 47 | + |
| 48 | +- should the format still show errors when the build isn't running? |
| 49 | +- should it show during various states of `.compiler.log`? |
| 50 | + |
| 51 | + |
| 52 | +<!-- - when to check for .bsb.lock |
| 53 | +- when to check for lib/bs --> |
| 54 | + |
0 commit comments