Skip to content

Conversation

adpi2
Copy link
Member

@adpi2 adpi2 commented Oct 22, 2020

Fixes #6006

When using scalac, the sourcePath of the reported positions is virtual file refs.
When using Dotty, the sourcePath of the reported positions is absolute path, and so the BuildServerReporter was not working.

In the BuildServerReporter I now use the pos.sourceFile rather than the pos.sourcePath to store the diagnostics. The pos.sourceFile is much more stable because it is a real file from which I can reliably extract the absolute path.

I have added 2 build server tests. The first one checks that the last report contains an error, the other one checks that the last report contains a warning.

@adpi2 adpi2 requested a review from eed3si9n October 22, 2020 12:05
@eed3si9n
Copy link
Member

When using Dotty, the sourcePath of the reported positions is absolute path, and so the BuildServerReporter was not working.

Which file paths are we passing to Dotty?

In the BuildServerReporter I now use the pos.sourceFile rather than the pos.sourcePath to store the diagnostics.

We should avoid the use of java.io.File as much as possible. Not just for virtual file, but this also relate to other abstract paths like paths in JAR files and Java modules.

@adpi2
Copy link
Member Author

adpi2 commented Oct 26, 2020

Which file paths are we passing to Dotty?

We are passing VirtualFile.

But the Dotty sbt-bridge is sending absolute paths back to us. It get them from the pos.sourceFile:
https://github.com/lampepfl/dotty/blob/b2dc1016976558c6fbc67970139266486f2ad9d7/sbt-bridge/src/xsbt/DelegatingReporter.java#L77-L91

We should avoid the use of java.io.File as much as possible.

Ok. I changed the implementation so that it relies on pos.sourcePath and not pos.sourceFile. It uses the FileConverter to handle both cases: virtual file ids and absolute paths.

@eed3si9n
Copy link
Member

But the Dotty sbt-bridge is sending absolute paths back to us. It get them from the pos.sourceFile:
https://github.com/lampepfl/dotty/blob/b2dc1016976558c6fbc67970139266486f2ad9d7/sbt-bridge/src/xsbt/DelegatingReporter.java#L77-L91

Since I made changes to the compiler bridge in sbt/zinc but did not send PRs to Dotty it makes sense that there are some differences in the implementation. I'd suggest we send PR to make that side consistent then.

@adpi2
Copy link
Member Author

adpi2 commented Oct 26, 2020

I'd suggest we send PR to make that side consistent then.

Agreed.

I still think this current PR makes much sense since it enables compatibility on previous versions of sbt-dotty. IMO it is a pity that I cannot use BSP in sbt 1.4.1 on a Dotty project. It used to work pretty well on 1.4.0.

Also I think this implementation will be a lot more robust on future changes since it relies on the file converter.

@eed3si9n eed3si9n merged commit 8c3ea7d into sbt:develop Oct 26, 2020
adpi2 added a commit to adpi2/zinc that referenced this pull request Nov 26, 2020
This commit add support for `VirtualFiles`, that has recently been added
to Zinc, to the `scala3-compiler-bridge`. It fixes a bug that was
reported in sbt/sbt#6007.

Also it fixes a bug in the bug in the returned `CompileAnalysis` by
populating the `SourceInfos`. The reported warnings were not returned
back in `sbt-dotty` after a succefull compilation.
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

Successfully merging this pull request may close these issues.

[1.4.1] BSP empty failure report on Dotty project
2 participants