Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a mode to buildTarget/sources to return unmanaged sources only? #184

Open
retronym opened this issue Jun 26, 2021 · 6 comments
Open

Comments

@retronym
Copy link

This ticket is in the same spirit of #14, looking for ways to reduce long delays on IDE import.

I have been trying to use BSP to import scala/scala into IntelliJ. I noticed that the import triggers all source generators. In our project, this requires compilation of most of the project.

I would prefer to have source generators run in a second pass after the initial import. For the initial import, the IDE would be only need to know the base directories for generated sources. This would be enough to get the IDE into a working state while a background process triggered source generation (and any compilation transitively needed.)

/cc @jastice

@adpi2
Copy link
Member

adpi2 commented Jun 28, 2021

I think you mean buildTarget/sources rather than buildTarget/dependencySources here, rigth?

The protocol already allows to send/receive source directories rather than individual files. So technically, a build server can respond with the base directory of the generated sources and trigger the generation asynchronously or even postpone the generation for when it's really needed (buildTarget/compile).

That's not how it is implemented today in sbt, but maybe we should. @jastice Would that work in IntelliJ if the source generation is postponed to the first buildTarget/compile?

@retronym retronym changed the title Add a mode to dependencySources to return unmanaged sources only? Add a mode to buildTarget/sources to return unmanaged sources only? Jun 28, 2021
@retronym
Copy link
Author

Yep, I've update description with the correct target.

IntelliJ's project model only supports source directories so it would be just as happy to receive managed source directories.

Another advantage of this approach that it makes it possible to import a project that has some erroneous code that would prevent the source generators from completing.

But leaving the source generation until the first compile isn't ideal because a) the user can't see / program against the generated APIs until that point.

@adpi2
Copy link
Member

adpi2 commented Jun 28, 2021

In sbt we could implement something like this:

case r if r.method == "buildTarget/sources" =>
  val target = ...
  callback.appendExec(s"bspBuildTargetSources $target", Some(r.id))
  callback.appendExec(s"$target / managedSources", None) // trigger the source generations after responding

That would prevent the build import from failing if the source generation fails. But it does not make the overall import time better because the next request, buildTarget/dependenycSources, will have to wait for the source generation to finish.

Actually I think it's not so bad to postpone the source generation until buildTarget/compile. It's true that the user wants to see the generated APIs as soon as possible, and the solution would be for IntelliJ to send a buildTarget/compile just after the build import:

  1. Send workspace/buildTargets
  2. Send buildTarget/sources
  3. Send buildTarget/dependencySources
  4. Send buildTarget/scalacOptions
  5. Build imported successfully
  6. Send buildTarget/compile to force source generation (and resource generation)

Or even better, we could introduce buildTarget/generateSources and buildTarget/generateResources.

@jastice
Copy link
Member

jastice commented Jun 28, 2021

That's not how it is implemented today in sbt, but maybe we should. @jastice Would that work in IntelliJ if the source generation is postponed to the first buildTarget/compile?

Yes, triggering a build after import is feasible and probably not too disruptive. But if the build then generates new source directories that are not already reported by buildTarget/sources we'll have the issue that IntelliJ doesn't acknowledge them as project sources.

@adpi2
Copy link
Member

adpi2 commented Jun 28, 2021

Yes, triggering a build after import is feasible and probably not too disruptive. But if the build then generates new source directories that are not already reported by buildTarget/sources we'll have the issue that IntelliJ doesn't acknowledge them as project sources.

Yes but we can report the src_managed directory in buildTarget/sources and fill it afterward on buildTarget/compile.

@jastice
Copy link
Member

jastice commented Jun 28, 2021

Yes but we can report the src_managed directory in buildTarget/sources and fill it afterward on buildTarget/compile.

Yes, for the sbt use case this should work well. Other build tools may have a different approach and only report actually generated sources.

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

No branches or pull requests

3 participants