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

Optimize imports on file generation #92

Open
AdrianRaFo opened this issue Jul 3, 2018 · 11 comments
Open

Optimize imports on file generation #92

AdrianRaFo opened this issue Jul 3, 2018 · 11 comments

Comments

@AdrianRaFo
Copy link

AdrianRaFo commented Jul 3, 2018

I have realized that when I import an avdl file into another, the result statement looks like this:

import domain.{HTTPError, CredentialsError, Response, Request, TimeOutError, ParseError, ValidationError}

Too many times a lot of them are unused which cause a huge list of unused imports. So my question is: Is it possible to import only the necessary fields? or Could we change that statement by import domain._ or something like that?

Thank you so much for your attention.

@julianpeeters
Copy link
Owner

Apologies for the delayed response @AdrianRaFo.

Is it possible to import only the necessary fields? or Could we change that statement by import domain._ or something like that?

I would certainly be in favor of the first option, and although my shedule is tight for the time being, I'll try to prioritize this over the next couple weeks. Thanks for pointing this out. Time for sbt-tpolecat in the scripted tests.

@lachatak
Copy link

HI @julianpeeters
I am using sbt plugin 2.0.0-RC18 and it seems like it generates not used imports which is picked up by sbt-tpolecat and my build fails. Is there any progress in this area?
Thank you

@karolchmist
Copy link

I've opened a PR that solves a problem of too many imports. I'm not sure if it covers this case as well (it's been a while), but maybe someone could test it on the branch from the PR?

@julianpeeters
Copy link
Owner

sorry @lachatak, this is still pretty far down on my queue, I don't have a good estimation of a time frame. You may like to consider the fork that @karolchmist mentioned?

Thank you for the PR @karolchmist , however I'll have to decline anything but a general fix, because any added complexity will further impede maintenance.

@karolchmist
Copy link

No problem @julianpeeters. I'll close my PR and keep the fork.

Do you think a bigger refactoring would be needed to get rid of unused imports? Can I help? Do you have any hints or work in progress?

@julianpeeters
Copy link
Owner

@karolchmist Yes, avrohugger needs a revamp, but I believe there are some goals here that are achievable:

  1. Remove unused imports: this is likely to be a strait-forward bug fix (in some old code). As you probably saw, each format has a way to generate the imports it needs when generating a class def, and it looks like something is going wrong with getUserDefinedImports which is defined here. Hmm, maybe the the dependencies _of the class' dependencies` are accidentally being included?
  2. Provide import config, for e.g. wildcard and/or fully-qualified type names: eventually avrohugger will need this, but
    a. it will require a bit more work to wire and test; and
    b. configs need clunky scripted integration tests, but my CI account is nearly maxed at 50min. and adding another may be a roadblock.

I'd be happy to expand on any of the above.

@AdrianRaFo
Copy link
Author

For the meantime, as a workaround, I'm using the silencer plugin:

addCompilerPlugin("com.github.ghik" % "silencer-plugin"     % V.silencer cross CrossVersion.full),
libraryDependencies += "com.github.ghik" % "silencer-lib" % V.silencer % Provided cross CrossVersion.full

with a scalacOption

"-P:silencer:pathFilters=target"

to silent all the warning from code under the target folder (usually generated code)

@karolchmist
Copy link

@AdrianRaFo nice workaround!

Worth noting that a native solution will be incorporated into scala 2.13.2 :)
scala/scala-dev#333

@nicolaemarasoiu
Copy link

nicolaemarasoiu commented May 12, 2020

Thanks guys, for Scala 2.12 which are the options?

  • is there a way to apply Optionally limit the depth of nested schemas to reduce number of superfluous imports Optionally limit the depth of nested schemas to reduce number of superfluous imports #120 in order to limit the number of unused imports or the probability of such unused imports to be generated? can you help me with this?
  • create a separate sbt module (transform the sbt project to multi-module/multi-project)?
  • upgrade to Scala 2.13
  • use the silencer plugin created by @AdrianRaFo
  • disable (comment) "-Xfatal-warnings"
  • is there an option to configure unused imports separately from the other warnings?
  • is there an option to remove unused imports from generated Scala code?
    Is there any other option?
    Could you help me define/describe the multi-module/sub-projects/multi-project sbt build approach each with its own configuration/settings? Thank you very much

@AdrianRaFo
Copy link
Author

@nicolaemarasoiu I didn't create that plugin, just suggested

@nicolaemarasoiu
Copy link

ok, for me the silencer plugin approach worked great; since i had scala version 2.12.10 for other dependencies, I've used:
addCompilerPlugin("com.github.ghik" % "silencer-plugin" % "1.6.0" cross CrossVersion.full)

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

5 participants