Reliable error diagnostics for any editor

Following Move forward with warn-as-error by default. For each run of bsb we always write the compiler output to a named file, e.g, .compiler.log.

For any editor plugins, it only needs watch such file and update its problems panels once any change detected, thoughts?

Note the downside is that if you have some unsaved files, that won’t be detected but we can still report syntax errors for those unsaved files. This is not the most fancy way of doing error diagnostics, but it’s probably the most reliable way of doing it ?

6 Likes

It’s an addition to the normal output ? we’ll still see errors and warnings on standard output ?
That could be easier to synchronise the external annotator in my case.
how errors would be serialised in the log ?

It’s an addition to the normal output ? we’ll still see errors and warnings on standard output ?

Yes

It’s an addition to the normal output ? we’ll still see errors and warnings on standard output ?

The same as terminal but only contains compiler output

Why we plan to write a file is that the editor does not need run bsb, they just watch/read the build log

2 Likes

Why we plan to write a file is that the editor does not need run bsb, they just watch/read the build log

I think this is a great idea and should indeed make error diagnostics in the editor extremely solid. :smiley:

It won’t help with Type Hints / Autocomplete though (which I hope will also be provided by the VS Code plugin at some point). Do you already have a plan how to implement those, too?

2 Likes

Although I like the errors to automatically disappear while typing it’s not a bad compromise to only do it on save for now.

1 Like

It’s a good idea but as @jfrolich mentioned with this approach diagnostics I think can’t be updated wihout saving the file.

It won’t help with Type Hints / Autocomplete though (which I hope will also be provided by the VS Code plugin at some point). Do you already have a plan how to implement those, too?

I’m also interested in this. is there any plan to achieve type information with a new approach or language server has to read from .cmt files or something like that.

Yeah. The difference being that what’s in the file is the latest run whereas in the terminal it’ll be streaming as usual.

The file will also persist after your build is done. Theoretically you can have other tools query it at a later time given that it’s not stale, but no promise for now.

Read-only diagnosis for editors is much more scalable. It means the editor itself (assuming you only have one open) doesn’t have to be the centralized point of building, aka you get to run your own bsb in the terminal, or have it as part of a larger build step without needing to negotiate with the editor to make sure you’re not stepping on each other’s toes, etc. It also means if you drag in a file from a different project, you don’t end up with some impedance mismatch of assuming that a single editor instance maps to a single project (e.g. you can show the errors from as many projects as you’d like in a single editor instance).

We do, but that part will be tackled differently. Unrelated to the feature above. Let’s focus on this issue first. Also, note that we’re not trying to reinvent the wheel; we’re only redoing the parts that should be solid. One big value proposition we have is a solid type system; for most users today, this isn’t even true if their primary interface to the type system is in-editor report, which is currently best-effort + mired by quite a few plugin-related problems. So that parts needs to be properly solved by ourselves. Type hints and autocomplete can defer to existing infra even.

That’s right. But it’s not like this particular feature would block what you’re asking for. We’re gonna postpone a real-time approach for now because we need a baseline of robustness. Also, it’s kinda hard to do real-time diagnosis while keeping soundness right now. Actually, to our knowledge, no language even offer the combination of soundness + real-time-ness in editor. At least we’re gonna check the first one now.

4 Likes

The type hints/autocomplete work will be rebased on reason-langauge-service plugging.
The thing we want to replace is the error diagnostics which is unreliable and misguided.

4 Likes

For people who are interested in editor tooling, the changes are landed on master branch (including windows support).

So whenever you run bsb, it will always write all compiler output to file lib/bs/.compiler.log.

The typical workflow is that you have npx bsb -w on your terminal, and your editor subscribe changes to lib/bs/.compiler.log.

As a fallback, if the editor could not find this file, it can try run bsb manually

The remaining work is to tweak the output format to make it relatively easy to parse.

5 Likes

@Hongbo Great work, I just tried implementing error highlighting for coc-rescript using .compiler.log and it works perfectly.

I did notice a minor differences in the formatting of filename and error location. Warnings and “We found a bug” have a : separating the two:

Warning number 26
/path/to/file/File.res:37:7-10

We've found a bug for you!
/path/to/file/File.res:42:11-14

But syntax errors have a space separating filename and location:

Syntax error!
/path/to/file/File.res 40:22-42:5

Maybe this is something that will be fixed with the output tweaking?

1 Like

Seems already addressed by upstream: https://github.com/rescript-lang/rescript-compiler/pull/4686
Other feedback is welcome

1 Like

@Hongbo Does it mean that the error reporting is going to be responsibility of editor integration (client) rather than rescript language server? Or am I misunderstood the comment?

Yes. The motivation is that the build system is quite important to be client facing (instead of hidden by the editor).

2 Likes

I think bob misunderstood your question @alex.fedoseev? It’s still the (language) server that reads that log file, if that’s what you’re asking. What did you mean by the client doing it?

Yeah, I guess it was misunderstanding. By client, I meant vscode/atom/ language client which starts language server.

So it’s still responsibility of rescript-language-server to read into this log file and dispatch parsed diagnostics to the editor language client.

Yes, it’s the server that reads it. I have to draft up the description for how this should be done to avoid stale diagnosis as much as possible. This’ll be useful for other editors with different logic like IntelliJ, Sublime Text, etc. Feel free to keep watching the rescript-vscode repo’s docs.

7 Likes

Hi all,

After working on this post about build system changes, I realized that we can capture the warnings output without making any disruptive changes to clients. That means you can still have -warn-error as a fine grained control. The build system will just capture the warnings magically.

It’s a bit more work to restore such behaviors, but I will revert such changes to make user experience better.

Also I would like to take this as an example: the rescript maintainers have to make trade off from time to time, it’s in our best interest to make user experience better regardless of how much extra work needs to be done. Sometimes users may not have as much context as maintainers on the design space.

5 Likes