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

Respect -P:semanticdb:exclude #875

Closed
abdheshkumar opened this issue Sep 20, 2018 · 21 comments
Closed

Respect -P:semanticdb:exclude #875

abdheshkumar opened this issue Sep 20, 2018 · 21 comments

Comments

@abdheshkumar
Copy link
Contributor

Reproduce:

class DefineImplicits() extends scala.annotation.StaticAnnotation {

  // scalafix:off
  inline def apply(defn: Any): Any = meta { 
...
}
//// scalafix:on

https://gitter.im/scalacenter/scalafix?at=5ba395ea5df5194734e91fef
Error:

 error: ; expected but def found
[error]   inline def apply(defn: Any): Any = meta {
@gabro
Copy link
Collaborator

gabro commented Sep 20, 2018

I think this is scalameta/scalameta#1038 (which has been closed but it's not fixed)

@abdheshkumar
Copy link
Contributor Author

Is there a workaround? @gabro It is still not working after excluding file.

unmanagedSources.in(Compile, scalafix) := unmanagedSources.in(Compile).value.filterNot(file =>file.getName.contains("Macros"))
here Macros is Macros.scala file that has macro related code.

@gabro
Copy link
Collaborator

gabro commented Sep 20, 2018

As a workaround, you can add a dummy statement before the inline statement:

class DefineImplicits() extends scala.annotation.StaticAnnotation {
  val dummy = 42
  // scalafix:off
  inline def apply(defn: Any): Any = meta { 
  // ...
}

This works because the bug only happens when inline starts a template (a template is scalac lingo for an extends A { ... } clause

@gabro
Copy link
Collaborator

gabro commented Sep 20, 2018

(I'm tracking the new issue here scalameta/scalameta#1776)

@abdheshkumar
Copy link
Contributor Author

Ok, thank you @gabro Do you have an idea why it is not excluding file?

@gabro
Copy link
Collaborator

gabro commented Sep 20, 2018

No, I have no idea. It could be that it still tries to parse the file before excluding it, but I'm not sure.

@abdheshkumar
Copy link
Contributor Author

Ok thank you @gabro but the workaround is not working.

  val dummy = 42
  inline def apply(defn: Any): Any = meta { -}

@gabro
Copy link
Collaborator

gabro commented Sep 20, 2018

is it the same exact error?

@abdheshkumar
Copy link
Contributor Author

abdheshkumar commented Sep 20, 2018

@gabro Yes, it is same.

error: ; expected but def found
[error]   inline def apply(defn: Any): Any = meta {
[error]          ^

@gabro
Copy link
Collaborator

gabro commented Sep 20, 2018

Mm, it might be slightly different then. We'll have to wait for @olafurpg to clear this up.

@abdheshkumar
Copy link
Contributor Author

@gabro anyway thank you!

@olafurpg
Copy link
Contributor

@abdheshkumar Is the error reported during compilation or after running scalafix?

Either way, I am afraid that scalafix semantic rules won't work for source files where inline/meta macro annotations are used. It is not enough to exclude the file defining the macro but also all files where the macros are used.

The inline/meta macro annotations are no longer under development and it is recommended to use org.scalamacros:paradise annotations instead (which have been merged into the Scala compiler for 2.13).

To exclude a file from compilation with semanticdb-scalac, add the following to your build

scalacOptions += "-P:semanticdb:exclude:Macros"

To support the inline keyword in Scalafix, add the following to .scalafix.conf

// .scalafix.conf
parser.inlineKeyword = true

@abdheshkumar
Copy link
Contributor Author

@olafurpg thank you so much for the detailed reply. I am getting that error while running scalafix RemoveUnused

@abdheshkumar
Copy link
Contributor Author

abdheshkumar commented Sep 20, 2018

@olafurpg Looks like that error has gone now.
How to exclude multiple files here scalacOptions += "-P:semanticdb:exclude:Macros" . I have tried scalacOptions += "-P:semanticdb:exclude:Macros,Schema" but it doesn't work and it said bad scalacOption.
Another question, I have below code.

 // scalafix:off
    q"""
      Map(${cases: _*})
     """
    // scalafix:on

I am getting

 error: repeated argument not allowed here
[error]       Map(${cases: _*})
[error]                    ^

@abdheshkumar
Copy link
Contributor Author

I think, `scalacOptions += "-P:semanticdb:exclude:Macros|Schema" fixed the problems.

@olafurpg
Copy link
Contributor

What happens if you change to Map(..$cases)? I have not seen that syntax before, it might be a parser bug but if you can use ..$ instead then that's a faster workaround.

@abdheshkumar
Copy link
Contributor Author

@olafurpg thank you that trick solved repeated argument not allowed here error. With the help of you,I am able to run scalafix on project which use Macro.scala but not able to run scalafix on project where I have actual Macros.scala file. Below is the error which I am getting.

[info] Running scalafix on 22 Scala sources
[error] SemanticDB not found: META-INF/semanticdb/libraries/utils/shared/src/main/scala/utils/implicits/Macros.scala.semanticdb
[error] (Compile / scalafix) scalafix.sbt.ScalafixFailed: MissingSemanticdbError
[error] Total time: 18 s, completed 21-Sep-2018 01:10:05
sbt:utilities library> 

I have equired scalacOptions enabled and semanticdb-scalac compile plugin.

sbt:utilities library> show scalacOptions 
[info] * -unchecked
[info] * -deprecation
[info] * -feature
[info] * -language:higherKinds
[info] * -Ypartial-unification
[info] * -Yrangepos
[info] * -Ywarn-unused-import
[info] * -P:semanticdb:exclude:Macros
[success] Total time: 9 s, completed 21-Sep-2018 01:13:33
sbt:utilities library> show libraryDependencies
[info] * org.spire-math:kind-projector:0.9.3:plugin->default(compile)
[info] * org.scalamacros:paradise:2.1.0:plugin->default(compile)
[info] * org.scalameta:paradise:3.0.0-M11:plugin->default(compile)
[info] * org.scalameta:semanticdb-scalac:4.0.0-RC1:plugin->default(compile)

Please, could you help me on this too?

@olafurpg
Copy link
Contributor

Do you have the following settings enabled?

unmanagedSources.in(Compile, scalafix) := unmanagedSources.in(Compile).value.filterNot(file =>file.getName.contains("Macros"))

The error happens because "Macros.scala" is one of the 22 sources in the "Running scalafix on 22 Scala sources" message.

@olafurpg
Copy link
Contributor

You can validate which files are processed by running scalafix --verbose.

@olafurpg olafurpg changed the title Scalafix 0.8.0-RC1 is not working with macro. Respect -P:semanticdb:exclude Sep 21, 2018
@olafurpg
Copy link
Contributor

I think the best solution here is to make scalafix respect the -P:semanticdb:exclude setting so that it will not be necessary to configure unmanagedSources. A related issue is #879

@olafurpg
Copy link
Contributor

Pending fix #885

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